pick 97420a31d The big reformat of 2020
This commit is contained in:
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,240 +27,200 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AdaptorItemHandler extends InventoryAdaptor {
|
||||
protected final IItemHandler itemHandler;
|
||||
|
||||
public class AdaptorItemHandler extends InventoryAdaptor
|
||||
{
|
||||
protected final IItemHandler itemHandler;
|
||||
public AdaptorItemHandler(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
public AdaptorItemHandler( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return this.itemHandler.getSlots() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return this.itemHandler.getSlots() > 0;
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
for (int slot = 0; slot < slots && amount > 0; slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty() || (!filter.isEmpty() && !Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots && amount > 0; slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null) {
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!destination.canInsert(extracted)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Attempt extracting it
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, false);
|
||||
|
||||
// Attempt extracting it
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (rv.isEmpty()) {
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted;
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
} else {
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow(extracted.getCount());
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted;
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow( extracted.getCount() );
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
for (int slot = 0; slot < slots && amount > 0; slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
ItemStack extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
|
||||
for( int slot = 0; slot < slots && amount > 0; slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
ItemStack extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if (extracted.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( extracted.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null) {
|
||||
if (!destination.canInsert(extracted)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
if (rv.isEmpty()) {
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted.copy();
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
} else {
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow(extracted.getCount());
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
// Use the first stack as a template for the result
|
||||
rv = extracted.copy();
|
||||
filter = extracted;
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Subsequent stacks will just increase the extracted size
|
||||
rv.grow( extracted.getCount() );
|
||||
amount -= extracted.getCount();
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
/**
|
||||
* For fuzzy extract, we will only ever extract one slot, since we're afraid of
|
||||
* merging two item stacks with different damage values.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode,
|
||||
IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
/**
|
||||
* For fuzzy extract, we will only ever extract one slot, since we're afraid of merging two item stacks with
|
||||
* different damage values.
|
||||
*/
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
for (int slot = 0; slot < slots && extracted.isEmpty(); slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty()
|
||||
|| (!filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (destination != null) {
|
||||
ItemStack simulated = this.itemHandler.extractItem(slot, amount, true);
|
||||
if (simulated.isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if( destination != null )
|
||||
{
|
||||
ItemStack simulated = this.itemHandler.extractItem( slot, amount, true );
|
||||
if( simulated.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!destination.canInsert(simulated)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if( !destination.canInsert( simulated ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, false);
|
||||
}
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, false );
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode,
|
||||
IInventoryDestination destination) {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
ItemStack extracted = ItemStack.EMPTY;
|
||||
for (int slot = 0; slot < slots && extracted.isEmpty(); slot++) {
|
||||
final ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
if (is.isEmpty()
|
||||
|| (!filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < slots && extracted.isEmpty(); slot++ )
|
||||
{
|
||||
final ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if( is.isEmpty() || ( !filter.isEmpty() && !Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
continue;
|
||||
}
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem(slot, amount, true);
|
||||
|
||||
// Attempt extracting it
|
||||
extracted = this.itemHandler.extractItem( slot, amount, true );
|
||||
if (!extracted.isEmpty() && destination != null) {
|
||||
if (!destination.canInsert(extracted)) {
|
||||
extracted = ItemStack.EMPTY; // Keep on looking...
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if( !extracted.isEmpty() && destination != null )
|
||||
{
|
||||
if( !destination.canInsert( extracted ) )
|
||||
{
|
||||
extracted = ItemStack.EMPTY; // Keep on looking...
|
||||
}
|
||||
}
|
||||
}
|
||||
return extracted;
|
||||
}
|
||||
|
||||
return extracted;
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack toBeAdded) {
|
||||
return this.addItems(toBeAdded, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( ItemStack toBeAdded )
|
||||
{
|
||||
return this.addItems( toBeAdded, false );
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack toBeSimulated) {
|
||||
return this.addItems(toBeSimulated, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( ItemStack toBeSimulated )
|
||||
{
|
||||
return this.addItems( toBeSimulated, true );
|
||||
}
|
||||
protected ItemStack addItems(final ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for (int slot = 0; slot < slots; slot++) {
|
||||
if (!this.itemHandler.getStackInSlot(slot).isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int slots = this.itemHandler.getSlots();
|
||||
for( int slot = 0; slot < slots; slot++ )
|
||||
{
|
||||
if( !this.itemHandler.getStackInSlot( slot ).isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new ItemHandlerIterator( this.itemHandler );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new ItemHandlerIterator(this.itemHandler);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,58 +18,47 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
|
||||
|
||||
import appeng.util.Platform;
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler {
|
||||
public AdaptorItemHandlerPlayerInv(final PlayerEntity playerInv) {
|
||||
super(new PlayerMainInvWrapper(playerInv.inventory));
|
||||
}
|
||||
|
||||
public class AdaptorItemHandlerPlayerInv extends AdaptorItemHandler
|
||||
{
|
||||
public AdaptorItemHandlerPlayerInv( final PlayerEntity playerInv )
|
||||
{
|
||||
super( new PlayerMainInvWrapper( playerInv.inventory ) );
|
||||
}
|
||||
/**
|
||||
* Tries to fill existing stacks first
|
||||
*/
|
||||
@Override
|
||||
protected ItemStack addItems(final ItemStack itemsToAdd, final boolean simulate) {
|
||||
if (itemsToAdd.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tries to fill existing stacks first
|
||||
*/
|
||||
@Override
|
||||
protected ItemStack addItems( final ItemStack itemsToAdd, final boolean simulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
|
||||
ItemStack left = itemsToAdd.copy();
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
ItemStack is = this.itemHandler.getStackInSlot(slot);
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
ItemStack is = this.itemHandler.getStackInSlot( slot );
|
||||
if (Platform.itemComparisons().isSameItem(is, left)) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
}
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
if( Platform.itemComparisons().isSameItem( is, left ) )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
}
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
for (int slot = 0; slot < this.itemHandler.getSlots(); slot++) {
|
||||
left = this.itemHandler.insertItem(slot, left, simulate);
|
||||
if (left.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
for( int slot = 0; slot < this.itemHandler.getSlots(); slot++ )
|
||||
{
|
||||
left = this.itemHandler.insertItem( slot, left, simulate );
|
||||
if( left.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
return left;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@@ -29,200 +28,164 @@ import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor {
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
private final List<ItemStack> i;
|
||||
|
||||
private final List<ItemStack> i;
|
||||
public AdaptorList(final List<ItemStack> s) {
|
||||
this.i = s;
|
||||
}
|
||||
|
||||
public AdaptorList( final List<ItemStack> s )
|
||||
{
|
||||
this.i = s;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return !this.i.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return !this.i.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeItems(int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
final int s = this.i.size();
|
||||
for (int x = 0; x < s; x++) {
|
||||
final ItemStack is = this.i.get(x);
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.size();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.get( x );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.grow(-amount);
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
is.grow( -amount );
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
// remove it..
|
||||
if( is.getCount() <= 0 )
|
||||
{
|
||||
this.i.remove( x );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateRemove(int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty() && (filter.isEmpty() || Platform.itemComparisons().isSameItem(is, filter))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, final ItemStack filter, final FuzzyMode fuzzyMode,
|
||||
final IInventoryDestination destination) {
|
||||
final int s = this.i.size();
|
||||
for (int x = 0; x < s; x++) {
|
||||
final ItemStack is = this.i.get(x);
|
||||
if (!is.isEmpty()
|
||||
&& (filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.size();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.get( x );
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
is.grow(-amount);
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
is.grow( -amount );
|
||||
// remove it..
|
||||
if (is.getCount() <= 0) {
|
||||
this.i.remove(x);
|
||||
}
|
||||
|
||||
// remove it..
|
||||
if( is.getCount() <= 0 )
|
||||
{
|
||||
this.i.remove( x );
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int amount, final ItemStack filter, final FuzzyMode fuzzyMode,
|
||||
final IInventoryDestination destination) {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty()
|
||||
&& (filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem(is, filter, fuzzyMode))) {
|
||||
if (amount > is.getCount()) {
|
||||
amount = is.getCount();
|
||||
}
|
||||
if (destination != null && !destination.canInsert(is)) {
|
||||
amount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
if( amount > is.getCount() )
|
||||
{
|
||||
amount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
amount = 0;
|
||||
}
|
||||
if (amount > 0) {
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount(amount);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( amount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( amount );
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(final ItemStack toBeAdded) {
|
||||
if (toBeAdded.isEmpty()) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if (toBeAdded.getCount() == 0) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
if( toBeAdded.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if( toBeAdded.getCount() == 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
final ItemStack left = toBeAdded.copy();
|
||||
|
||||
final ItemStack left = toBeAdded.copy();
|
||||
for (final ItemStack is : this.i) {
|
||||
if (ItemStack.areItemsEqual(is, left)) {
|
||||
is.grow(left.getCount());
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( ItemStack.areItemsEqual( is, left ) )
|
||||
{
|
||||
is.grow( left.getCount() );
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
this.i.add(left);
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
this.i.add( left );
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(final ItemStack toBeSimulated) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
for (final ItemStack is : this.i) {
|
||||
if (!is.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
for( final ItemStack is : this.i )
|
||||
{
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new StackToSlotIterator( this.i.iterator() );
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new StackToSlotIterator(this.i.iterator());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public interface IAEAppEngInventory {
|
||||
void saveChanges();
|
||||
|
||||
public interface IAEAppEngInventory
|
||||
{
|
||||
void saveChanges();
|
||||
|
||||
void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack );
|
||||
void onChangeInventory(IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack);
|
||||
}
|
||||
|
||||
@@ -18,12 +18,9 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryDestination {
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
|
||||
boolean canInsert( ItemStack stack );
|
||||
boolean canInsert(ItemStack stack);
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
@@ -36,171 +35,143 @@ import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor {
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IActionSource src;
|
||||
private int maxSlots = 0;
|
||||
|
||||
private final IMEInventory<IAEItemStack> target;
|
||||
private final IActionSource src;
|
||||
private int maxSlots = 0;
|
||||
public IMEAdaptor(final IMEInventory<IAEItemStack> input, final IActionSource src) {
|
||||
this.target = input;
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
public IMEAdaptor( final IMEInventory<IAEItemStack> input, final IActionSource src )
|
||||
{
|
||||
this.target = input;
|
||||
this.src = src;
|
||||
}
|
||||
@Override
|
||||
public boolean hasSlots() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator() {
|
||||
return new IMEAdaptorIterator(this, this.getList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new IMEAdaptorIterator( this, this.getList() );
|
||||
}
|
||||
private IItemList<IAEItemStack> getList() {
|
||||
return this.target.getAvailableItems(
|
||||
AEApi.instance().storage().getStorageChannel(IItemStorageChannel.class).createList());
|
||||
}
|
||||
|
||||
private IItemList<IAEItemStack> getList()
|
||||
{
|
||||
return this.target.getAvailableItems( AEApi.instance().storage().getStorageChannel( IItemStorageChannel.class ).createList() );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeItems(final int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
return this.doRemoveItems(amount, filter, destination, Actionable.MODULATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
private ItemStack doRemoveItems(final int amount, final ItemStack filter, final IInventoryDestination destination,
|
||||
final Actionable type) {
|
||||
IAEItemStack req = null;
|
||||
|
||||
private ItemStack doRemoveItems( final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type )
|
||||
{
|
||||
IAEItemStack req = null;
|
||||
if (filter.isEmpty()) {
|
||||
final IItemList<IAEItemStack> list = this.getList();
|
||||
if (!list.isEmpty()) {
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
} else {
|
||||
req = AEItemStack.fromItemStack(filter);
|
||||
}
|
||||
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
final IItemList<IAEItemStack> list = this.getList();
|
||||
if( !list.isEmpty() )
|
||||
{
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
req = AEItemStack.fromItemStack( filter );
|
||||
}
|
||||
IAEItemStack out = null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
if (req != null) {
|
||||
req.setStackSize(amount);
|
||||
out = this.target.extractItems(req, type, this.src);
|
||||
}
|
||||
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( amount );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
}
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateRemove(final int amount, final ItemStack filter, final IInventoryDestination destination) {
|
||||
return this.doRemoveItems(amount, filter, destination, Actionable.SIMULATE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
return this.doRemoveItems( amount, filter, destination, Actionable.SIMULATE );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(final int amount, final ItemStack filter, final FuzzyMode fuzzyMode,
|
||||
final IInventoryDestination destination) {
|
||||
if (filter.isEmpty()) {
|
||||
return this.doRemoveItems(amount, null, destination, Actionable.MODULATE);
|
||||
}
|
||||
return this.doRemoveItemsFuzzy(amount, filter, destination, Actionable.MODULATE, fuzzyMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
return this.doRemoveItems( amount, null, destination, Actionable.MODULATE );
|
||||
}
|
||||
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.MODULATE, fuzzyMode );
|
||||
}
|
||||
private ItemStack doRemoveItemsFuzzy(final int amount, final ItemStack filter,
|
||||
final IInventoryDestination destination, final Actionable type, final FuzzyMode fuzzyMode) {
|
||||
final IAEItemStack reqFilter = AEItemStack.fromItemStack(filter);
|
||||
if (reqFilter == null) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private ItemStack doRemoveItemsFuzzy( final int amount, final ItemStack filter, final IInventoryDestination destination, final Actionable type, final FuzzyMode fuzzyMode )
|
||||
{
|
||||
final IAEItemStack reqFilter = AEItemStack.fromItemStack( filter );
|
||||
if( reqFilter == null )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
IAEItemStack out = null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
for (final IAEItemStack req : ImmutableList.copyOf(this.getList().findFuzzy(reqFilter, fuzzyMode))) {
|
||||
if (req != null) {
|
||||
req.setStackSize(amount);
|
||||
out = this.target.extractItems(req, type, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for( final IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ) )
|
||||
{
|
||||
if( req != null )
|
||||
{
|
||||
req.setStackSize( amount );
|
||||
out = this.target.extractItems( req, type, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(final int amount, final ItemStack filter, final FuzzyMode fuzzyMode,
|
||||
final IInventoryDestination destination) {
|
||||
if (filter.isEmpty()) {
|
||||
return this.doRemoveItems(amount, ItemStack.EMPTY, destination, Actionable.SIMULATE);
|
||||
}
|
||||
return this.doRemoveItemsFuzzy(amount, filter, destination, Actionable.SIMULATE, fuzzyMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
if( filter.isEmpty() )
|
||||
{
|
||||
return this.doRemoveItems( amount, ItemStack.EMPTY, destination, Actionable.SIMULATE );
|
||||
}
|
||||
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.SIMULATE, fuzzyMode );
|
||||
}
|
||||
@Override
|
||||
public ItemStack addItems(final ItemStack toBeAdded) {
|
||||
final IAEItemStack in = AEItemStack.fromItemStack(toBeAdded);
|
||||
if (in != null) {
|
||||
final IAEItemStack out = this.target.injectItems(in, Actionable.MODULATE, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
final IAEItemStack in = AEItemStack.fromItemStack( toBeAdded );
|
||||
if( in != null )
|
||||
{
|
||||
final IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public ItemStack simulateAdd(final ItemStack toBeSimulated) {
|
||||
final IAEItemStack in = AEItemStack.fromItemStack(toBeSimulated);
|
||||
if (in != null) {
|
||||
final IAEItemStack out = this.target.injectItems(in, Actionable.SIMULATE, this.src);
|
||||
if (out != null) {
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
final IAEItemStack in = AEItemStack.fromItemStack( toBeSimulated );
|
||||
if( in != null )
|
||||
{
|
||||
final IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src );
|
||||
if( out != null )
|
||||
{
|
||||
return out.createItemStack();
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public boolean containsItems() {
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !this.getList().isEmpty();
|
||||
}
|
||||
int getMaxSlots() {
|
||||
return this.maxSlots;
|
||||
}
|
||||
|
||||
int getMaxSlots()
|
||||
{
|
||||
return this.maxSlots;
|
||||
}
|
||||
|
||||
void setMaxSlots( final int maxSlots )
|
||||
{
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
void setMaxSlots(final int maxSlots) {
|
||||
this.maxSlots = maxSlots;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -26,57 +25,49 @@ import net.minecraft.item.ItemStack;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public final class IMEAdaptorIterator implements Iterator<ItemSlot> {
|
||||
private final Iterator<IAEItemStack> stack;
|
||||
private final ItemSlot slot = new ItemSlot();
|
||||
private final IMEAdaptor parent;
|
||||
private final int containerSize;
|
||||
|
||||
public final class IMEAdaptorIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
private final Iterator<IAEItemStack> stack;
|
||||
private final ItemSlot slot = new ItemSlot();
|
||||
private final IMEAdaptor parent;
|
||||
private final int containerSize;
|
||||
private int offset = 0;
|
||||
private boolean hasNext;
|
||||
|
||||
private int offset = 0;
|
||||
private boolean hasNext;
|
||||
public IMEAdaptorIterator(final IMEAdaptor parent, final IItemList<IAEItemStack> availableItems) {
|
||||
this.stack = availableItems.iterator();
|
||||
this.containerSize = parent.getMaxSlots();
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
public IMEAdaptorIterator( final IMEAdaptor parent, final IItemList<IAEItemStack> availableItems )
|
||||
{
|
||||
this.stack = availableItems.iterator();
|
||||
this.containerSize = parent.getMaxSlots();
|
||||
this.parent = parent;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
this.hasNext = this.stack.hasNext();
|
||||
return this.offset < this.containerSize || this.hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
this.hasNext = this.stack.hasNext();
|
||||
return this.offset < this.containerSize || this.hasNext;
|
||||
}
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
this.slot.setSlot(this.offset);
|
||||
this.offset++;
|
||||
this.slot.setExtractable(true);
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
this.slot.setSlot( this.offset );
|
||||
this.offset++;
|
||||
this.slot.setExtractable( true );
|
||||
if (this.parent.getMaxSlots() < this.offset) {
|
||||
this.parent.setMaxSlots(this.offset);
|
||||
}
|
||||
|
||||
if( this.parent.getMaxSlots() < this.offset )
|
||||
{
|
||||
this.parent.setMaxSlots( this.offset );
|
||||
}
|
||||
if (this.hasNext) {
|
||||
final IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack(item);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
if( this.hasNext )
|
||||
{
|
||||
final IAEItemStack item = this.stack.next();
|
||||
this.slot.setAEItemStack( item );
|
||||
return this.slot;
|
||||
}
|
||||
this.slot.setItemStack(ItemStack.EMPTY);
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
this.slot.setItemStack( ItemStack.EMPTY );
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
@Override
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -26,32 +25,26 @@ import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination {
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination
|
||||
{
|
||||
private final IMEInventory<IAEItemStack> me;
|
||||
|
||||
private final IMEInventory<IAEItemStack> me;
|
||||
public IMEInventoryDestination(final IMEInventory<IAEItemStack> o) {
|
||||
this.me = o;
|
||||
}
|
||||
|
||||
public IMEInventoryDestination( final IMEInventory<IAEItemStack> o )
|
||||
{
|
||||
this.me = o;
|
||||
}
|
||||
@Override
|
||||
public boolean canInsert(final ItemStack stack) {
|
||||
|
||||
@Override
|
||||
public boolean canInsert( final ItemStack stack )
|
||||
{
|
||||
if (stack.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final IAEItemStack failed = this.me.injectItems(AEItemStack.fromItemStack(stack), Actionable.SIMULATE, null);
|
||||
|
||||
final IAEItemStack failed = this.me.injectItems( AEItemStack.fromItemStack( stack ), Actionable.SIMULATE, null );
|
||||
|
||||
if( failed == null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return failed.getStackSize() != stack.getCount();
|
||||
}
|
||||
if (failed == null) {
|
||||
return true;
|
||||
}
|
||||
return failed.getStackSize() != stack.getCount();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,8 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
public enum InvOperation
|
||||
{
|
||||
EXTRACT, INSERT, SET
|
||||
public enum InvOperation {
|
||||
EXTRACT, INSERT, SET
|
||||
}
|
||||
|
||||
@@ -18,45 +18,38 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
class ItemHandlerIterator implements Iterator<ItemSlot> {
|
||||
|
||||
class ItemHandlerIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
private final IItemHandler itemHandler;
|
||||
|
||||
private final IItemHandler itemHandler;
|
||||
private final ItemSlot itemSlot = new ItemSlot();
|
||||
|
||||
private final ItemSlot itemSlot = new ItemSlot();
|
||||
private int slot = 0;
|
||||
|
||||
private int slot = 0;
|
||||
ItemHandlerIterator(IItemHandler itemHandler) {
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
ItemHandlerIterator( IItemHandler itemHandler )
|
||||
{
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return this.slot < this.itemHandler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.slot < this.itemHandler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
if( this.slot >= this.itemHandler.getSlots() )
|
||||
{
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable( !this.itemHandler.extractItem( this.slot, 1, true ).isEmpty() );
|
||||
this.itemSlot.setItemStack( this.itemHandler.getStackInSlot( this.slot ) );
|
||||
this.itemSlot.setSlot( this.slot );
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
@Override
|
||||
public ItemSlot next() {
|
||||
if (this.slot >= this.itemHandler.getSlots()) {
|
||||
throw new NoSuchElementException();
|
||||
}
|
||||
this.itemSlot.setExtractable(!this.itemHandler.extractItem(this.slot, 1, true).isEmpty());
|
||||
this.itemSlot.setItemStack(this.itemHandler.getStackInSlot(this.slot));
|
||||
this.itemSlot.setSlot(this.slot);
|
||||
this.slot++;
|
||||
return this.itemSlot;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
@@ -26,86 +25,71 @@ import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.storage.data.IAEStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T> {
|
||||
|
||||
public class ItemListIgnoreCrafting<T extends IAEStack<T>> implements IItemList<T>
|
||||
{
|
||||
private final IItemList<T> target;
|
||||
|
||||
private final IItemList<T> target;
|
||||
public ItemListIgnoreCrafting(final IItemList<T> cla) {
|
||||
this.target = cla;
|
||||
}
|
||||
|
||||
public ItemListIgnoreCrafting( final IItemList<T> cla )
|
||||
{
|
||||
this.target = cla;
|
||||
}
|
||||
@Override
|
||||
public void add(T option) {
|
||||
if (option != null && option.isCraftable()) {
|
||||
option = option.copy();
|
||||
option.setCraftable(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add( T option )
|
||||
{
|
||||
if( option != null && option.isCraftable() )
|
||||
{
|
||||
option = option.copy();
|
||||
option.setCraftable( false );
|
||||
}
|
||||
this.target.add(option);
|
||||
}
|
||||
|
||||
this.target.add( option );
|
||||
}
|
||||
@Override
|
||||
public T findPrecise(final T i) {
|
||||
return this.target.findPrecise(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise( final T i )
|
||||
{
|
||||
return this.target.findPrecise( i );
|
||||
}
|
||||
@Override
|
||||
public Collection<T> findFuzzy(final T input, final FuzzyMode fuzzy) {
|
||||
return this.target.findFuzzy(input, fuzzy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy( final T input, final FuzzyMode fuzzy )
|
||||
{
|
||||
return this.target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.target.isEmpty();
|
||||
}
|
||||
@Override
|
||||
public void addStorage(final T option) {
|
||||
this.target.addStorage(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage( final T option )
|
||||
{
|
||||
this.target.addStorage( option );
|
||||
}
|
||||
@Override
|
||||
public void addCrafting(final T option) {
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting( final T option )
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
@Override
|
||||
public void addRequestable(final T option) {
|
||||
this.target.addRequestable(option);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable( final T option )
|
||||
{
|
||||
this.target.addRequestable( option );
|
||||
}
|
||||
@Override
|
||||
public T getFirstItem() {
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem()
|
||||
{
|
||||
return this.target.getFirstItem();
|
||||
}
|
||||
@Override
|
||||
public int size() {
|
||||
return this.target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return this.target.size();
|
||||
}
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return this.target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
this.target.resetStatus();
|
||||
}
|
||||
@Override
|
||||
public void resetStatus() {
|
||||
this.target.resetStatus();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,63 +18,54 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class ItemSlot {
|
||||
|
||||
public class ItemSlot
|
||||
{
|
||||
private int slot;
|
||||
private boolean isExtractable;
|
||||
// one or the other..
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
private int slot;
|
||||
private boolean isExtractable;
|
||||
// one or the other..
|
||||
private IAEItemStack aeItemStack;
|
||||
private ItemStack itemStack;
|
||||
public ItemStack getItemStack() {
|
||||
return this.itemStack.isEmpty()
|
||||
? (this.aeItemStack == null ? ItemStack.EMPTY : (this.itemStack = this.aeItemStack.createItemStack()))
|
||||
: this.itemStack;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return this.itemStack
|
||||
.isEmpty() ? ( this.aeItemStack == null ? ItemStack.EMPTY : ( this.itemStack = this.aeItemStack.createItemStack() ) ) : this.itemStack;
|
||||
}
|
||||
public void setItemStack(final ItemStack is) {
|
||||
this.aeItemStack = null;
|
||||
this.itemStack = is;
|
||||
}
|
||||
|
||||
public void setItemStack( final ItemStack is )
|
||||
{
|
||||
this.aeItemStack = null;
|
||||
this.itemStack = is;
|
||||
}
|
||||
public IAEItemStack getAEItemStack() {
|
||||
return this.aeItemStack == null
|
||||
? (this.itemStack.isEmpty() ? null : (this.aeItemStack = AEItemStack.fromItemStack(this.itemStack)))
|
||||
: this.aeItemStack;
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return this.aeItemStack == null ? ( this.itemStack
|
||||
.isEmpty() ? null : ( this.aeItemStack = AEItemStack.fromItemStack( this.itemStack ) ) ) : this.aeItemStack;
|
||||
}
|
||||
void setAEItemStack(final IAEItemStack is) {
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
void setAEItemStack( final IAEItemStack is )
|
||||
{
|
||||
this.aeItemStack = is;
|
||||
this.itemStack = ItemStack.EMPTY;
|
||||
}
|
||||
public boolean isExtractable() {
|
||||
return this.isExtractable;
|
||||
}
|
||||
|
||||
public boolean isExtractable()
|
||||
{
|
||||
return this.isExtractable;
|
||||
}
|
||||
void setExtractable(final boolean isExtractable) {
|
||||
this.isExtractable = isExtractable;
|
||||
}
|
||||
|
||||
void setExtractable( final boolean isExtractable )
|
||||
{
|
||||
this.isExtractable = isExtractable;
|
||||
}
|
||||
public int getSlot() {
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public int getSlot()
|
||||
{
|
||||
return this.slot;
|
||||
}
|
||||
|
||||
public void setSlot( final int slot )
|
||||
{
|
||||
this.slot = slot;
|
||||
}
|
||||
public void setSlot(final int slot) {
|
||||
this.slot = slot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
@@ -30,141 +29,118 @@ import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
public class WrapperChainedItemHandler implements IItemHandlerModifiable {
|
||||
private IItemHandler[] itemHandler; // the handlers
|
||||
private int[] baseIndex; // index-offsets of the different handlers
|
||||
private int slotCount; // number of total slots
|
||||
|
||||
public class WrapperChainedItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private IItemHandler[] itemHandler; // the handlers
|
||||
private int[] baseIndex; // index-offsets of the different handlers
|
||||
private int slotCount; // number of total slots
|
||||
public WrapperChainedItemHandler(IItemHandler... itemHandler) {
|
||||
this.setItemHandlers(itemHandler);
|
||||
}
|
||||
|
||||
public WrapperChainedItemHandler( IItemHandler... itemHandler )
|
||||
{
|
||||
this.setItemHandlers( itemHandler );
|
||||
}
|
||||
private void setItemHandlers(IItemHandler[] handlers) {
|
||||
this.itemHandler = handlers;
|
||||
this.baseIndex = new int[this.itemHandler.length];
|
||||
int index = 0;
|
||||
for (int i = 0; i < this.itemHandler.length; i++) {
|
||||
index += this.itemHandler[i].getSlots();
|
||||
this.baseIndex[i] = index;
|
||||
}
|
||||
this.slotCount = index;
|
||||
}
|
||||
|
||||
private void setItemHandlers( IItemHandler[] handlers )
|
||||
{
|
||||
this.itemHandler = handlers;
|
||||
this.baseIndex = new int[this.itemHandler.length];
|
||||
int index = 0;
|
||||
for( int i = 0; i < this.itemHandler.length; i++ )
|
||||
{
|
||||
index += this.itemHandler[i].getSlots();
|
||||
this.baseIndex[i] = index;
|
||||
}
|
||||
this.slotCount = index;
|
||||
}
|
||||
// returns the handler index for the slot
|
||||
private int getIndexForSlot(int slot) {
|
||||
if (slot < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
// returns the handler index for the slot
|
||||
private int getIndexForSlot( int slot )
|
||||
{
|
||||
if( slot < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
for (int i = 0; i < this.baseIndex.length; i++) {
|
||||
if (slot - this.baseIndex[i] < 0) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( int i = 0; i < this.baseIndex.length; i++ )
|
||||
{
|
||||
if( slot - this.baseIndex[i] < 0 )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
private IItemHandler getHandlerFromIndex(int index) {
|
||||
if (index < 0 || index >= this.itemHandler.length) {
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
return this.itemHandler[index];
|
||||
}
|
||||
|
||||
private IItemHandler getHandlerFromIndex( int index )
|
||||
{
|
||||
if( index < 0 || index >= this.itemHandler.length )
|
||||
{
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
return this.itemHandler[index];
|
||||
}
|
||||
private int getSlotFromIndex(int slot, int index) {
|
||||
if (index <= 0 || index >= this.baseIndex.length) {
|
||||
return slot;
|
||||
}
|
||||
return slot - this.baseIndex[index - 1];
|
||||
}
|
||||
|
||||
private int getSlotFromIndex( int slot, int index )
|
||||
{
|
||||
if( index <= 0 || index >= this.baseIndex.length )
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
return slot - this.baseIndex[index - 1];
|
||||
}
|
||||
public void cycleOrder() {
|
||||
if (this.itemHandler.length > 1) {
|
||||
ArrayList<IItemHandler> newOrder = new ArrayList<>();
|
||||
newOrder.add(this.itemHandler[this.itemHandler.length - 1]);
|
||||
for (int i = 0; i < this.itemHandler.length - 1; ++i) {
|
||||
newOrder.add(this.itemHandler[i]);
|
||||
}
|
||||
this.setItemHandlers(newOrder.toArray(new IItemHandler[this.itemHandler.length]));
|
||||
}
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
{
|
||||
if( this.itemHandler.length > 1 )
|
||||
{
|
||||
ArrayList<IItemHandler> newOrder = new ArrayList<>();
|
||||
newOrder.add( this.itemHandler[this.itemHandler.length - 1] );
|
||||
for( int i = 0; i < this.itemHandler.length - 1; ++i )
|
||||
{
|
||||
newOrder.add( this.itemHandler[i] );
|
||||
}
|
||||
this.setItemHandlers( newOrder.toArray( new IItemHandler[this.itemHandler.length] ) );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.slotCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.slotCount;
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot(final int slot) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.getStackInSlot(targetSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( final int slot )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.getStackInSlot( targetSlot );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(final int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.insertItem(targetSlot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( final int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.insertItem( targetSlot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.extractItem(targetSlot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.extractItem( targetSlot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int localSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.getSlotLimit(localSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int localSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.getSlotLimit( localSlot );
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
ItemHandlerUtil.setStackInSlot(handler, targetSlot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
ItemHandlerUtil.setStackInSlot( handler, targetSlot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
int index = this.getIndexForSlot( slot );
|
||||
IItemHandler handler = this.getHandlerFromIndex( index );
|
||||
int targetSlot = this.getSlotFromIndex( slot, index );
|
||||
return handler.isItemValid( targetSlot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
int index = this.getIndexForSlot(slot);
|
||||
IItemHandler handler = this.getHandlerFromIndex(index);
|
||||
int targetSlot = this.getSlotFromIndex(slot, index);
|
||||
return handler.isItemValid(targetSlot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,26 +18,21 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler {
|
||||
private final PlayerInventory inv;
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler
|
||||
{
|
||||
private final PlayerInventory inv;
|
||||
public WrapperCursorItemHandler(PlayerInventory PlayerInventory) {
|
||||
super(1);
|
||||
|
||||
public WrapperCursorItemHandler( PlayerInventory PlayerInventory )
|
||||
{
|
||||
super( 1 );
|
||||
this.inv = PlayerInventory;
|
||||
this.setStackInSlot(0, PlayerInventory.getItemStack());
|
||||
}
|
||||
|
||||
this.inv = PlayerInventory;
|
||||
this.setStackInSlot( 0, PlayerInventory.getItemStack() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
this.inv.setItemStack( this.getStackInSlot( slot ) );
|
||||
}
|
||||
@Override
|
||||
protected void onContentsChanged(int slot) {
|
||||
this.inv.setItemStack(this.getStackInSlot(slot));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -28,71 +27,58 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
public class WrapperFilteredItemHandler implements IItemHandlerModifiable {
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter filter;
|
||||
|
||||
public class WrapperFilteredItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter filter;
|
||||
public WrapperFilteredItemHandler(@Nonnull IItemHandler handler, @Nonnull IAEItemFilter filter) {
|
||||
this.handler = handler;
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
public WrapperFilteredItemHandler( @Nonnull IItemHandler handler, @Nonnull IAEItemFilter filter )
|
||||
{
|
||||
this.handler = handler;
|
||||
this.filter = filter;
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.handler, slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.handler, slot, stack );
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.handler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.handler.getSlots();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return this.handler.getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return this.handler.getStackInSlot( slot );
|
||||
}
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
if (!this.filter.allowInsert(this.handler, slot, stack)) {
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( !this.filter.allowInsert( this.handler, slot, stack ) )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
return this.handler.insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
return this.handler.insertItem( slot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (!this.filter.allowExtract(this.handler, slot, amount)) {
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( !this.filter.allowExtract( this.handler, slot, amount ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
return this.handler.extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
return this.handler.extractItem( slot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.handler.getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return this.handler.getSlotLimit( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( !this.filter.allowInsert( this.handler, slot, stack ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return this.handler.isItemValid( slot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
if (!this.filter.allowInsert(this.handler, slot, stack)) {
|
||||
return false;
|
||||
}
|
||||
return this.handler.isItemValid(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,97 +26,80 @@ import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
public class WrapperInvItemHandler implements IInventory {
|
||||
private final IItemHandler inv;
|
||||
|
||||
public class WrapperInvItemHandler implements IInventory
|
||||
{
|
||||
private final IItemHandler inv;
|
||||
public WrapperInvItemHandler(final IItemHandler inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public WrapperInvItemHandler( final IItemHandler inv )
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
@Override
|
||||
public int getSizeInventory() {
|
||||
return this.inv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.inv.getSlots();
|
||||
}
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return ItemHandlerUtil.isEmpty(this.inv);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return ItemHandlerUtil.isEmpty( this.inv );
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int index) {
|
||||
return this.inv.getStackInSlot(index);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int index )
|
||||
{
|
||||
return this.inv.getStackInSlot( index );
|
||||
}
|
||||
@Override
|
||||
public ItemStack decrStackSize(int index, int count) {
|
||||
return this.inv.extractItem(index, count, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( int index, int count )
|
||||
{
|
||||
return this.inv.extractItem( index, count, false );
|
||||
}
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot(int index) {
|
||||
return this.inv.extractItem(index, this.inv.getSlotLimit(index), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( int index )
|
||||
{
|
||||
return this.inv.extractItem( index, this.inv.getSlotLimit( index ), false );
|
||||
}
|
||||
@Override
|
||||
public void setInventorySlotContents(int index, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.inv, index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( int index, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.inv, index, stack );
|
||||
}
|
||||
@Override
|
||||
public int getInventoryStackLimit() {
|
||||
int max = 0;
|
||||
for (int i = 0; i < this.inv.getSlots(); ++i) {
|
||||
max = Math.max(max, this.inv.getSlotLimit(i));
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int max = 0;
|
||||
for( int i = 0; i < this.inv.getSlots(); ++i )
|
||||
{
|
||||
max = Math.max( max, this.inv.getSlotLimit( i ) );
|
||||
}
|
||||
return max;
|
||||
}
|
||||
@Override
|
||||
public void markDirty() {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public boolean isUsableByPlayer(PlayerEntity player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( PlayerEntity player )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void openInventory(PlayerEntity player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( PlayerEntity player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public void closeInventory(PlayerEntity player) {
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( PlayerEntity player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int index, ItemStack stack) {
|
||||
return this.inv.isItemValid(index, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int index, ItemStack stack )
|
||||
{
|
||||
return this.inv.isItemValid( index, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
ItemHandlerUtil.clear( this.inv );
|
||||
}
|
||||
@Override
|
||||
public void clear() {
|
||||
ItemHandlerUtil.clear(this.inv);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,94 +26,77 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
public class WrapperRangeItemHandler implements IItemHandlerModifiable {
|
||||
private final IItemHandler compose;
|
||||
private final int minSlot;
|
||||
private final int maxSlot;
|
||||
|
||||
public class WrapperRangeItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final IItemHandler compose;
|
||||
private final int minSlot;
|
||||
private final int maxSlot;
|
||||
public WrapperRangeItemHandler(IItemHandler compose, int minSlot, int maxSlotExclusive) {
|
||||
this.compose = compose;
|
||||
this.minSlot = minSlot;
|
||||
this.maxSlot = maxSlotExclusive;
|
||||
}
|
||||
|
||||
public WrapperRangeItemHandler( IItemHandler compose, int minSlot, int maxSlotExclusive )
|
||||
{
|
||||
this.compose = compose;
|
||||
this.minSlot = minSlot;
|
||||
this.maxSlot = maxSlotExclusive;
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.maxSlot - this.minSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.maxSlot - this.minSlot;
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.getStackInSlot(slot + this.minSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.getStackInSlot( slot + this.minSlot );
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.insertItem(slot + this.minSlot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.insertItem( slot + this.minSlot, stack, simulate );
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.extractItem(slot + this.minSlot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.extractItem( slot + this.minSlot, amount, simulate );
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, @Nonnull ItemStack stack) {
|
||||
if (this.checkSlot(slot)) {
|
||||
ItemHandlerUtil.setStackInSlot(this.compose, slot + this.minSlot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.compose, slot + this.minSlot, stack );
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.getSlotLimit(slot + this.minSlot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.getSlotLimit( slot + this.minSlot );
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
private boolean checkSlot(int localSlot) {
|
||||
return localSlot + this.minSlot < this.maxSlot;
|
||||
}
|
||||
|
||||
private boolean checkSlot( int localSlot )
|
||||
{
|
||||
return localSlot + this.minSlot < this.maxSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
if( this.checkSlot( slot ) )
|
||||
{
|
||||
return this.compose.isItemValid( slot + this.minSlot, stack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
if (this.checkSlot(slot)) {
|
||||
return this.compose.isItemValid(slot + this.minSlot, stack);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
@@ -27,55 +26,45 @@ import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
public class WrapperSupplierItemHandler implements IItemHandlerModifiable {
|
||||
private final Supplier<IItemHandler> sourceHandler;
|
||||
|
||||
public class WrapperSupplierItemHandler implements IItemHandlerModifiable
|
||||
{
|
||||
private final Supplier<IItemHandler> sourceHandler;
|
||||
public WrapperSupplierItemHandler(Supplier<IItemHandler> source) {
|
||||
this.sourceHandler = source;
|
||||
}
|
||||
|
||||
public WrapperSupplierItemHandler( Supplier<IItemHandler> source )
|
||||
{
|
||||
this.sourceHandler = source;
|
||||
}
|
||||
@Override
|
||||
public int getSlots() {
|
||||
return this.sourceHandler.get().getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return this.sourceHandler.get().getSlots();
|
||||
}
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int slot) {
|
||||
return this.sourceHandler.get().getStackInSlot(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return this.sourceHandler.get().getStackInSlot( slot );
|
||||
}
|
||||
@Override
|
||||
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate) {
|
||||
return this.sourceHandler.get().insertItem(slot, stack, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
return this.sourceHandler.get().insertItem( slot, stack, simulate );
|
||||
}
|
||||
@Override
|
||||
public ItemStack extractItem(int slot, int amount, boolean simulate) {
|
||||
return this.sourceHandler.get().extractItem(slot, amount, simulate);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
return this.sourceHandler.get().extractItem( slot, amount, simulate );
|
||||
}
|
||||
@Override
|
||||
public int getSlotLimit(int slot) {
|
||||
return this.sourceHandler.get().getSlotLimit(slot);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return this.sourceHandler.get().getSlotLimit( slot );
|
||||
}
|
||||
@Override
|
||||
public void setStackInSlot(int slot, ItemStack stack) {
|
||||
ItemHandlerUtil.setStackInSlot(this.sourceHandler.get(), slot, stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( this.sourceHandler.get(), slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid( int slot, ItemStack stack )
|
||||
{
|
||||
return this.sourceHandler.get().isItemValid( slot, stack );
|
||||
}
|
||||
@Override
|
||||
public boolean isItemValid(int slot, ItemStack stack) {
|
||||
return this.sourceHandler.get().isItemValid(slot, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,32 +18,26 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.definitions.IItemDefinition;
|
||||
|
||||
public class AEItemDefinitionFilter implements IAEItemFilter {
|
||||
private final IItemDefinition definition;
|
||||
|
||||
public class AEItemDefinitionFilter implements IAEItemFilter
|
||||
{
|
||||
private final IItemDefinition definition;
|
||||
public AEItemDefinitionFilter(IItemDefinition definition) {
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
public AEItemDefinitionFilter( IItemDefinition definition )
|
||||
{
|
||||
this.definition = definition;
|
||||
}
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return this.definition.isSameAs( stack );
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return this.definition.isSameAs(stack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,47 +18,37 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public class AEItemFilters {
|
||||
public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter();
|
||||
public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter();
|
||||
|
||||
public class AEItemFilters
|
||||
{
|
||||
public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter();
|
||||
public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter();
|
||||
private AEItemFilters() {
|
||||
}
|
||||
|
||||
private AEItemFilters()
|
||||
{
|
||||
}
|
||||
private static class InsertOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class InsertOnlyFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
private static class ExtractOnlyFilter implements IAEItemFilter {
|
||||
@Override
|
||||
public boolean allowExtract(IItemHandler inv, int slot, int amount) {
|
||||
return true;
|
||||
}
|
||||
|
||||
private static class ExtractOnlyFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert(IItemHandler inv, int slot, ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,14 +18,11 @@
|
||||
|
||||
package appeng.util.inv.filter;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
public interface IAEItemFilter {
|
||||
boolean allowExtract(IItemHandler inv, int slot, int amount);
|
||||
|
||||
public interface IAEItemFilter
|
||||
{
|
||||
boolean allowExtract( IItemHandler inv, int slot, int amount );
|
||||
|
||||
boolean allowInsert( IItemHandler inv, int slot, ItemStack stack );
|
||||
boolean allowInsert(IItemHandler inv, int slot, ItemStack stack);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user