Relocate Source to proper directory.
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.iterators.NullIterator;
|
||||
|
||||
public class AdaptorBCPipe extends InventoryAdaptor
|
||||
{
|
||||
|
||||
final private IBC bc;
|
||||
final private TileEntity i;
|
||||
final private ForgeDirection d;
|
||||
|
||||
public AdaptorBCPipe(TileEntity s, ForgeDirection dd) {
|
||||
bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
if ( bc != null )
|
||||
{
|
||||
if ( bc.isPipe( s, dd ) )
|
||||
{
|
||||
i = s;
|
||||
d = dd;
|
||||
return;
|
||||
}
|
||||
}
|
||||
i = null;
|
||||
d = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int amount, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( i == null )
|
||||
return A;
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
if ( bc.addItemsToPipe( i, A, d ) )
|
||||
return null;
|
||||
return A;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
if ( i == null )
|
||||
return A;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new NullIterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,367 @@
|
||||
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 IInventory i;
|
||||
private boolean wrapperEnabled;
|
||||
|
||||
public AdaptorIInventory(IInventory s) {
|
||||
i = s;
|
||||
wrapperEnabled = s instanceof IInventoryWrapper;
|
||||
}
|
||||
|
||||
boolean canRemoveStackFromSlot(int x, ItemStack is)
|
||||
{
|
||||
if ( wrapperEnabled )
|
||||
return ((IInventoryWrapper) i).canRemoveItemFromSlot( x, is );
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
ItemStack rv = null;
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
|
||||
if ( is.stackSize == rv.stackSize )
|
||||
{
|
||||
i.setInventorySlotContents( x, null );
|
||||
i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= rv.stackSize;
|
||||
i.setInventorySlotContents( x, po );
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
if ( rv != null )
|
||||
{
|
||||
// i.markDirty();
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for (int x = 0; x < s && how_many > 0; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
filter = rv;
|
||||
rv.stackSize = lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.stackSize += lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
|
||||
if ( is.stackSize == lhow_many )
|
||||
{
|
||||
i.setInventorySlotContents( x, null );
|
||||
i.markDirty();
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack po = is.copy();
|
||||
po.stackSize -= lhow_many;
|
||||
i.setInventorySlotContents( x, po );
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if ( rv != null )
|
||||
// i.markDirty();
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
int s = i.getSizeInventory();
|
||||
ItemStack rv = null;
|
||||
|
||||
for (int x = 0; x < s && how_many > 0; x++)
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is != null && canRemoveStackFromSlot( x, is ) && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
int lhow_many = how_many;
|
||||
if ( lhow_many > is.stackSize )
|
||||
lhow_many = is.stackSize;
|
||||
if ( destination != null && !destination.canInsert( is ) )
|
||||
lhow_many = 0;
|
||||
|
||||
if ( lhow_many > 0 )
|
||||
{
|
||||
if ( rv == null )
|
||||
{
|
||||
rv = is.copy();
|
||||
rv.stackSize = lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv.stackSize += lhow_many;
|
||||
how_many -= lhow_many;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int stack_limit = A.getMaxStackSize();
|
||||
if ( stack_limit > i.getInventoryStackLimit() )
|
||||
stack_limit = i.getInventoryStackLimit();
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int pass = 0; pass < 2; pass++)
|
||||
{
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.isItemValidForSlot( x, A ) )
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is == null && pass != 0 )
|
||||
{
|
||||
ItemStack thisSlot = left.copy();
|
||||
if ( thisSlot.stackSize > stack_limit )
|
||||
thisSlot.stackSize = stack_limit;
|
||||
left.stackSize -= thisSlot.stackSize;
|
||||
|
||||
i.setInventorySlotContents( x, thisSlot );
|
||||
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
// i.markDirty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else if ( is != null )
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( is, left ) )
|
||||
{
|
||||
if ( is.stackSize < stack_limit )
|
||||
{
|
||||
int room = stack_limit - is.stackSize;
|
||||
int used = left.stackSize;
|
||||
if ( used > room )
|
||||
used = room;
|
||||
|
||||
is.stackSize += used;
|
||||
i.setInventorySlotContents( x, is );
|
||||
i.markDirty();
|
||||
|
||||
left.stackSize -= used;
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
// i.markDirty();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// if ( left.stackSize != A.stackSize )
|
||||
// i.markDirty();
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return A;
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int stack_limit = A.getMaxStackSize();
|
||||
if ( stack_limit > i.getInventoryStackLimit() )
|
||||
stack_limit = i.getInventoryStackLimit();
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
if ( i.isItemValidForSlot( x, A ) )
|
||||
{
|
||||
ItemStack is = i.getStackInSlot( x );
|
||||
if ( is == null )
|
||||
{
|
||||
ItemStack thisSlot = left.copy();
|
||||
if ( thisSlot.stackSize > stack_limit )
|
||||
thisSlot.stackSize = stack_limit;
|
||||
left.stackSize -= thisSlot.stackSize;
|
||||
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( Platform.isSameItemPrecise( is, left ) )
|
||||
{
|
||||
if ( is.stackSize < stack_limit )
|
||||
{
|
||||
int room = stack_limit - is.stackSize;
|
||||
int used = left.stackSize;
|
||||
if ( used > room )
|
||||
used = room;
|
||||
|
||||
left.stackSize -= used;
|
||||
if ( left.stackSize <= 0 )
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return left;
|
||||
}
|
||||
|
||||
class InvIterator implements Iterator<ItemSlot>
|
||||
{
|
||||
|
||||
final ItemSlot is = new ItemSlot();
|
||||
int x = 0;
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
return x < i.getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
ItemStack iss = i.getStackInSlot( x );
|
||||
|
||||
is.isExtractable = canRemoveStackFromSlot( x, iss );
|
||||
is.setItemStack( iss );
|
||||
|
||||
is.slot = x++;
|
||||
return is;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
// nothing!
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new InvIterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import buildcraft.api.inventory.ISpecialInventory;
|
||||
|
||||
public class AdaptorISpecialInventory extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private AdaptorIInventory remover;
|
||||
|
||||
private ISpecialInventory i;
|
||||
private ForgeDirection d;
|
||||
|
||||
public AdaptorISpecialInventory(ISpecialInventory s, ForgeDirection dd) {
|
||||
i = s;
|
||||
d = dd;
|
||||
|
||||
if ( s instanceof ISidedInventory )
|
||||
remover = new AdaptorIInventory( new WrapperMCISidedInventory( (ISidedInventory) s, d ) );
|
||||
else
|
||||
remover = new AdaptorIInventory( s );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return remover.removeSimilarItems( how_many, filter, fuzzyMode, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
return remover.simulateSimilarRemove( how_many, filter, fuzzyMode, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return remover.removeItems( how_many, filter, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination destination)
|
||||
{
|
||||
return remover.simulateRemove( how_many, filter, destination );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
int used = i.addItem( A, true, d );
|
||||
ItemStack out = A.copy();
|
||||
out.stackSize -= used;
|
||||
if ( out.stackSize > 0 )
|
||||
return out;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
int used = i.addItem( A, false, d );
|
||||
ItemStack out = A.copy();
|
||||
out.stackSize -= used;
|
||||
if ( out.stackSize > 0 )
|
||||
return out;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
if ( i instanceof ISidedInventory )
|
||||
{
|
||||
ISidedInventory sided = (ISidedInventory) i;
|
||||
int slots[] = sided.getAccessibleSlotsFromSide( d.ordinal() );
|
||||
|
||||
if ( slots == null )
|
||||
return false;
|
||||
|
||||
int s = slots.length;
|
||||
for (int x = 0; x < s; x++)
|
||||
if ( i.getStackInSlot( slots[x] ) != null )
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int s = i.getSizeInventory();
|
||||
for (int x = 0; x < s; x++)
|
||||
if ( i.getStackInSlot( x ) != null )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return remover.iterator();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,186 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.StackToSlotIterator;
|
||||
|
||||
public class AdaptorList extends InventoryAdaptor
|
||||
{
|
||||
|
||||
private List<ItemStack> i;
|
||||
|
||||
public AdaptorList(List<ItemStack> s) {
|
||||
i = s;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.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 )
|
||||
i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemFuzzy( is, filter, fuzzyMode )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if ( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack filter, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.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 )
|
||||
i.remove( x );
|
||||
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack filter, IInventoryDestination dest)
|
||||
{
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null && (filter == null || Platform.isSameItemPrecise( is, filter )) )
|
||||
{
|
||||
if ( how_many > is.stackSize )
|
||||
how_many = is.stackSize;
|
||||
if ( dest != null && !dest.canInsert( is ) )
|
||||
how_many = 0;
|
||||
|
||||
if ( how_many > 0 )
|
||||
{
|
||||
ItemStack rv = is.copy();
|
||||
rv.stackSize = how_many;
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
|
||||
ItemStack left = A.copy();
|
||||
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( Platform.isSameItem( is, left ) )
|
||||
{
|
||||
is.stackSize += left.stackSize;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
i.add( left );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
|
||||
int s = i.size();
|
||||
for (int x = 0; x < s; x++)
|
||||
{
|
||||
ItemStack is = i.get( x );
|
||||
if ( is != null )
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new StackToSlotIterator( i.iterator() );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
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 EntityPlayer p;
|
||||
|
||||
public AdaptorPlayerHand(EntityPlayer _p) {
|
||||
p = _p;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
ItemStack hand = 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 )
|
||||
p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack Filter, FuzzyMode fuzzyMode, IInventoryDestination dest)
|
||||
{
|
||||
|
||||
ItemStack hand = 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;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination dest)
|
||||
{
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
hand.stackSize -= how_many;
|
||||
if ( hand.stackSize <= 0 )
|
||||
p.inventory.setItemStack( null );
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination dest)
|
||||
{
|
||||
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( hand == null )
|
||||
return null;
|
||||
|
||||
if ( Filter == null || Platform.isSameItemPrecise( Filter, hand ) )
|
||||
{
|
||||
ItemStack result = hand.copy();
|
||||
result.stackSize = hand.stackSize > how_many ? how_many : hand.stackSize;
|
||||
return result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
|
||||
if ( A == null )
|
||||
return null;
|
||||
if ( A.stackSize == 0 )
|
||||
return null;
|
||||
if ( p == null )
|
||||
return A;
|
||||
if ( p.inventory == null )
|
||||
return A;
|
||||
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
|
||||
if ( hand != null && !Platform.isSameItem( A, hand ) )
|
||||
return A;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
newHand = A.copy();
|
||||
else
|
||||
{
|
||||
newHand = hand;
|
||||
original = hand.stackSize;
|
||||
newHand.stackSize += A.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = A.copy();
|
||||
B.stackSize -= newHand.stackSize - original;
|
||||
p.inventory.setItemStack( newHand );
|
||||
return B;
|
||||
}
|
||||
|
||||
p.inventory.setItemStack( newHand );
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
ItemStack hand = p.inventory.getItemStack();
|
||||
if ( A == null )
|
||||
return null;
|
||||
|
||||
if ( hand != null && !Platform.isSameItem( A, hand ) )
|
||||
return A;
|
||||
|
||||
int original = 0;
|
||||
ItemStack newHand = null;
|
||||
if ( hand == null )
|
||||
newHand = A.copy();
|
||||
else
|
||||
{
|
||||
newHand = hand.copy();
|
||||
original = hand.stackSize;
|
||||
newHand.stackSize += A.stackSize;
|
||||
}
|
||||
|
||||
if ( newHand.stackSize > newHand.getMaxStackSize() )
|
||||
{
|
||||
newHand.stackSize = newHand.getMaxStackSize();
|
||||
ItemStack B = A.copy();
|
||||
B.stackSize -= newHand.stackSize - original;
|
||||
return B;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return p.inventory.getItemStack() != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new NullIterator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
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;
|
||||
|
||||
public AdaptorPlayerInventory(IInventory playerInv, boolean swap)
|
||||
{
|
||||
|
||||
if ( swap )
|
||||
src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, size-9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) );
|
||||
else
|
||||
src = playerInv;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
{
|
||||
return src.getStackInSlot( var1 + min );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
return src.decrStackSize( min + var1, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
{
|
||||
return src.getStackInSlotOnClosing( min + var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
{
|
||||
src.setInventorySlotContents( var1 + min, var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return src.isUseableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
src.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
src.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryDestination
|
||||
{
|
||||
|
||||
public boolean canInsert(ItemStack stack);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface IInventoryWrapper
|
||||
{
|
||||
|
||||
boolean canRemoveItemFromSlot(int x, ItemStack is);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.FuzzyMode;
|
||||
import appeng.api.networking.security.BaseActionSource;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.storage.data.IItemList;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
public class IMEAdaptor extends InventoryAdaptor
|
||||
{
|
||||
|
||||
IMEInventory<IAEItemStack> target;
|
||||
BaseActionSource src;
|
||||
int maxSlots = 0;
|
||||
|
||||
public IMEAdaptor(IMEInventory<IAEItemStack> input, BaseActionSource src) {
|
||||
target = input;
|
||||
this.src = src;
|
||||
}
|
||||
|
||||
IItemList<IAEItemStack> getList()
|
||||
{
|
||||
return target.getAvailableItems( AEApi.instance().storage().createItemList() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemSlot> iterator()
|
||||
{
|
||||
return new IMEAdaptorIterator( this, getList() );
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItemsFuzzy(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type, FuzzyMode fuzzyMode)
|
||||
{
|
||||
IAEItemStack reqFilter = AEItemStack.create( Filter );
|
||||
if ( reqFilter == null )
|
||||
return null;
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
for (IAEItemStack req : ImmutableList.copyOf( getList().findFuzzy( reqFilter, fuzzyMode ) ))
|
||||
{
|
||||
if ( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = target.extractItems( req, type, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public ItemStack doRemoveItems(int how_many, ItemStack Filter, IInventoryDestination destination, Actionable type)
|
||||
{
|
||||
IAEItemStack req = null;
|
||||
|
||||
if ( Filter == null )
|
||||
{
|
||||
IItemList<IAEItemStack> list = getList();
|
||||
if ( !list.isEmpty() )
|
||||
req = list.getFirstItem();
|
||||
}
|
||||
else
|
||||
req = AEItemStack.create( Filter );
|
||||
|
||||
IAEItemStack out = null;
|
||||
|
||||
if ( req != null )
|
||||
{
|
||||
req.setStackSize( how_many );
|
||||
out = target.extractItems( req, type, src );
|
||||
}
|
||||
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeItems(int how_many, ItemStack Filter, IInventoryDestination destination)
|
||||
{
|
||||
return doRemoveItems( how_many, Filter, destination, Actionable.MODULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateRemove(int how_many, ItemStack Filter, IInventoryDestination destination)
|
||||
{
|
||||
return doRemoveItems( how_many, Filter, destination, Actionable.SIMULATE );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeSimilarItems(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
if ( filter == null )
|
||||
return doRemoveItems( how_many, null, destination, Actionable.MODULATE );
|
||||
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.MODULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateSimilarRemove(int how_many, ItemStack filter, FuzzyMode fuzzyMode, IInventoryDestination destination)
|
||||
{
|
||||
if ( filter == null )
|
||||
return doRemoveItems( how_many, null, destination, Actionable.SIMULATE );
|
||||
return doRemoveItemsFuzzy( how_many, filter, destination, Actionable.SIMULATE, fuzzyMode );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack addItems(ItemStack A)
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( A );
|
||||
if ( in != null )
|
||||
{
|
||||
IAEItemStack out = target.injectItems( in, Actionable.MODULATE, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack simulateAdd(ItemStack A)
|
||||
{
|
||||
IAEItemStack in = AEItemStack.create( A );
|
||||
if ( in != null )
|
||||
{
|
||||
IAEItemStack out = target.injectItems( in, Actionable.SIMULATE, src );
|
||||
if ( out != null )
|
||||
return out.getItemStack();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean containsItems()
|
||||
{
|
||||
return !getList().isEmpty();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
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>
|
||||
{
|
||||
|
||||
Iterator<IAEItemStack> stack;
|
||||
ItemSlot slot = new ItemSlot();
|
||||
int offset = 0;
|
||||
boolean hasNext;
|
||||
|
||||
final IMEAdaptor parent;
|
||||
final int containerSize;
|
||||
|
||||
public IMEAdaptorIterator(IMEAdaptor parent, IItemList<IAEItemStack> availableItems) {
|
||||
stack = availableItems.iterator();
|
||||
containerSize = parent.maxSlots;
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasNext()
|
||||
{
|
||||
hasNext = stack.hasNext();
|
||||
return offset < containerSize || hasNext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemSlot next()
|
||||
{
|
||||
slot.slot = offset++;
|
||||
slot.isExtractable=true;
|
||||
|
||||
if ( parent.maxSlots < offset )
|
||||
parent.maxSlots = offset;
|
||||
|
||||
if ( hasNext )
|
||||
{
|
||||
IAEItemStack item = stack.next();
|
||||
slot.setAEItemStack( item );
|
||||
return slot;
|
||||
}
|
||||
|
||||
slot.setItemStack( null );
|
||||
return slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remove()
|
||||
{
|
||||
throw new RuntimeException( "Not Implemented!" );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.storage.IMEInventory;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
public class IMEInventoryDestination implements IInventoryDestination
|
||||
{
|
||||
|
||||
IMEInventory<IAEItemStack> me;
|
||||
|
||||
public IMEInventoryDestination(IMEInventory<IAEItemStack> o) {
|
||||
me = o;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsert(ItemStack stack)
|
||||
{
|
||||
|
||||
if ( stack == null )
|
||||
return false;
|
||||
|
||||
IAEItemStack failed = me.injectItems( AEItemStack.create( stack ), Actionable.SIMULATE, null );
|
||||
|
||||
if ( failed == null )
|
||||
return true;
|
||||
return failed.getStackSize() != stack.stackSize;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
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) {
|
||||
target = cla;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(T option)
|
||||
{
|
||||
if ( option != null && option.isCraftable() )
|
||||
{
|
||||
option = (T) option.copy();
|
||||
option.setCraftable( false );
|
||||
}
|
||||
|
||||
target.add( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCrafting(T option)
|
||||
{
|
||||
// nothing.
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findPrecise(T i)
|
||||
{
|
||||
return target.findPrecise( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<T> findFuzzy(T input, FuzzyMode fuzzy)
|
||||
{
|
||||
return target.findFuzzy( input, fuzzy );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return target.isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStorage(T option)
|
||||
{
|
||||
target.addStorage( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addRequestable(T option)
|
||||
{
|
||||
target.addRequestable( option );
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getFirstItem()
|
||||
{
|
||||
return target.getFirstItem();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size()
|
||||
{
|
||||
return target.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator()
|
||||
{
|
||||
return target.iterator();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resetStatus()
|
||||
{
|
||||
target.resetStatus();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
|
||||
// one or the other..
|
||||
private IAEItemStack aeitemstack;
|
||||
private ItemStack itemStack;
|
||||
|
||||
public boolean isExtractable;
|
||||
|
||||
public void setItemStack(ItemStack is)
|
||||
{
|
||||
aeitemstack = null;
|
||||
itemStack = is;
|
||||
}
|
||||
|
||||
public void setAEItemStack(IAEItemStack is)
|
||||
{
|
||||
aeitemstack = is;
|
||||
itemStack = null;
|
||||
}
|
||||
|
||||
public ItemStack getItemStack()
|
||||
{
|
||||
return itemStack == null ? (aeitemstack == null ? null : (itemStack = aeitemstack.getItemStack())) : itemStack;
|
||||
}
|
||||
|
||||
public IAEItemStack getAEItemStack()
|
||||
{
|
||||
return aeitemstack == null ? (itemStack == null ? null : (aeitemstack = AEItemStack.create( itemStack ))) : aeitemstack;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
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;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.integration.IntegrationType;
|
||||
import appeng.integration.abstraction.IBC;
|
||||
|
||||
public class WrapperBCPipe implements IInventory
|
||||
{
|
||||
|
||||
final private IBC bc;
|
||||
final private TileEntity ad;
|
||||
final private ForgeDirection dir;
|
||||
|
||||
public WrapperBCPipe(TileEntity te, ForgeDirection d) {
|
||||
bc = (IBC) AppEng.instance.getIntegration( IntegrationType.BC );
|
||||
ad = te;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
bc.addItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "BC Pipe Wrapper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return bc.canAddItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,212 @@
|
||||
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;
|
||||
|
||||
public class WrapperChainedInventory implements IInventory
|
||||
{
|
||||
|
||||
class InvOffset
|
||||
{
|
||||
|
||||
int offset;
|
||||
int size;
|
||||
IInventory i;
|
||||
};
|
||||
|
||||
int fullSize = 0;
|
||||
|
||||
private List<IInventory> l;
|
||||
private HashMap<Integer, InvOffset> offsets;
|
||||
|
||||
public WrapperChainedInventory(IInventory... ilist) {
|
||||
setInventory( ilist );
|
||||
}
|
||||
|
||||
public WrapperChainedInventory(List<IInventory> ilist) {
|
||||
setInventory( ilist );
|
||||
}
|
||||
|
||||
public void cycleOrder()
|
||||
{
|
||||
if ( l.size() > 1 )
|
||||
{
|
||||
List<IInventory> newOrder = new ArrayList( l.size() );
|
||||
newOrder.add( l.get( l.size() - 1 ) );
|
||||
for (int x = 0; x < l.size() - 1; x++)
|
||||
newOrder.add( l.get( x ) );
|
||||
setInventory( newOrder );
|
||||
}
|
||||
}
|
||||
|
||||
public void calculateSizes()
|
||||
{
|
||||
offsets = new HashMap<Integer, WrapperChainedInventory.InvOffset>();
|
||||
|
||||
int offset = 0;
|
||||
for (IInventory in : l)
|
||||
{
|
||||
InvOffset io = new InvOffset();
|
||||
io.offset = offset;
|
||||
io.size = in.getSizeInventory();
|
||||
io.i = in;
|
||||
|
||||
for (int y = 0; y < io.size; y++)
|
||||
{
|
||||
offsets.put( y + io.offset, io );
|
||||
}
|
||||
|
||||
offset += io.size;
|
||||
}
|
||||
|
||||
fullSize = offset;
|
||||
}
|
||||
|
||||
public void setInventory(IInventory... a)
|
||||
{
|
||||
l = ImmutableList.copyOf( a );
|
||||
calculateSizes();
|
||||
}
|
||||
|
||||
public void setInventory(List<IInventory> a)
|
||||
{
|
||||
l = a;
|
||||
calculateSizes();
|
||||
}
|
||||
|
||||
public IInventory getInv(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public int getInvSlot(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return idx - io.offset;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return fullSize;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.getStackInSlot( idx - io.offset );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int idx, int var2)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.decrStackSize( idx - io.offset, var2 );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int idx)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.getStackInSlotOnClosing( idx - io.offset );
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int idx, ItemStack var2)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
io.i.setInventorySlotContents( idx - io.offset, var2 );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return "ChainedInv";
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
int smallest = 64;
|
||||
|
||||
for (IInventory i : l)
|
||||
smallest = Math.min( smallest, i.getInventoryStackLimit() );
|
||||
|
||||
return smallest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
for (IInventory i : l)
|
||||
{
|
||||
i.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int idx, ItemStack itemstack)
|
||||
{
|
||||
InvOffset io = offsets.get( idx );
|
||||
if ( io != null )
|
||||
{
|
||||
return io.i.isItemValidForSlot( idx - io.offset, itemstack );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class WrapperInvSlot
|
||||
{
|
||||
|
||||
class InternalInterfaceWrapper implements IInventory
|
||||
{
|
||||
|
||||
private final IInventory inv;
|
||||
private final int slot;
|
||||
|
||||
public InternalInterfaceWrapper(IInventory target, int slot) {
|
||||
this.inv = target;
|
||||
this.slot = slot;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return inv.getStackInSlot( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int num)
|
||||
{
|
||||
return inv.decrStackSize( slot, num );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return inv.getStackInSlotOnClosing( slot );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
inv.setInventorySlotContents( slot, itemstack );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return inv.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return inv.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return inv.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
inv.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return inv.isUseableByPlayer( entityplayer );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
inv.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
inv.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return isItemValid( itemstack ) && inv.isItemValidForSlot( slot, itemstack );
|
||||
}
|
||||
};
|
||||
|
||||
private IInventory inv;
|
||||
|
||||
public WrapperInvSlot(IInventory inv) {
|
||||
this.inv = inv;
|
||||
}
|
||||
|
||||
public IInventory getWrapper(int slot)
|
||||
{
|
||||
InternalInterfaceWrapper wrapper = new InternalInterfaceWrapper( inv, slot );
|
||||
return wrapper;
|
||||
}
|
||||
|
||||
protected boolean isItemValid(ItemStack itemstack)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,129 @@
|
||||
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 IInventory src;
|
||||
int[] slots;
|
||||
protected boolean ignoreValidItems = false;
|
||||
|
||||
public static String concatLines(int[] s, String separator)
|
||||
{
|
||||
if ( s.length > 0 )
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < s.length; i++)
|
||||
{
|
||||
if ( sb.length() > 0 )
|
||||
sb.append( separator );
|
||||
sb.append( s[i] );
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int[] s, boolean ignoreValid) {
|
||||
src = a;
|
||||
slots = s;
|
||||
|
||||
if ( slots == null )
|
||||
slots = new int[0];
|
||||
|
||||
ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
public WrapperInventoryRange(IInventory a, int _min, int _size, boolean ignoreValid) {
|
||||
src = a;
|
||||
slots = new int[_size];
|
||||
for (int x = 0; x < _size; x++)
|
||||
slots[x] = _min + x;
|
||||
ignoreValidItems = ignoreValid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return slots.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int var1)
|
||||
{
|
||||
return src.getStackInSlot( slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
return src.decrStackSize( slots[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int var1)
|
||||
{
|
||||
return src.getStackInSlotOnClosing( slots[var1] );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int var1, ItemStack var2)
|
||||
{
|
||||
src.setInventorySlotContents( slots[var1], var2 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return src.getInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return src.getInventoryStackLimit();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
src.markDirty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer var1)
|
||||
{
|
||||
return src.isUseableByPlayer( var1 );
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
src.openInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
src.closeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
if ( ignoreValidItems )
|
||||
return true;
|
||||
|
||||
return src.isItemValidForSlot( slots[i], itemstack );
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package appeng.util.inv;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventory, IInventoryWrapper
|
||||
{
|
||||
|
||||
private ForgeDirection dir;
|
||||
ISidedInventory side;
|
||||
|
||||
public WrapperMCISidedInventory(ISidedInventory a, ForgeDirection d) {
|
||||
super( a, a.getAccessibleSlotsFromSide( d.ordinal() ), false );
|
||||
side = a;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
|
||||
if ( ignoreValidItems )
|
||||
return true;
|
||||
|
||||
if ( side.isItemValidForSlot( slots[i], itemstack ) )
|
||||
return side.canInsertItem( slots[i], itemstack, dir.ordinal() );
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRemoveItemFromSlot(int i, ItemStack is)
|
||||
{
|
||||
if ( is == null )
|
||||
return false;
|
||||
|
||||
return side.canExtractItem( slots[i], is, dir.ordinal() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int var1, int var2)
|
||||
{
|
||||
if ( canRemoveItemFromSlot( var1, getStackInSlot( var1 ) ) )
|
||||
return super.decrStackSize( var1, var2 );
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
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
|
||||
{
|
||||
|
||||
TileEntity ad;
|
||||
ForgeDirection dir;
|
||||
|
||||
public WrapperTEPipe(TileEntity te, ForgeDirection d) {
|
||||
ad = te;
|
||||
dir = d;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize(int i, int j)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlotOnClosing(int i)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents(int i, ItemStack itemstack)
|
||||
{
|
||||
// ITE.addItemsToPipe( ad, itemstack, dir );
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getInventoryName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUseableByPlayer(EntityPlayer entityplayer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemstack)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user