Basic reformat, hit once, hope never again

This commit is contained in:
thatsIch
2015-04-03 08:54:31 +02:00
parent 4ff1631f89
commit d34c988c88
886 changed files with 31400 additions and 30990 deletions
@@ -18,6 +18,7 @@
package appeng.util.inv;
import java.util.Iterator;
import net.minecraft.item.ItemStack;
@@ -31,6 +32,7 @@ import appeng.integration.abstraction.IBC;
import appeng.util.InventoryAdaptor;
import appeng.util.iterators.NullIterator;
public class AdaptorBCPipe extends InventoryAdaptor
{
@@ -38,11 +40,12 @@ public class AdaptorBCPipe extends InventoryAdaptor
final private TileEntity i;
final private ForgeDirection d;
public AdaptorBCPipe(TileEntity s, ForgeDirection dd) {
public AdaptorBCPipe( TileEntity s, ForgeDirection dd )
{
this.bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
if ( this.bc != null )
if( this.bc != null )
{
if ( this.bc.isPipe( s, dd ) )
if( this.bc.isPipe( s, dd ) )
{
this.i = s;
this.d = dd;
@@ -54,48 +57,48 @@ public class AdaptorBCPipe extends InventoryAdaptor
}
@Override
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
return null;
}
@Override
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
{
return null;
}
@Override
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
return null;
}
@Override
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
return null;
}
@Override
public ItemStack addItems(ItemStack toBeAdded )
public ItemStack addItems( ItemStack toBeAdded )
{
if ( this.i == null )
if( this.i == null )
return toBeAdded;
if ( toBeAdded == null )
if( toBeAdded == null )
return null;
if ( toBeAdded.stackSize == 0 )
if( toBeAdded.stackSize == 0 )
return null;
if ( this.bc.addItemsToPipe( this.i, toBeAdded, this.d ) )
if( this.bc.addItemsToPipe( this.i, toBeAdded, this.d ) )
return null;
return toBeAdded;
}
@Override
public ItemStack simulateAdd(ItemStack toBeSimulated )
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
if ( this.i == null )
if( this.i == null )
return toBeSimulated;
return null;
}
@@ -111,5 +114,4 @@ public class AdaptorBCPipe extends InventoryAdaptor
{
return new NullIterator<ItemSlot>();
}
}
@@ -41,117 +41,26 @@ public class AdaptorIInventory extends InventoryAdaptor
this.wrapperEnabled = s instanceof IInventoryWrapper;
}
boolean canRemoveStackFromSlot( int x, ItemStack is )
{
if ( this.wrapperEnabled )
return ( ( IInventoryWrapper ) this.i ).canRemoveItemFromSlot( x, is );
return true;
}
@Override
public boolean containsItems()
{
int s = this.i.getSizeInventory();
for ( int x = 0; x < s; x++ )
{
if ( this.i.getStackInSlot( x ) != null )
return true;
}
return false;
}
@Override
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int s = this.i.getSizeInventory();
for ( int x = 0; x < s; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
int newAmount = amount;
if ( newAmount > is.stackSize )
newAmount = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
newAmount = 0;
ItemStack rv = null;
if ( newAmount > 0 )
{
rv = is.copy();
rv.stackSize = newAmount;
if ( is.stackSize == rv.stackSize )
{
this.i.setInventorySlotContents( x, null );
this.i.markDirty();
}
else
{
ItemStack po = is.copy();
po.stackSize -= rv.stackSize;
this.i.setInventorySlotContents( x, po );
this.i.markDirty();
}
}
if ( rv != null )
{
// i.markDirty();
return rv;
}
}
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int s = this.i.getSizeInventory();
for ( int x = 0; x < s; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
int boundAmount = amount;
if ( boundAmount > is.stackSize )
boundAmount = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
boundAmount = 0;
if ( boundAmount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = boundAmount;
return rv;
}
}
}
return null;
}
@Override
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
int s = this.i.getSizeInventory();
ItemStack rv = null;
for ( int x = 0; x < s && amount > 0; x++ )
for( int x = 0; x < s && amount > 0; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
{
int boundAmounts = amount;
if ( boundAmounts > is.stackSize )
if( boundAmounts > is.stackSize )
boundAmounts = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
if( destination != null && !destination.canInsert( is ) )
boundAmounts = 0;
if ( boundAmounts > 0 )
if( boundAmounts > 0 )
{
if ( rv == null )
if( rv == null )
{
rv = is.copy();
filter = rv;
@@ -164,7 +73,7 @@ public class AdaptorIInventory extends InventoryAdaptor
amount -= boundAmounts;
}
if ( is.stackSize == boundAmounts )
if( is.stackSize == boundAmounts )
{
this.i.setInventorySlotContents( x, null );
this.i.markDirty();
@@ -192,20 +101,20 @@ public class AdaptorIInventory extends InventoryAdaptor
int s = this.i.getSizeInventory();
ItemStack rv = null;
for ( int x = 0; x < s && amount > 0; x++ )
for( int x = 0; x < s && amount > 0; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if ( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
{
int boundAmount = amount;
if ( boundAmount > is.stackSize )
if( boundAmount > is.stackSize )
boundAmount = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
if( destination != null && !destination.canInsert( is ) )
boundAmount = 0;
if ( boundAmount > 0 )
if( boundAmount > 0 )
{
if ( rv == null )
if( rv == null )
{
rv = is.copy();
rv.stackSize = boundAmount;
@@ -223,6 +132,78 @@ public class AdaptorIInventory extends InventoryAdaptor
return rv;
}
@Override
public ItemStack removeSimilarItems( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int s = this.i.getSizeInventory();
for( int x = 0; x < s; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
int newAmount = amount;
if( newAmount > is.stackSize )
newAmount = is.stackSize;
if( destination != null && !destination.canInsert( is ) )
newAmount = 0;
ItemStack rv = null;
if( newAmount > 0 )
{
rv = is.copy();
rv.stackSize = newAmount;
if( is.stackSize == rv.stackSize )
{
this.i.setInventorySlotContents( x, null );
this.i.markDirty();
}
else
{
ItemStack po = is.copy();
po.stackSize -= rv.stackSize;
this.i.setInventorySlotContents( x, po );
this.i.markDirty();
}
}
if( rv != null )
{
// i.markDirty();
return rv;
}
}
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
int s = this.i.getSizeInventory();
for( int x = 0; x < s; x++ )
{
ItemStack is = this.i.getStackInSlot( x );
if( is != null && this.canRemoveStackFromSlot( x, is ) && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
int boundAmount = amount;
if( boundAmount > is.stackSize )
boundAmount = is.stackSize;
if( destination != null && !destination.canInsert( is ) )
boundAmount = 0;
if( boundAmount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = boundAmount;
return rv;
}
}
}
return null;
}
@Override
public ItemStack addItems( ItemStack toBeAdded )
{
@@ -235,6 +216,18 @@ public class AdaptorIInventory extends InventoryAdaptor
return this.addItems( toBeSimulated, false );
}
@Override
public boolean containsItems()
{
int s = this.i.getSizeInventory();
for( int x = 0; x < s; x++ )
{
if( this.i.getStackInSlot( x ) != null )
return true;
}
return false;
}
/**
* Adds an {@link ItemStack} to the adapted {@link IInventory}.
*
@@ -243,13 +236,13 @@ public class AdaptorIInventory extends InventoryAdaptor
* than the limit.
*
* @param itemsToAdd itemStack to add to the inventory
* @param modulate true to modulate, false for simulate
* @param modulate true to modulate, false for simulate
*
* @return the left itemstack, which could not be added
*/
private ItemStack addItems( ItemStack itemsToAdd, boolean modulate )
{
if ( itemsToAdd == null || itemsToAdd.stackSize == 0 )
if( itemsToAdd == null || itemsToAdd.stackSize == 0 )
{
return null;
}
@@ -259,35 +252,35 @@ public class AdaptorIInventory extends InventoryAdaptor
int perOperationLimit = Math.min( this.i.getInventoryStackLimit(), stackLimit );
int inventorySize = this.i.getSizeInventory();
for ( int slot = 0; slot < inventorySize; slot++ )
for( int slot = 0; slot < inventorySize; slot++ )
{
ItemStack next = left.copy();
next.stackSize = Math.min( perOperationLimit, next.stackSize );
if ( this.i.isItemValidForSlot( slot, next ) )
if( this.i.isItemValidForSlot( slot, next ) )
{
ItemStack is = this.i.getStackInSlot( slot );
if ( is == null )
if( is == null )
{
left.stackSize -= next.stackSize;
if ( modulate )
if( modulate )
{
this.i.setInventorySlotContents( slot, next );
this.i.markDirty();
}
if ( left.stackSize <= 0 )
if( left.stackSize <= 0 )
{
return null;
}
}
else if ( Platform.isSameItemPrecise( is, left ) && is.stackSize < perOperationLimit )
else if( Platform.isSameItemPrecise( is, left ) && is.stackSize < perOperationLimit )
{
int room = perOperationLimit - is.stackSize;
int used = Math.min( left.stackSize, room );
if ( modulate )
if( modulate )
{
is.stackSize += used;
this.i.setInventorySlotContents( slot, is );
@@ -295,7 +288,7 @@ public class AdaptorIInventory extends InventoryAdaptor
}
left.stackSize -= used;
if ( left.stackSize <= 0 )
if( left.stackSize <= 0 )
{
return null;
}
@@ -306,6 +299,19 @@ public class AdaptorIInventory extends InventoryAdaptor
return left;
}
boolean canRemoveStackFromSlot( int x, ItemStack is )
{
if( this.wrapperEnabled )
return ( (IInventoryWrapper) this.i ).canRemoveItemFromSlot( x, is );
return true;
}
@Override
public Iterator<ItemSlot> iterator()
{
return new InvIterator();
}
class InvIterator implements Iterator<ItemSlot>
{
@@ -336,13 +342,5 @@ public class AdaptorIInventory extends InventoryAdaptor
{
// nothing!
}
}
@Override
public Iterator<ItemSlot> iterator()
{
return new InvIterator();
}
}
+83 -83
View File
@@ -18,6 +18,7 @@
package appeng.util.inv;
import java.util.Iterator;
import java.util.List;
@@ -28,96 +29,39 @@ import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.iterators.StackToSlotIterator;
public class AdaptorList extends InventoryAdaptor
{
private final List<ItemStack> i;
public AdaptorList(List<ItemStack> s) {
public AdaptorList( List<ItemStack> s )
{
this.i = s;
}
@Override
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
int s = this.i.size();
for (int x = 0; x < s; x++)
for( int x = 0; x < s; x++ )
{
ItemStack is = this.i.get( x );
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
{
if ( how_many > is.stackSize )
how_many = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
how_many = 0;
if ( how_many > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = how_many;
is.stackSize -= how_many;
// remove it..
if ( is.stackSize <= 0 )
this.i.remove( x );
return rv;
}
}
}
return null;
}
@Override
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
{
for (ItemStack is : this.i)
{
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
{
if ( amount > is.stackSize )
{
if( amount > is.stackSize )
amount = is.stackSize;
}
if ( destination != null && !destination.canInsert( is ) )
{
amount = 0;
}
if ( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = amount;
return rv;
}
}
}
return null;
}
@Override
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
{
int s = this.i.size();
for (int x = 0; x < s; x++)
{
ItemStack is = this.i.get( x );
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
{
if ( amount > is.stackSize )
amount = is.stackSize;
if ( destination != null && !destination.canInsert( is ) )
if( destination != null && !destination.canInsert( is ) )
amount = 0;
if ( amount > 0 )
if( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = amount;
is.stackSize -= amount;
// remove it..
if ( is.stackSize <= 0 )
if( is.stackSize <= 0 )
this.i.remove( x );
return rv;
@@ -128,22 +72,22 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
{
for (ItemStack is : this.i)
for( ItemStack is : this.i )
{
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
if( is != null && ( filter == null || Platform.isSameItemPrecise( is, filter ) ) )
{
if ( amount > is.stackSize )
if( amount > is.stackSize )
{
amount = is.stackSize;
}
if ( destination != null && !destination.canInsert( is ) )
if( destination != null && !destination.canInsert( is ) )
{
amount = 0;
}
if ( amount > 0 )
if( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = amount;
@@ -152,22 +96,79 @@ public class AdaptorList extends InventoryAdaptor
}
}
return null;
}
@Override
public ItemStack addItems(ItemStack toBeAdded )
public ItemStack removeSimilarItems( int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
if ( toBeAdded == null )
int s = this.i.size();
for( int x = 0; x < s; x++ )
{
ItemStack is = this.i.get( x );
if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
if( how_many > is.stackSize )
how_many = is.stackSize;
if( destination != null && !destination.canInsert( is ) )
how_many = 0;
if( how_many > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = how_many;
is.stackSize -= how_many;
// remove it..
if( is.stackSize <= 0 )
this.i.remove( x );
return rv;
}
}
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
for( ItemStack is : this.i )
{
if( is != null && ( filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode ) ) )
{
if( amount > is.stackSize )
{
amount = is.stackSize;
}
if( destination != null && !destination.canInsert( is ) )
{
amount = 0;
}
if( amount > 0 )
{
ItemStack rv = is.copy();
rv.stackSize = amount;
return rv;
}
}
}
return null;
}
@Override
public ItemStack addItems( ItemStack toBeAdded )
{
if( toBeAdded == null )
return null;
if ( toBeAdded.stackSize == 0 )
if( toBeAdded.stackSize == 0 )
return null;
ItemStack left = toBeAdded.copy();
for (ItemStack is : this.i)
for( ItemStack is : this.i )
{
if ( Platform.isSameItem( is, left ) )
if( Platform.isSameItem( is, left ) )
{
is.stackSize += left.stackSize;
return null;
@@ -179,7 +180,7 @@ public class AdaptorList extends InventoryAdaptor
}
@Override
public ItemStack simulateAdd(ItemStack toBeSimulated )
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
return null;
}
@@ -187,9 +188,9 @@ public class AdaptorList extends InventoryAdaptor
@Override
public boolean containsItems()
{
for (ItemStack is : this.i)
for( ItemStack is : this.i )
{
if ( is != null )
if( is != null )
{
return true;
}
@@ -202,5 +203,4 @@ public class AdaptorList extends InventoryAdaptor
{
return new StackToSlotIterator( this.i.iterator() );
}
}
@@ -1,4 +1,3 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
@@ -44,57 +43,19 @@ public class AdaptorPlayerHand extends InventoryAdaptor
this.p = _p;
}
@Override
public ItemStack removeSimilarItems( int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
return null;
if ( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
hand.stackSize -= how_many;
if ( hand.stackSize <= 0 )
this.p.inventory.setItemStack( null );
return result;
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
return null;
if ( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
return result;
}
return null;
}
@Override
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
if( hand == null )
return null;
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
if( filter == null || Platform.isSameItemPrecise( filter, hand ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
hand.stackSize -= amount;
if ( hand.stackSize <= 0 )
if( hand.stackSize <= 0 )
this.p.inventory.setItemStack( null );
return result;
}
@@ -107,10 +68,48 @@ public class AdaptorPlayerHand extends InventoryAdaptor
{
ItemStack hand = this.p.inventory.getItemStack();
if ( hand == null )
if( hand == null )
return null;
if ( filter == null || Platform.isSameItemPrecise( filter, hand ) )
if( filter == null || Platform.isSameItemPrecise( filter, hand ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
return result;
}
return null;
}
@Override
public ItemStack removeSimilarItems( int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if( hand == null )
return null;
if( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
hand.stackSize -= how_many;
if( hand.stackSize <= 0 )
this.p.inventory.setItemStack( null );
return result;
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
ItemStack hand = this.p.inventory.getItemStack();
if( hand == null )
return null;
if( Filter == null || Platform.isSameItemFuzzy( Filter, hand, fuzzyMode ) )
{
ItemStack result = hand.copy();
result.stackSize = hand.stackSize > amount ? amount : hand.stackSize;
@@ -124,23 +123,23 @@ public class AdaptorPlayerHand extends InventoryAdaptor
public ItemStack addItems( ItemStack toBeAdded )
{
if ( toBeAdded == null )
if( toBeAdded == null )
return null;
if ( toBeAdded.stackSize == 0 )
if( toBeAdded.stackSize == 0 )
return null;
if ( this.p == null )
if( this.p == null )
return toBeAdded;
if ( this.p.inventory == null )
if( this.p.inventory == null )
return toBeAdded;
ItemStack hand = this.p.inventory.getItemStack();
if ( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) )
if( hand != null && !Platform.isSameItemPrecise( toBeAdded, hand ) )
return toBeAdded;
int original = 0;
ItemStack newHand = null;
if ( hand == null )
if( hand == null )
newHand = toBeAdded.copy();
else
{
@@ -149,7 +148,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
newHand.stackSize += toBeAdded.stackSize;
}
if ( newHand.stackSize > newHand.getMaxStackSize() )
if( newHand.stackSize > newHand.getMaxStackSize() )
{
newHand.stackSize = newHand.getMaxStackSize();
ItemStack B = toBeAdded.copy();
@@ -166,15 +165,15 @@ public class AdaptorPlayerHand extends InventoryAdaptor
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
ItemStack hand = this.p.inventory.getItemStack();
if ( toBeSimulated == null )
if( toBeSimulated == null )
return null;
if ( hand != null && !Platform.isSameItem( toBeSimulated, hand ) )
if( hand != null && !Platform.isSameItem( toBeSimulated, hand ) )
return toBeSimulated;
int original = 0;
ItemStack newHand = null;
if ( hand == null )
if( hand == null )
newHand = toBeSimulated.copy();
else
{
@@ -183,7 +182,7 @@ public class AdaptorPlayerHand extends InventoryAdaptor
newHand.stackSize += toBeSimulated.stackSize;
}
if ( newHand.stackSize > newHand.getMaxStackSize() )
if( newHand.stackSize > newHand.getMaxStackSize() )
{
newHand.stackSize = newHand.getMaxStackSize();
ItemStack B = toBeSimulated.copy();
@@ -18,25 +18,26 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class AdaptorPlayerInventory implements IInventory
{
private final IInventory src;
private final int min=0;
private final int size=36;
private final int min = 0;
private final int size = 36;
public AdaptorPlayerInventory(IInventory playerInv, boolean swap)
public AdaptorPlayerInventory( IInventory playerInv, boolean swap )
{
if ( swap )
this.src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, this.size -9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
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
@@ -46,25 +47,25 @@ public class AdaptorPlayerInventory implements IInventory
}
@Override
public ItemStack getStackInSlot(int var1)
public ItemStack getStackInSlot( int var1 )
{
return this.src.getStackInSlot( var1 + this.min );
}
@Override
public ItemStack decrStackSize(int var1, int var2)
public ItemStack decrStackSize( int var1, int var2 )
{
return this.src.decrStackSize( this.min + var1, var2 );
}
@Override
public ItemStack getStackInSlotOnClosing(int var1)
public ItemStack getStackInSlotOnClosing( int var1 )
{
return this.src.getStackInSlotOnClosing( this.min + var1 );
}
@Override
public void setInventorySlotContents(int var1, ItemStack var2)
public void setInventorySlotContents( int var1, ItemStack var2 )
{
this.src.setInventorySlotContents( var1 + this.min, var2 );
}
@@ -75,6 +76,12 @@ public class AdaptorPlayerInventory implements IInventory
return this.src.getInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
@@ -88,7 +95,7 @@ public class AdaptorPlayerInventory implements IInventory
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1)
public boolean isUseableByPlayer( EntityPlayer var1 )
{
return this.src.isUseableByPlayer( var1 );
}
@@ -106,15 +113,8 @@ public class AdaptorPlayerInventory implements IInventory
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
return this.src.isItemValidForSlot( i, itemstack );
}
}
@@ -18,11 +18,12 @@
package appeng.util.inv;
import net.minecraft.item.ItemStack;
public interface IInventoryDestination
{
boolean canInsert( ItemStack stack );
}
@@ -18,11 +18,12 @@
package appeng.util.inv;
import net.minecraft.item.ItemStack;
public interface IInventoryWrapper
{
boolean canRemoveItemFromSlot(int x, ItemStack is);
boolean canRemoveItemFromSlot( int x, ItemStack is );
}
+53 -51
View File
@@ -18,12 +18,13 @@
package appeng.util.inv;
import java.util.Iterator;
import com.google.common.collect.ImmutableList;
import net.minecraft.item.ItemStack;
import com.google.common.collect.ImmutableList;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
import appeng.api.config.FuzzyMode;
@@ -34,6 +35,7 @@ import appeng.api.storage.data.IItemList;
import appeng.util.InventoryAdaptor;
import appeng.util.item.AEItemStack;
public class IMEAdaptor extends InventoryAdaptor
{
@@ -41,52 +43,37 @@ public class IMEAdaptor extends InventoryAdaptor
final BaseActionSource src;
int maxSlots = 0;
public IMEAdaptor(IMEInventory<IAEItemStack> input, BaseActionSource src) {
public IMEAdaptor( IMEInventory<IAEItemStack> input, BaseActionSource src )
{
this.target = input;
this.src = src;
}
IItemList<IAEItemStack> getList()
{
return this.target.getAvailableItems( AEApi.instance().storage().createItemList() );
}
@Override
public Iterator<ItemSlot> iterator()
{
return new IMEAdaptorIterator( this, this.getList() );
}
public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode)
IItemList<IAEItemStack> getList()
{
IAEItemStack reqFilter = AEItemStack.create( Filter );
if ( reqFilter == null )
return null;
IAEItemStack out = null;
for (IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ))
{
if ( req != null )
{
req.setStackSize( how_many );
out = this.target.extractItems( req, type, this.src );
if ( out != null )
return out.getItemStack();
}
}
return null;
return this.target.getAvailableItems( AEApi.instance().storage().createItemList() );
}
public ItemStack doRemoveItems(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type)
@Override
public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination )
{
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
}
public ItemStack doRemoveItems( int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type )
{
IAEItemStack req = null;
if ( Filter == null )
if( Filter == null )
{
IItemList<IAEItemStack> list = this.getList();
if ( !list.isEmpty() )
if( !list.isEmpty() )
req = list.getFirstItem();
}
else
@@ -94,67 +81,83 @@ public class IMEAdaptor extends InventoryAdaptor
IAEItemStack out = null;
if ( req != null )
if( req != null )
{
req.setStackSize( how_many );
out = this.target.extractItems( req, type, this.src );
}
if ( out != null )
if( out != null )
return out.getItemStack();
return null;
}
@Override
public ItemStack removeItems(int amount, ItemStack filter, IInventoryDestination destination)
{
return this.doRemoveItems( amount, filter, destination, Actionable.MODULATE );
}
@Override
public ItemStack simulateRemove(int amount, ItemStack filter, IInventoryDestination destination)
public ItemStack simulateRemove( int amount, ItemStack filter, IInventoryDestination destination )
{
return this.doRemoveItems( amount, filter, destination, Actionable.SIMULATE );
}
@Override
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack removeSimilarItems( int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
if ( filter == null )
if( filter == null )
return this.doRemoveItems( how_many, null, destination, Actionable.MODULATE );
return this.doRemoveItemsFuzzy( how_many, filter, destination, Actionable.MODULATE, fuzzyMode );
}
@Override
public ItemStack simulateSimilarRemove(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
public ItemStack doRemoveItemsFuzzy( int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode )
{
if ( filter == null )
IAEItemStack reqFilter = AEItemStack.create( Filter );
if( reqFilter == null )
return null;
IAEItemStack out = null;
for( IAEItemStack req : ImmutableList.copyOf( this.getList().findFuzzy( reqFilter, fuzzyMode ) ) )
{
if( req != null )
{
req.setStackSize( how_many );
out = this.target.extractItems( req, type, this.src );
if( out != null )
return out.getItemStack();
}
}
return null;
}
@Override
public ItemStack simulateSimilarRemove( int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination )
{
if( filter == null )
return this.doRemoveItems( amount, null, destination, Actionable.SIMULATE );
return this.doRemoveItemsFuzzy( amount, filter, destination, Actionable.SIMULATE, fuzzyMode );
}
@Override
public ItemStack addItems(ItemStack toBeAdded )
public ItemStack addItems( ItemStack toBeAdded )
{
IAEItemStack in = AEItemStack.create( toBeAdded );
if ( in != null )
if( in != null )
{
IAEItemStack out = this.target.injectItems( in, Actionable.MODULATE, this.src );
if ( out != null )
if( out != null )
return out.getItemStack();
}
return null;
}
@Override
public ItemStack simulateAdd(ItemStack toBeSimulated )
public ItemStack simulateAdd( ItemStack toBeSimulated )
{
IAEItemStack in = AEItemStack.create( toBeSimulated );
if ( in != null )
if( in != null )
{
IAEItemStack out = this.target.injectItems( in, Actionable.SIMULATE, this.src );
if ( out != null )
if( out != null )
return out.getItemStack();
}
return null;
@@ -165,5 +168,4 @@ public class IMEAdaptor extends InventoryAdaptor
{
return !this.getList().isEmpty();
}
}
@@ -18,23 +18,25 @@
package appeng.util.inv;
import java.util.Iterator;
import appeng.api.storage.data.IAEItemStack;
import appeng.api.storage.data.IItemList;
public class IMEAdaptorIterator implements Iterator<ItemSlot>
{
final Iterator<IAEItemStack> stack;
final ItemSlot slot = new ItemSlot();
final IMEAdaptor parent;
final int containerSize;
int offset = 0;
boolean hasNext;
final IMEAdaptor parent;
final int containerSize;
public IMEAdaptorIterator(IMEAdaptor parent, IItemList<IAEItemStack> availableItems) {
public IMEAdaptorIterator( IMEAdaptor parent, IItemList<IAEItemStack> availableItems )
{
this.stack = availableItems.iterator();
this.containerSize = parent.maxSlots;
this.parent = parent;
@@ -52,12 +54,12 @@ public class IMEAdaptorIterator implements Iterator<ItemSlot>
{
this.slot.slot = this.offset;
this.offset++;
this.slot.isExtractable=true;
this.slot.isExtractable = true;
if ( this.parent.maxSlots < this.offset )
if( this.parent.maxSlots < this.offset )
this.parent.maxSlots = this.offset;
if ( this.hasNext )
if( this.hasNext )
{
IAEItemStack item = this.stack.next();
this.slot.setAEItemStack( item );
@@ -18,6 +18,7 @@
package appeng.util.inv;
import net.minecraft.item.ItemStack;
import appeng.api.config.Actionable;
@@ -25,27 +26,28 @@ import appeng.api.storage.IMEInventory;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
public class IMEInventoryDestination implements IInventoryDestination
{
final IMEInventory<IAEItemStack> me;
public IMEInventoryDestination(IMEInventory<IAEItemStack> o) {
public IMEInventoryDestination( IMEInventory<IAEItemStack> o )
{
this.me = o;
}
@Override
public boolean canInsert(ItemStack stack)
public boolean canInsert( ItemStack stack )
{
if ( stack == null )
if( stack == null )
return false;
IAEItemStack failed = this.me.injectItems( AEItemStack.create( stack ), Actionable.SIMULATE, null );
if ( failed == null )
if( failed == null )
return true;
return failed.getStackSize() != stack.stackSize;
}
}
@@ -18,6 +18,7 @@
package appeng.util.inv;
import java.util.Collection;
import java.util.Iterator;
@@ -25,19 +26,21 @@ import appeng.api.config.FuzzyMode;
import appeng.api.storage.data.IAEStack;
import appeng.api.storage.data.IItemList;
public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
{
final IItemList<T> target;
public ItemListIgnoreCrafting(IItemList<T> cla) {
public ItemListIgnoreCrafting( IItemList<T> cla )
{
this.target = cla;
}
@Override
public void add(T option)
public void add( T option )
{
if ( option != null && option.isCraftable() )
if( option != null && option.isCraftable() )
{
option = (T) option.copy();
option.setCraftable( false );
@@ -47,19 +50,13 @@ public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
}
@Override
public void addCrafting(T option)
{
// nothing.
}
@Override
public T findPrecise(T i)
public T findPrecise( T i )
{
return this.target.findPrecise( i );
}
@Override
public Collection<T> findFuzzy(T input, FuzzyMode fuzzy)
public Collection<T> findFuzzy( T input, FuzzyMode fuzzy )
{
return this.target.findFuzzy( input, fuzzy );
}
@@ -71,13 +68,19 @@ public class ItemListIgnoreCrafting<T extends IAEStack> implements IItemList<T>
}
@Override
public void addStorage(T option)
public void addStorage( T option )
{
this.target.addStorage( option );
}
@Override
public void addRequestable(T option)
public void addCrafting( T option )
{
// nothing.
}
@Override
public void addRequestable( T option )
{
this.target.addRequestable( option );
}
+14 -15
View File
@@ -18,42 +18,41 @@
package appeng.util.inv;
import net.minecraft.item.ItemStack;
import appeng.api.storage.data.IAEItemStack;
import appeng.util.item.AEItemStack;
public class ItemSlot
{
public int slot;
public boolean isExtractable;
// one or the other..
private IAEItemStack aeItemStack;
private ItemStack itemStack;
public boolean isExtractable;
public ItemStack getItemStack()
{
return this.itemStack == null ? ( this.aeItemStack == null ? null : ( this.itemStack = this.aeItemStack.getItemStack() ) ) : this.itemStack;
}
public void setItemStack(ItemStack is)
public void setItemStack( ItemStack is )
{
this.aeItemStack = null;
this.itemStack = is;
}
public void setAEItemStack(IAEItemStack is)
public IAEItemStack getAEItemStack()
{
return this.aeItemStack == null ? ( this.itemStack == null ? null : ( this.aeItemStack = AEItemStack.create( this.itemStack ) ) ) : this.aeItemStack;
}
public void setAEItemStack( IAEItemStack is )
{
this.aeItemStack = is;
this.itemStack = null;
}
public ItemStack getItemStack()
{
return this.itemStack == null ? (this.aeItemStack == null ? null : (this.itemStack = this.aeItemStack.getItemStack())) : this.itemStack;
}
public IAEItemStack getAEItemStack()
{
return this.aeItemStack == null ? (this.itemStack == null ? null : (this.aeItemStack = AEItemStack.create( this.itemStack ))) : this.aeItemStack;
}
}
@@ -18,6 +18,7 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
@@ -28,6 +29,7 @@ import appeng.core.AppEng;
import appeng.integration.IntegrationType;
import appeng.integration.abstraction.IBC;
public class WrapperBCPipe implements IInventory
{
@@ -35,7 +37,8 @@ public class WrapperBCPipe implements IInventory
final private TileEntity ad;
final private ForgeDirection dir;
public WrapperBCPipe(TileEntity te, ForgeDirection d) {
public WrapperBCPipe( TileEntity te, ForgeDirection d )
{
this.bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
this.ad = te;
this.dir = d;
@@ -48,25 +51,25 @@ public class WrapperBCPipe implements IInventory
}
@Override
public ItemStack getStackInSlot(int i)
public ItemStack getStackInSlot( int i )
{
return null;
}
@Override
public ItemStack decrStackSize(int i, int j)
public ItemStack decrStackSize( int i, int j )
{
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
public ItemStack getStackInSlotOnClosing( int i )
{
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
public void setInventorySlotContents( int i, ItemStack itemstack )
{
this.bc.addItemsToPipe( this.ad, itemstack, this.dir );
}
@@ -83,18 +86,6 @@ public class WrapperBCPipe implements IInventory
return false;
}
@Override
public void closeInventory()
{
}
@Override
public void openInventory()
{
}
@Override
public int getInventoryStackLimit()
{
@@ -108,15 +99,26 @@ public class WrapperBCPipe implements IInventory
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
public boolean isUseableByPlayer( EntityPlayer entityplayer )
{
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public void openInventory()
{
}
@Override
public void closeInventory()
{
}
@Override
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
return this.bc.canAddItemsToPipe( this.ad, itemstack, this.dir );
}
}
@@ -18,50 +18,34 @@
package appeng.util.inv;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import com.google.common.collect.ImmutableList;
public class WrapperChainedInventory implements IInventory
{
static class InvOffset
{
int offset;
int size;
IInventory i;
}
int fullSize = 0;
private List<IInventory> l;
private HashMap<Integer, InvOffset> offsets;
public WrapperChainedInventory(IInventory... inventories) {
this.setInventory( inventories );
}
public WrapperChainedInventory(List<IInventory> inventories) {
this.setInventory( inventories );
}
public void cycleOrder()
public WrapperChainedInventory( IInventory... inventories )
{
if ( this.l.size() > 1 )
{
List<IInventory> newOrder = new ArrayList<IInventory>( 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 );
}
this.setInventory( inventories );
}
public void setInventory( IInventory... a )
{
this.l = ImmutableList.copyOf( a );
this.calculateSizes();
}
public void calculateSizes()
@@ -69,14 +53,14 @@ public class WrapperChainedInventory implements IInventory
this.offsets = new HashMap<Integer, WrapperChainedInventory.InvOffset>();
int offset = 0;
for (IInventory in : this.l)
for( IInventory in : this.l )
{
InvOffset io = new InvOffset();
io.offset = offset;
io.size = in.getSizeInventory();
io.i = in;
for (int y = 0; y < io.size; y++)
for( int y = 0; y < io.size; y++ )
{
this.offsets.put( y + io.offset, io );
}
@@ -87,32 +71,43 @@ public class WrapperChainedInventory implements IInventory
this.fullSize = offset;
}
public void setInventory(IInventory... a)
public WrapperChainedInventory( List<IInventory> inventories )
{
this.l = ImmutableList.copyOf( a );
this.calculateSizes();
this.setInventory( inventories );
}
public void setInventory(List<IInventory> a)
public void setInventory( List<IInventory> a )
{
this.l = a;
this.calculateSizes();
}
public IInventory getInv(int idx)
public void cycleOrder()
{
if( this.l.size() > 1 )
{
List<IInventory> newOrder = new ArrayList<IInventory>( 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( int idx )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return io.i;
}
return null;
}
public int getInvSlot(int idx)
public int getInvSlot( int idx )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return idx - io.offset;
}
@@ -126,10 +121,10 @@ public class WrapperChainedInventory implements IInventory
}
@Override
public ItemStack getStackInSlot(int idx)
public ItemStack getStackInSlot( int idx )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return io.i.getStackInSlot( idx - io.offset );
}
@@ -137,10 +132,10 @@ public class WrapperChainedInventory implements IInventory
}
@Override
public ItemStack decrStackSize(int idx, int var2)
public ItemStack decrStackSize( int idx, int var2 )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return io.i.decrStackSize( idx - io.offset, var2 );
}
@@ -148,10 +143,10 @@ public class WrapperChainedInventory implements IInventory
}
@Override
public ItemStack getStackInSlotOnClosing(int idx)
public ItemStack getStackInSlotOnClosing( int idx )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return io.i.getStackInSlotOnClosing( idx - io.offset );
}
@@ -159,10 +154,10 @@ public class WrapperChainedInventory implements IInventory
}
@Override
public void setInventorySlotContents(int idx, ItemStack var2)
public void setInventorySlotContents( int idx, ItemStack var2 )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
io.i.setInventorySlotContents( idx - io.offset, var2 );
}
@@ -174,12 +169,18 @@ public class WrapperChainedInventory implements IInventory
return "ChainedInv";
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
int smallest = 64;
for (IInventory i : this.l)
for( IInventory i : this.l )
smallest = Math.min( smallest, i.getInventoryStackLimit() );
return smallest;
@@ -188,14 +189,14 @@ public class WrapperChainedInventory implements IInventory
@Override
public void markDirty()
{
for (IInventory i : this.l)
for( IInventory i : this.l )
{
i.markDirty();
}
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1)
public boolean isUseableByPlayer( EntityPlayer var1 )
{
return false;
}
@@ -211,20 +212,21 @@ public class WrapperChainedInventory implements IInventory
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public boolean isItemValidForSlot(int idx, ItemStack itemstack)
public boolean isItemValidForSlot( int idx, ItemStack itemstack )
{
InvOffset io = this.offsets.get( idx );
if ( io != null )
if( io != null )
{
return io.i.isItemValidForSlot( idx - io.offset, itemstack );
}
return false;
}
static class InvOffset
{
int offset;
int size;
IInventory i;
}
}
@@ -18,20 +18,40 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class WrapperInvSlot
{
private final IInventory inv;
public WrapperInvSlot( IInventory inv )
{
this.inv = inv;
}
public IInventory getWrapper( int slot )
{
return new InternalInterfaceWrapper( this.inv, slot );
}
protected boolean isItemValid( ItemStack itemstack )
{
return true;
}
class InternalInterfaceWrapper implements IInventory
{
private final IInventory inv;
private final int slot;
public InternalInterfaceWrapper(IInventory target, int slot) {
public InternalInterfaceWrapper( IInventory target, int slot )
{
this.inv = target;
this.slot = slot;
}
@@ -43,25 +63,25 @@ public class WrapperInvSlot
}
@Override
public ItemStack getStackInSlot(int i)
public ItemStack getStackInSlot( int i )
{
return this.inv.getStackInSlot( this.slot );
}
@Override
public ItemStack decrStackSize(int i, int num)
public ItemStack decrStackSize( int i, int num )
{
return this.inv.decrStackSize( this.slot, num );
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
public ItemStack getStackInSlotOnClosing( int i )
{
return this.inv.getStackInSlotOnClosing( this.slot );
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
public void setInventorySlotContents( int i, ItemStack itemstack )
{
this.inv.setInventorySlotContents( this.slot, itemstack );
}
@@ -91,7 +111,7 @@ public class WrapperInvSlot
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
public boolean isUseableByPlayer( EntityPlayer entityplayer )
{
return this.inv.isUseableByPlayer( entityplayer );
}
@@ -109,26 +129,9 @@ public class WrapperInvSlot
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
return WrapperInvSlot.this.isItemValid( itemstack ) && this.inv.isItemValidForSlot( this.slot, itemstack );
}
}
private final IInventory inv;
public WrapperInvSlot(IInventory inv) {
this.inv = inv;
}
public IInventory getWrapper(int slot)
{
return new InternalInterfaceWrapper( this.inv, slot );
}
protected boolean isItemValid(ItemStack itemstack)
{
return true;
}
}
@@ -18,25 +18,47 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
public class WrapperInventoryRange implements IInventory
{
private final IInventory src;
int[] slots;
protected boolean ignoreValidItems = false;
int[] slots;
public static String concatLines(int[] s, String separator)
public WrapperInventoryRange( IInventory a, int[] s, boolean ignoreValid )
{
if ( s.length > 0 )
this.src = a;
this.slots = s;
if( this.slots == null )
this.slots = new int[0];
this.ignoreValidItems = ignoreValid;
}
public WrapperInventoryRange( IInventory a, int _min, int _size, boolean ignoreValid )
{
this.src = a;
this.slots = new int[_size];
for( int x = 0; x < _size; x++ )
this.slots[x] = _min + x;
this.ignoreValidItems = ignoreValid;
}
public static String concatLines( int[] s, String separator )
{
if( s.length > 0 )
{
StringBuilder sb = new StringBuilder();
for (int value : s)
for( int value : s )
{
if ( sb.length() > 0 )
if( sb.length() > 0 )
{
sb.append( separator );
}
@@ -47,24 +69,6 @@ public class WrapperInventoryRange implements IInventory
return "";
}
public WrapperInventoryRange(IInventory a, int[] s, boolean ignoreValid) {
this.src = a;
this.slots = s;
if ( this.slots == null )
this.slots = new int[0];
this.ignoreValidItems = ignoreValid;
}
public WrapperInventoryRange(IInventory a, int _min, int _size, boolean ignoreValid) {
this.src = a;
this.slots = new int[_size];
for (int x = 0; x < _size; x++)
this.slots[x] = _min + x;
this.ignoreValidItems = ignoreValid;
}
@Override
public int getSizeInventory()
{
@@ -72,25 +76,25 @@ public class WrapperInventoryRange implements IInventory
}
@Override
public ItemStack getStackInSlot(int var1)
public ItemStack getStackInSlot( int var1 )
{
return this.src.getStackInSlot( this.slots[var1] );
}
@Override
public ItemStack decrStackSize(int var1, int var2)
public ItemStack decrStackSize( int var1, int var2 )
{
return this.src.decrStackSize( this.slots[var1], var2 );
}
@Override
public ItemStack getStackInSlotOnClosing(int var1)
public ItemStack getStackInSlotOnClosing( int var1 )
{
return this.src.getStackInSlotOnClosing( this.slots[var1] );
}
@Override
public void setInventorySlotContents(int var1, ItemStack var2)
public void setInventorySlotContents( int var1, ItemStack var2 )
{
this.src.setInventorySlotContents( this.slots[var1], var2 );
}
@@ -101,6 +105,12 @@ public class WrapperInventoryRange implements IInventory
return this.src.getInventoryName();
}
@Override
public boolean hasCustomInventoryName()
{
return false;
}
@Override
public int getInventoryStackLimit()
{
@@ -114,7 +124,7 @@ public class WrapperInventoryRange implements IInventory
}
@Override
public boolean isUseableByPlayer(EntityPlayer var1)
public boolean isUseableByPlayer( EntityPlayer var1 )
{
return this.src.isUseableByPlayer( var1 );
}
@@ -132,18 +142,11 @@ public class WrapperInventoryRange implements IInventory
}
@Override
public boolean hasCustomInventoryName()
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
return false;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
{
if ( this.ignoreValidItems )
if( this.ignoreValidItems )
return true;
return this.src.isItemValidForSlot( this.slots[i], itemstack );
}
}
@@ -18,50 +18,52 @@
package appeng.util.inv;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventoryWrapper
{
private final ForgeDirection dir;
final ISidedInventory side;
private final ForgeDirection dir;
public WrapperMCISidedInventory(ISidedInventory a, ForgeDirection d) {
public WrapperMCISidedInventory( ISidedInventory a, ForgeDirection d )
{
super( a, a.getAccessibleSlotsFromSide( d.ordinal() ), false );
this.side = a;
this.dir = d;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public ItemStack decrStackSize( int var1, int var2 )
{
if( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) )
return super.decrStackSize( var1, var2 );
return null;
}
@Override
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
if ( this.ignoreValidItems )
if( this.ignoreValidItems )
return true;
if ( this.side.isItemValidForSlot( this.slots[i], itemstack ) )
if( this.side.isItemValidForSlot( this.slots[i], itemstack ) )
return this.side.canInsertItem( this.slots[i], itemstack, this.dir.ordinal() );
return false;
}
@Override
public boolean canRemoveItemFromSlot(int i, ItemStack is)
public boolean canRemoveItemFromSlot( int i, ItemStack is )
{
if ( is == null )
if( is == null )
return false;
return this.side.canExtractItem( this.slots[i], is, this.dir.ordinal() );
}
@Override
public ItemStack decrStackSize(int var1, int var2)
{
if ( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) )
return super.decrStackSize( var1, var2 );
return null;
}
}
@@ -18,19 +18,22 @@
package appeng.util.inv;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;
public class WrapperTEPipe implements IInventory
{
final TileEntity ad;
final ForgeDirection dir;
public WrapperTEPipe(TileEntity te, ForgeDirection d) {
public WrapperTEPipe( TileEntity te, ForgeDirection d )
{
this.ad = te;
this.dir = d;
}
@@ -42,25 +45,25 @@ public class WrapperTEPipe implements IInventory
}
@Override
public ItemStack getStackInSlot(int i)
public ItemStack getStackInSlot( int i )
{
return null;
}
@Override
public ItemStack decrStackSize(int i, int j)
public ItemStack decrStackSize( int i, int j )
{
return null;
}
@Override
public ItemStack getStackInSlotOnClosing(int i)
public ItemStack getStackInSlotOnClosing( int i )
{
return null;
}
@Override
public void setInventorySlotContents(int i, ItemStack itemstack)
public void setInventorySlotContents( int i, ItemStack itemstack )
{
// ITE.addItemsToPipe( ad, itemstack, dir );
}
@@ -90,7 +93,7 @@ public class WrapperTEPipe implements IInventory
}
@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer)
public boolean isUseableByPlayer( EntityPlayer entityplayer )
{
return false;
}
@@ -108,9 +111,8 @@ public class WrapperTEPipe implements IInventory
}
@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack)
public boolean isItemValidForSlot( int i, ItemStack itemstack )
{
return false;
}
}