Use IItemHandler instead of IInventory internally (#2971)
* Use IItemHandler instead of IInventory internally
This commit is contained in:
@@ -1,368 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
public class AdaptorIInventory extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private final IInventory i;
|
||||
private final boolean wrapperEnabled;
|
||||
|
||||
public AdaptorIInventory( final IInventory s )
|
||||
{
|
||||
this.i = s;
|
||||
this.wrapperEnabled = s instanceof IInventoryWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.getSizeInventory();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
for( int x = 0; x < s && amount > 0; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.getStackInSlot( x );
|
||||
if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
int boundAmounts = amount;
|
||||
if( boundAmounts > is.getCount() )
|
||||
{
|
||||
boundAmounts = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
boundAmounts = 0;
|
||||
}
|
||||
|
||||
if( boundAmounts > 0 )
|
||||
{
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
rv = is.copy();
|
||||
filter = rv;
|
||||
rv.setCount( boundAmounts );
|
||||
amount -= boundAmounts;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.grow( boundAmounts );
|
||||
amount -= boundAmounts;
|
||||
}
|
||||
|
||||
if( is.getCount() == boundAmounts )
|
||||
{
|
||||
this.i.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
this.i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack po = is.copy();
|
||||
po.grow( -boundAmounts );
|
||||
this.i.setInventorySlotContents( x, po );
|
||||
this.i.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if ( rv != null )
|
||||
// i.markDirty();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.getSizeInventory();
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
|
||||
for( int x = 0; x < s && amount > 0; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.getStackInSlot( x );
|
||||
if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) )
|
||||
{
|
||||
int boundAmount = amount;
|
||||
if( boundAmount > is.getCount() )
|
||||
{
|
||||
boundAmount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
boundAmount = 0;
|
||||
}
|
||||
|
||||
if( boundAmount > 0 )
|
||||
{
|
||||
if( rv.isEmpty() )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.setCount( boundAmount );
|
||||
amount -= boundAmount;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.grow( boundAmount );
|
||||
amount -= boundAmount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.getStackInSlot( x );
|
||||
if( !is.isEmpty() && this.canRemoveStackFromSlot( x,
|
||||
is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int newAmount = amount;
|
||||
if( newAmount > is.getCount() )
|
||||
{
|
||||
newAmount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
newAmount = 0;
|
||||
}
|
||||
|
||||
ItemStack rv = ItemStack.EMPTY;
|
||||
if( newAmount > 0 )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.setCount( newAmount );
|
||||
|
||||
if( is.getCount() == rv.getCount() )
|
||||
{
|
||||
this.i.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
this.i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
final ItemStack po = is.copy();
|
||||
po.grow( -rv.getCount() );
|
||||
this.i.setInventorySlotContents( x, po );
|
||||
this.i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if( !rv.isEmpty() )
|
||||
{
|
||||
// i.markDirty();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
final int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
final ItemStack is = this.i.getStackInSlot( x );
|
||||
|
||||
if( !is.isEmpty() && this.canRemoveStackFromSlot( x,
|
||||
is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) )
|
||||
{
|
||||
int boundAmount = amount;
|
||||
if( boundAmount > is.getCount() )
|
||||
{
|
||||
boundAmount = is.getCount();
|
||||
}
|
||||
if( destination != null && !destination.canInsert( is ) )
|
||||
{
|
||||
boundAmount = 0;
|
||||
}
|
||||
|
||||
if( boundAmount > 0 )
|
||||
{
|
||||
final ItemStack rv = is.copy();
|
||||
rv.setCount( boundAmount );
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
return this.addItems( toBeAdded, true );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
return this.addItems( toBeSimulated, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
final int s = this.i.getSizeInventory();
|
||||
for( int x = 0; x < s; x++ )
|
||||
{
|
||||
if( !this.i.getStackInSlot( x ).isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an {@link ItemStack} to the adapted {@link IInventory}.
|
||||
*
|
||||
* It respects the inventories stack limit, which can result in not all items added and some left ones are returned.
|
||||
* The ItemStack next is required for inventories, which will fail on isItemValidForSlot() for stacksizes larger
|
||||
* than the limit.
|
||||
*
|
||||
* @param itemsToAdd itemStack to add to the inventory
|
||||
* @param modulate true to modulate, false for simulate
|
||||
*
|
||||
* @return the left itemstack, which could not be added
|
||||
*/
|
||||
private ItemStack addItems( final ItemStack itemsToAdd, final boolean modulate )
|
||||
{
|
||||
if( itemsToAdd.isEmpty() || itemsToAdd.getCount() == 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
final ItemStack left = itemsToAdd.copy();
|
||||
final int stackLimit = itemsToAdd.getMaxStackSize();
|
||||
final int perOperationLimit = Math.min( this.i.getInventoryStackLimit(), stackLimit );
|
||||
final int inventorySize = this.i.getSizeInventory();
|
||||
|
||||
for( int slot = 0; slot < inventorySize; slot++ )
|
||||
{
|
||||
final ItemStack next = left.copy();
|
||||
next.setCount( Math.min( perOperationLimit, next.getCount() ) );
|
||||
|
||||
if( this.i.isItemValidForSlot( slot, next ) )
|
||||
{
|
||||
final ItemStack is = this.i.getStackInSlot( slot );
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
left.grow( -next.getCount() );
|
||||
|
||||
if( modulate )
|
||||
{
|
||||
this.i.setInventorySlotContents( slot, next );
|
||||
this.i.markDirty();
|
||||
}
|
||||
|
||||
if( left.getCount() <= 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
else if( Platform.itemComparisons().isSameItem( is, left ) && is.getCount() < perOperationLimit )
|
||||
{
|
||||
final int room = perOperationLimit - is.getCount();
|
||||
final int used = Math.min( left.getCount(), room );
|
||||
|
||||
if( modulate )
|
||||
{
|
||||
is.grow( used );
|
||||
this.i.setInventorySlotContents( slot, is );
|
||||
this.i.markDirty();
|
||||
}
|
||||
|
||||
left.grow( -used );
|
||||
if( left.getCount() <= 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
private boolean canRemoveStackFromSlot( final int x, final ItemStack is )
|
||||
{
|
||||
if( this.wrapperEnabled )
|
||||
{
|
||||
return ( (IInventoryWrapper) this.i ).canRemoveItemFromSlot( x, is );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new InvIterator();
|
||||
}
|
||||
|
||||
private class InvIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
private final ItemSlot is = new ItemSlot();
|
||||
private int x = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return this.x < AdaptorIInventory.this.i.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
final ItemStack iss = AdaptorIInventory.this.i.getStackInSlot( this.x );
|
||||
|
||||
this.is.setExtractable( AdaptorIInventory.this.canRemoveStackFromSlot( this.x, iss ) );
|
||||
this.is.setItemStack( iss );
|
||||
|
||||
this.is.setSlot( this.x );
|
||||
this.x++;
|
||||
return this.is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// nothing!
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -38,6 +38,12 @@ public class AdaptorItemHandler extends InventoryAdaptor
|
||||
this.itemHandler = itemHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return itemHandler.getSlots() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
|
||||
{
|
||||
|
||||
@@ -40,6 +40,12 @@ public class AdaptorList extends InventoryAdaptor
|
||||
this.i = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return !i.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
|
||||
@@ -1,237 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
|
||||
/*
|
||||
* Lets you do simply tests with the players cursor, without messing with the specifics.
|
||||
*/
|
||||
public class AdaptorPlayerHand extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private final EntityPlayer player;
|
||||
|
||||
public AdaptorPlayerHand( final EntityPlayer player )
|
||||
{
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( filter.isEmpty() || Platform.itemComparisons().isSameItem( filter, hand ) )
|
||||
{
|
||||
final ItemStack result = hand.copy();
|
||||
result.setCount( hand.getCount() > amount ? amount : hand.getCount() );
|
||||
hand.grow( -amount );
|
||||
if( hand.getCount() <= 0 )
|
||||
{
|
||||
this.player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove( final int amount, final ItemStack filter, final IInventoryDestination destination )
|
||||
{
|
||||
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( filter == null || Platform.itemComparisons().isSameItem( filter, hand ) )
|
||||
{
|
||||
final ItemStack result = hand.copy();
|
||||
result.setCount( hand.getCount() > amount ? amount : hand.getCount() );
|
||||
return result;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) )
|
||||
{
|
||||
final ItemStack result = hand.copy();
|
||||
result.setCount( hand.getCount() > amount ? amount : hand.getCount() );
|
||||
hand.grow( -amount );
|
||||
if( hand.getCount() <= 0 )
|
||||
{
|
||||
this.player.inventory.setItemStack( ItemStack.EMPTY );
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination )
|
||||
{
|
||||
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) )
|
||||
{
|
||||
final ItemStack result = hand.copy();
|
||||
result.setCount( hand.getCount() > amount ? amount : hand.getCount() );
|
||||
return result;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems( final ItemStack toBeAdded )
|
||||
{
|
||||
|
||||
if( toBeAdded.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if( toBeAdded.getCount() == 0 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
if( this.player == null )
|
||||
{
|
||||
return toBeAdded;
|
||||
}
|
||||
if( this.player.inventory == null )
|
||||
{
|
||||
return toBeAdded;
|
||||
}
|
||||
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
|
||||
if( !hand.isEmpty() && !Platform.itemComparisons().isSameItem( toBeAdded, hand ) )
|
||||
{
|
||||
return toBeAdded;
|
||||
}
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = ItemStack.EMPTY;
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
newHand = toBeAdded.copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
newHand = hand;
|
||||
original = hand.getCount();
|
||||
newHand.grow( toBeAdded.getCount() );
|
||||
}
|
||||
|
||||
if( newHand.getCount() > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.setCount( newHand.getMaxStackSize() );
|
||||
final ItemStack B = toBeAdded.copy();
|
||||
B.grow( -( newHand.getCount() - original ) );
|
||||
this.player.inventory.setItemStack( newHand );
|
||||
return B;
|
||||
}
|
||||
|
||||
this.player.inventory.setItemStack( newHand );
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd( final ItemStack toBeSimulated )
|
||||
{
|
||||
final ItemStack hand = this.player.inventory.getItemStack();
|
||||
if( toBeSimulated.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
if( !hand.isEmpty() && !Platform.itemComparisons().isEqualItem( toBeSimulated, hand ) )
|
||||
{
|
||||
return toBeSimulated;
|
||||
}
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = ItemStack.EMPTY;
|
||||
if( hand.isEmpty() )
|
||||
{
|
||||
newHand = toBeSimulated.copy();
|
||||
}
|
||||
else
|
||||
{
|
||||
newHand = hand.copy();
|
||||
original = hand.getCount();
|
||||
newHand.grow( toBeSimulated.getCount() );
|
||||
}
|
||||
|
||||
if( newHand.getCount() > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.setCount( newHand.getMaxStackSize() );
|
||||
final ItemStack B = toBeSimulated.copy();
|
||||
B.grow( -( newHand.getCount() - original ) );
|
||||
return B;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !this.player.inventory.getItemStack().isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new NullIterator<>();
|
||||
}
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
public class AdaptorPlayerInventory implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory src;
|
||||
private final int min = 0;
|
||||
private final int size = 36;
|
||||
|
||||
public AdaptorPlayerInventory( final IInventory playerInv, final boolean swap )
|
||||
{
|
||||
|
||||
if( swap )
|
||||
{
|
||||
this.src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, this.size - 9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.src = playerInv;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int var1 )
|
||||
{
|
||||
return this.src.getStackInSlot( var1 + this.min );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int var1, final int var2 )
|
||||
{
|
||||
return this.src.decrStackSize( this.min + var1, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int var1 )
|
||||
{
|
||||
return this.src.removeStackFromSlot( this.min + var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int var1, final ItemStack var2 )
|
||||
{
|
||||
this.src.setInventorySlotContents( var1 + this.min, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return this.src.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
this.src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
{
|
||||
return this.src.isUsableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
this.src.openInventory( player );
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
this.src.closeInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return this.src.isItemValidForSlot( i, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.src.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return this.src.getField( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
this.src.setField( id, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return this.src.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.src.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return this.src.isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
|
||||
public interface IAEAppEngInventory
|
||||
{
|
||||
void saveChanges();
|
||||
|
||||
void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack );
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandlerModifiable;
|
||||
|
||||
|
||||
public interface IInternalItemHandler extends IItemHandlerModifiable
|
||||
{
|
||||
boolean isItemValidForSlot( int slot, ItemStack stack );
|
||||
|
||||
void markDirty( int slot );
|
||||
}
|
||||
@@ -49,6 +49,12 @@ public class IMEAdaptor extends InventoryAdaptor
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasSlots()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
|
||||
+2
-6
@@ -19,11 +19,7 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IInventoryWrapper
|
||||
public enum InvOperation
|
||||
{
|
||||
|
||||
boolean canRemoveItemFromSlot( int x, ItemStack is );
|
||||
EXTRACT, INSERT, SET, DIRTY
|
||||
}
|
||||
@@ -1,275 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
public class WrapperChainedInventory implements IInventory
|
||||
{
|
||||
|
||||
private int fullSize = 0;
|
||||
private List<IInventory> l;
|
||||
private Map<Integer, InvOffset> offsets;
|
||||
|
||||
public WrapperChainedInventory( final IInventory... inventories )
|
||||
{
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
private void setInventory( final IInventory... a )
|
||||
{
|
||||
this.l = ImmutableList.copyOf( a );
|
||||
this.calculateSizes();
|
||||
}
|
||||
|
||||
private void calculateSizes()
|
||||
{
|
||||
this.offsets = new HashMap<>();
|
||||
|
||||
int offset = 0;
|
||||
for( final IInventory in : this.l )
|
||||
{
|
||||
final InvOffset io = new InvOffset();
|
||||
io.offset = offset;
|
||||
io.size = in.getSizeInventory();
|
||||
io.i = in;
|
||||
|
||||
for( int y = 0; y < io.size; y++ )
|
||||
{
|
||||
this.offsets.put( y + io.offset, io );
|
||||
}
|
||||
|
||||
offset += io.size;
|
||||
}
|
||||
|
||||
this.fullSize = offset;
|
||||
}
|
||||
|
||||
public WrapperChainedInventory( final List<IInventory> inventories )
|
||||
{
|
||||
this.setInventory( inventories );
|
||||
}
|
||||
|
||||
private void setInventory( final List<IInventory> a )
|
||||
{
|
||||
this.l = a;
|
||||
this.calculateSizes();
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
{
|
||||
if( this.l.size() > 1 )
|
||||
{
|
||||
final List<IInventory> newOrder = new ArrayList<>( this.l.size() );
|
||||
newOrder.add( this.l.get( this.l.size() - 1 ) );
|
||||
for( int x = 0; x < this.l.size() - 1; x++ )
|
||||
{
|
||||
newOrder.add( this.l.get( x ) );
|
||||
}
|
||||
this.setInventory( newOrder );
|
||||
}
|
||||
}
|
||||
|
||||
public IInventory getInv( final int idx )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return io.i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getInvSlot( final int idx )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return idx - io.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.fullSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int idx )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.getStackInSlot( idx - io.offset );
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int idx, final int var2 )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.decrStackSize( idx - io.offset, var2 );
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int idx )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.removeStackFromSlot( idx - io.offset );
|
||||
}
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int idx, final ItemStack var2 )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
io.i.setInventorySlotContents( idx - io.offset, var2 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "ChainedInv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int smallest = 64;
|
||||
|
||||
for( final IInventory i : this.l )
|
||||
{
|
||||
smallest = Math.min( smallest, i.getInventoryStackLimit() );
|
||||
}
|
||||
|
||||
return smallest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
for( final IInventory i : this.l )
|
||||
{
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int idx, final ItemStack itemstack )
|
||||
{
|
||||
final InvOffset io = this.offsets.get( idx );
|
||||
if( io != null )
|
||||
{
|
||||
return io.i.isItemValidForSlot( idx - io.offset, itemstack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static class InvOffset
|
||||
{
|
||||
|
||||
private int offset;
|
||||
private int size;
|
||||
private IInventory i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperChainedItemHandler implements IInternalItemHandler
|
||||
{
|
||||
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 )
|
||||
{
|
||||
setItemHandlers( itemHandler );
|
||||
}
|
||||
|
||||
private void setItemHandlers( IItemHandler[] handlers )
|
||||
{
|
||||
this.itemHandler = handlers;
|
||||
this.baseIndex = new int[itemHandler.length];
|
||||
int index = 0;
|
||||
for( int i = 0; i < itemHandler.length; i++ )
|
||||
{
|
||||
index += itemHandler[i].getSlots();
|
||||
baseIndex[i] = index;
|
||||
}
|
||||
this.slotCount = index;
|
||||
}
|
||||
|
||||
// returns the handler index for the slot
|
||||
private int getIndexForSlot( int slot )
|
||||
{
|
||||
if( slot < 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
for( int i = 0; i < baseIndex.length; i++ )
|
||||
{
|
||||
if( slot - baseIndex[i] < 0 )
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
private IItemHandler getHandlerFromIndex( int index )
|
||||
{
|
||||
if( index < 0 || index >= itemHandler.length )
|
||||
{
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
return itemHandler[index];
|
||||
}
|
||||
|
||||
private int getSlotFromIndex( int slot, int index )
|
||||
{
|
||||
if( index <= 0 || index >= baseIndex.length )
|
||||
{
|
||||
return slot;
|
||||
}
|
||||
return slot - 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] ) );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return slotCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( final int slot )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
return handler.getStackInSlot( targetSlot );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( final int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
return handler.insertItem( targetSlot, stack, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
return handler.extractItem( targetSlot, amount, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int localSlot = getSlotFromIndex( slot, index );
|
||||
return handler.getSlotLimit( localSlot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
ItemHandlerUtil.setStackInSlot( handler, targetSlot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
return ItemHandlerUtil.isItemValidForSlot( handler, targetSlot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
int index = getIndexForSlot( slot );
|
||||
IItemHandler handler = getHandlerFromIndex( index );
|
||||
int targetSlot = getSlotFromIndex( slot, index );
|
||||
ItemHandlerUtil.markDirty( handler, targetSlot );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
|
||||
public class WrapperCursorItemHandler extends ItemStackHandler
|
||||
{
|
||||
private final InventoryPlayer inv;
|
||||
|
||||
public WrapperCursorItemHandler( InventoryPlayer inventoryPlayer )
|
||||
{
|
||||
super( 1 );
|
||||
|
||||
this.inv = inventoryPlayer;
|
||||
setStackInSlot( 0, inventoryPlayer.getItemStack() );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
this.inv.setItemStack( getStackInSlot( slot ) );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class WrapperFilteredItemHandler implements IInternalItemHandler
|
||||
{
|
||||
private final IItemHandler handler;
|
||||
private final IAEItemFilter 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( handler, slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return handler.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return handler.getStackInSlot( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( !filter.allowInsert( handler, slot, stack ) )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
return handler.insertItem( slot, stack, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( !filter.allowExtract( handler, slot, amount ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return handler.extractItem( slot, amount, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return handler.getSlotLimit( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
if( !filter.allowInsert( handler, slot, stack ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return ItemHandlerUtil.isItemValidForSlot( handler, slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( handler, slot );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperInvItemHandler implements IInventory
|
||||
{
|
||||
private final IItemHandler inv;
|
||||
|
||||
public WrapperInvItemHandler( final IItemHandler inv )
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return inv.getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return ItemHandlerUtil.isEmpty( inv );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int index )
|
||||
{
|
||||
return inv.getStackInSlot( index );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( int index, int count )
|
||||
{
|
||||
return inv.extractItem( index, count, false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( int index )
|
||||
{
|
||||
return inv.extractItem( index, inv.getSlotLimit( index ), false );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( int index, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( inv, index, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int max = 0;
|
||||
for( int i = 0; i < inv.getSlots(); ++i )
|
||||
{
|
||||
max = Math.max( max, inv.getSlotLimit( i ) );
|
||||
}
|
||||
return max;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
ItemHandlerUtil.markDirty( inv, -1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( EntityPlayer player )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( EntityPlayer player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( EntityPlayer player )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int index, ItemStack stack )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( inv, index, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( int id, int value )
|
||||
{
|
||||
// NOP
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
ItemHandlerUtil.clear( inv );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,175 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
public class WrapperInvSlot
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
|
||||
public WrapperInvSlot( final IInventory inv )
|
||||
{
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public IInventory getWrapper( final int slot )
|
||||
{
|
||||
return new InternalInterfaceWrapper( this.inv, slot );
|
||||
}
|
||||
|
||||
protected boolean isItemValid( final ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
private class InternalInterfaceWrapper implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
private final int slot;
|
||||
|
||||
public InternalInterfaceWrapper( final IInventory target, final int slot )
|
||||
{
|
||||
this.inv = target;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int i )
|
||||
{
|
||||
return this.inv.getStackInSlot( this.slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int i, final int num )
|
||||
{
|
||||
return this.inv.decrStackSize( this.slot, num );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int i )
|
||||
{
|
||||
return this.inv.removeStackFromSlot( this.slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int i, final ItemStack itemstack )
|
||||
{
|
||||
this.inv.setInventorySlotContents( this.slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
this.inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer entityplayer )
|
||||
{
|
||||
return this.inv.isUsableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.inv.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return this.inv.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
this.inv.openInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
this.inv.closeInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.inv.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return this.inv.getField( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return this.inv.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return WrapperInvSlot.this.isItemValid( itemstack ) && this.inv.isItemValidForSlot( this.slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return this.inv.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
this.inv.setField( id, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,216 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
public class WrapperInventoryRange implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory src;
|
||||
private boolean ignoreValidItems = false;
|
||||
private int[] slots;
|
||||
|
||||
public WrapperInventoryRange( final IInventory a, final int[] s, final boolean ignoreValid )
|
||||
{
|
||||
this.src = a;
|
||||
this.setSlots( s );
|
||||
|
||||
if( this.getSlots() == null )
|
||||
{
|
||||
this.setSlots( new int[0] );
|
||||
}
|
||||
|
||||
this.setIgnoreValidItems( ignoreValid );
|
||||
}
|
||||
|
||||
public WrapperInventoryRange( final IInventory a, final int min, final int size, final boolean ignoreValid )
|
||||
{
|
||||
this.src = a;
|
||||
this.setSlots( new int[size] );
|
||||
for( int x = 0; x < size; x++ )
|
||||
{
|
||||
this.getSlots()[x] = min + x;
|
||||
}
|
||||
this.setIgnoreValidItems( ignoreValid );
|
||||
}
|
||||
|
||||
public static String concatLines( final int[] s, final String separator )
|
||||
{
|
||||
if( s.length > 0 )
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
for( final int value : s )
|
||||
{
|
||||
if( sb.length() > 0 )
|
||||
{
|
||||
sb.append( separator );
|
||||
}
|
||||
sb.append( value );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.getSlots().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int var1 )
|
||||
{
|
||||
return this.src.getStackInSlot( this.getSlots()[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int var1, final int var2 )
|
||||
{
|
||||
return this.src.decrStackSize( this.getSlots()[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int var1 )
|
||||
{
|
||||
return this.src.removeStackFromSlot( this.getSlots()[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int var1, final ItemStack var2 )
|
||||
{
|
||||
this.src.setInventorySlotContents( this.getSlots()[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
this.src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
{
|
||||
return this.src.isUsableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.src.getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return this.src.hasCustomName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
this.src.openInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
this.src.closeInventory( player );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.src.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return this.src.getField( id );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return this.src.getFieldCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return this.src.getDisplayName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
this.src.setField( id, value );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
if( this.isIgnoreValidItems() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.src.isItemValidForSlot( this.getSlots()[i], itemstack );
|
||||
}
|
||||
|
||||
boolean isIgnoreValidItems()
|
||||
{
|
||||
return this.ignoreValidItems;
|
||||
}
|
||||
|
||||
private void setIgnoreValidItems( final boolean ignoreValidItems )
|
||||
{
|
||||
this.ignoreValidItems = ignoreValidItems;
|
||||
}
|
||||
|
||||
int[] getSlots()
|
||||
{
|
||||
return this.slots;
|
||||
}
|
||||
|
||||
private void setSlots( final int[] slots )
|
||||
{
|
||||
this.slots = slots;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.Lazy;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperLazyItemHandler implements IInternalItemHandler
|
||||
{
|
||||
private final Lazy<IItemHandler> sourceHandler;
|
||||
|
||||
public WrapperLazyItemHandler( Supplier<IItemHandler> source )
|
||||
{
|
||||
this.sourceHandler = new Lazy<>( source );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return sourceHandler.get().getSlots();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
return sourceHandler.get().getStackInSlot( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
return sourceHandler.get().insertItem( slot, stack, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
return sourceHandler.get().extractItem( slot, amount, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return sourceHandler.get().getSlotLimit( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, ItemStack stack )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( sourceHandler.get(), slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( sourceHandler.get(), slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( sourceHandler.get(), slot );
|
||||
}
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
|
||||
|
||||
public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventoryWrapper
|
||||
{
|
||||
|
||||
private final ISidedInventory side;
|
||||
private final EnumFacing dir;
|
||||
|
||||
public WrapperMCISidedInventory( final ISidedInventory a, final EnumFacing d )
|
||||
{
|
||||
super( a, a.getSlotsForFace( d ), false );
|
||||
this.side = a;
|
||||
this.dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int var1, final int var2 )
|
||||
{
|
||||
if( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) )
|
||||
{
|
||||
return super.decrStackSize( var1, var2 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
|
||||
if( this.isIgnoreValidItems() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if( this.side.isItemValidForSlot( this.getSlots()[i], itemstack ) )
|
||||
{
|
||||
return this.side.canInsertItem( this.getSlots()[i], itemstack, this.dir );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveItemFromSlot( final int i, final ItemStack is )
|
||||
{
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return this.side.canExtractItem( this.getSlots()[i], is, this.dir );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.util.inv;
|
||||
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
|
||||
|
||||
public class WrapperRangeItemHandler implements IInternalItemHandler
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlots()
|
||||
{
|
||||
return maxSlot - minSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack getStackInSlot( int slot )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
return compose.getStackInSlot( slot + minSlot );
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
return compose.insertItem( slot + minSlot, stack, simulate );
|
||||
}
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
return compose.extractItem( slot + minSlot, amount, simulate );
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
ItemHandlerUtil.setStackInSlot( compose, slot + minSlot, stack );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
return compose.getSlotLimit( slot + minSlot );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
private boolean checkSlot( int localSlot )
|
||||
{
|
||||
return localSlot + minSlot < maxSlot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
return ItemHandlerUtil.isItemValidForSlot( compose, slot + minSlot, stack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
if( checkSlot( slot ) )
|
||||
{
|
||||
ItemHandlerUtil.markDirty( compose, slot + minSlot );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 AEItemDefinitionFilter( IItemDefinition definition )
|
||||
{
|
||||
this.definition = definition;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return definition.isSameAs( stack );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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();
|
||||
|
||||
private AEItemFilters()
|
||||
{
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
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 );
|
||||
|
||||
boolean allowInsert( IItemHandler inv, int slot, ItemStack stack );
|
||||
}
|
||||
Reference in New Issue
Block a user