Use IItemHandler instead of IInventory internally (#2971)

* Use IItemHandler instead of IInventory internally
This commit is contained in:
fscan
2017-07-28 22:04:32 +02:00
committed by yueh
parent c077840988
commit 52d28fabe3
156 changed files with 2410 additions and 4604 deletions
@@ -21,11 +21,11 @@ package appeng.tile.misc;
import java.util.List;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.CopyMode;
import appeng.api.config.Settings;
@@ -38,10 +38,11 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalAEInventory;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, IAEAppEngInventory, IConfigManagerHost
@@ -51,8 +52,8 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, 63 );
private final ConfigManager manager = new ConfigManager( this );
private IInventory cacheUpgrades = null;
private IInventory cacheConfig = null;
private IItemHandler cacheUpgrades = null;
private IItemHandler cacheConfig = null;
private boolean locked = false;
public TileCellWorkbench()
@@ -61,7 +62,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
this.cell.setEnableClientEvents( true );
}
public IInventory getCellUpgradeInventory()
public IItemHandler getCellUpgradeInventory()
{
if( this.cacheUpgrades == null )
{
@@ -77,7 +78,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
return null;
}
final IInventory inv = cell.getUpgradesInventory( is );
final IItemHandler inv = cell.getUpgradesInventory( is );
if( inv == null )
{
return null;
@@ -120,7 +121,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "config" ) )
{
@@ -142,7 +143,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
if( inv == this.cell && !this.locked )
{
@@ -151,11 +152,11 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
this.cacheUpgrades = null;
this.cacheConfig = null;
final IInventory configInventory = this.getCellConfigInventory();
final IItemHandler configInventory = this.getCellConfigInventory();
if( configInventory != null )
{
boolean cellHasConfig = false;
for( int x = 0; x < configInventory.getSizeInventory(); x++ )
for( int x = 0; x < configInventory.getSlots(); x++ )
{
if( !configInventory.getStackInSlot( x ).isEmpty() )
{
@@ -166,26 +167,21 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
if( cellHasConfig )
{
for( int x = 0; x < this.config.getSizeInventory(); x++ )
for( int x = 0; x < this.config.getSlots(); x++ )
{
this.config.setInventorySlotContents( x, configInventory.getStackInSlot( x ) );
this.config.setStackInSlot( x, configInventory.getStackInSlot( x ) );
}
}
else
{
for( int x = 0; x < this.config.getSizeInventory(); x++ )
{
configInventory.setInventorySlotContents( x, this.config.getStackInSlot( x ) );
}
configInventory.markDirty();
ItemHandlerUtil.copy( this.config, configInventory, false );
}
}
else if( this.manager.getSetting( Settings.COPY_MODE ) == CopyMode.CLEAR_ON_REMOVE )
{
for( int x = 0; x < this.config.getSizeInventory(); x++ )
for( int x = 0; x < this.config.getSlots(); x++ )
{
this.config.setInventorySlotContents( x, ItemStack.EMPTY );
this.config.setStackInSlot( x, ItemStack.EMPTY );
}
this.markDirty();
@@ -195,20 +191,15 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
}
else if( inv == this.config && !this.locked )
{
final IInventory c = this.getCellConfigInventory();
final IItemHandler c = this.getCellConfigInventory();
if( c != null )
{
for( int x = 0; x < this.config.getSizeInventory(); x++ )
{
c.setInventorySlotContents( x, this.config.getStackInSlot( x ) );
}
c.markDirty();
ItemHandlerUtil.copy( this.config, c, false );
}
}
}
private IInventory getCellConfigInventory()
private IItemHandler getCellConfigInventory()
{
if( this.cacheConfig == null )
{
@@ -224,7 +215,7 @@ public class TileCellWorkbench extends AEBaseTile implements IUpgradeableHost, I
return null;
}
final IInventory inv = cell.getConfigInventory( is );
final IItemHandler inv = cell.getConfigInventory( is );
if( inv == null )
{
return null;
+41 -56
View File
@@ -27,9 +27,9 @@ import java.util.List;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -53,16 +53,15 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkPowerTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
import appeng.util.item.AEItemStack;
public class TileCharger extends AENetworkPowerTile implements ICrankable, IGridTickable
{
private final int[] sides = { 0 };
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1, 1, new ChargerInvFilter() );
private int tickTickTimer = 0;
private int lastUpdate = 0;
@@ -89,11 +88,11 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
{
final IAEItemStack item = AEItemStack.loadItemStackFromPacket( data );
final ItemStack is = item.getItemStack();
this.inv.setInventorySlotContents( 0, is );
this.inv.setStackInSlot( 0, is );
}
catch( final Throwable t )
{
this.inv.setInventorySlotContents( 0, ItemStack.EMPTY );
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
}
return false; // TESR doesn't need updates!
}
@@ -101,7 +100,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
@TileEvent( TileEventType.NETWORK_WRITE )
public void writeToStream_TileCharger( final ByteBuf data ) throws IOException
{
final AEItemStack is = AEItemStack.create( this.getStackInSlot( 0 ) );
final AEItemStack is = AEItemStack.create( this.inv.getStackInSlot( 0 ) );
if( is != null )
{
is.writeToPacket( data );
@@ -133,7 +132,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
{
this.injectExternalPower( PowerUnits.AE, 150 );
final ItemStack myItem = this.getStackInSlot( 0 );
final ItemStack myItem = this.inv.getStackInSlot( 0 );
if( this.getInternalCurrentPower() > 1499 )
{
final IMaterials materials = AEApi.instance().definitions().materials();
@@ -142,7 +141,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.setInventorySlotContents( 0, charged ) );
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
}
}
}
@@ -154,27 +153,13 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.inv;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
final IItemDefinition cert = AEApi.instance().definitions().materials().certusQuartzCrystal();
return Platform.isChargeable( itemstack ) || cert.isSameAs( itemstack );
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
try
{
@@ -188,27 +173,6 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
this.markForUpdate();
}
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
if( Platform.isChargeable( extractedItem ) )
{
final IAEItemPowerStorage ips = (IAEItemPowerStorage) extractedItem.getItem();
if( ips.getAECurrentPower( extractedItem ) >= ips.getAEMaxPower( extractedItem ) )
{
return true;
}
}
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( extractedItem );
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing whichSide )
{
return this.sides;
}
public void activate( final EntityPlayer player )
{
if( !Platform.hasPermissions( new DimensionalCoord( this ), player ) )
@@ -216,7 +180,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
return;
}
final ItemStack myItem = this.getStackInSlot( 0 );
final ItemStack myItem = this.inv.getStackInSlot( 0 );
if( myItem.isEmpty() )
{
ItemStack held = player.inventory.getCurrentItem();
@@ -224,14 +188,14 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
if( AEApi.instance().definitions().materials().certusQuartzCrystal().isSameAs( held ) || Platform.isChargeable( held ) )
{
held = player.inventory.decrStackSize( player.inventory.currentItem, 1 );
this.setInventorySlotContents( 0, held );
this.inv.setStackInSlot( 0, held );
}
}
else
{
final List<ItemStack> drops = new ArrayList<>();
drops.add( myItem );
this.setInventorySlotContents( 0, ItemStack.EMPTY );
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
Platform.spawnDrops( this.world, this.pos.offset( this.getForward() ), drops );
}
}
@@ -250,7 +214,7 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
private boolean doWork()
{
final ItemStack myItem = this.getStackInSlot( 0 );
final ItemStack myItem = this.inv.getStackInSlot( 0 );
// charge from the network!
if( this.getInternalCurrentPower() < 1499 )
@@ -297,17 +261,38 @@ public class TileCharger extends AENetworkPowerTile implements ICrankable, IGrid
{
this.extractAEPower( this.getInternalMaxPower(), Actionable.MODULATE, PowerMultiplier.CONFIG );// 1500
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.setInventorySlotContents( 0, charged ) );
materials.certusQuartzCrystalCharged().maybeStack( myItem.getCount() ).ifPresent( charged -> this.inv.setStackInSlot( 0, charged ) );
}
}
return true;
}
@Override
public boolean isEmpty()
private class ChargerInvFilter implements IAEItemFilter
{
// TODO Auto-generated method stub
return false;
@Override
public boolean allowInsert( IItemHandler inv, final int i, final ItemStack itemstack )
{
final IItemDefinition cert = AEApi.instance().definitions().materials().certusQuartzCrystal();
return Platform.isChargeable( itemstack ) || cert.isSameAs( itemstack );
}
@Override
public boolean allowExtract( IItemHandler inv, final int slotIndex, int amount )
{
ItemStack extractedItem = inv.getStackInSlot( slotIndex );
if( Platform.isChargeable( extractedItem ) )
{
final IAEItemPowerStorage ips = (IAEItemPowerStorage) extractedItem.getItem();
if( ips.getAECurrentPower( extractedItem ) >= ips.getAEMaxPower( extractedItem ) )
{
return true;
}
}
return AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( extractedItem );
}
}
}
@@ -21,7 +21,6 @@ package appeng.tile.misc;
import javax.annotation.Nullable;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
@@ -52,10 +51,10 @@ import appeng.tile.AEBaseInvTile;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperChainedItemHandler;
public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost, IConfigurableObject
@@ -63,16 +62,15 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
public static final int BYTE_MULTIPLIER = 8;
private final int[] sides = {
0,
1
};
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 3 );
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
private final ConfigManager cm = new ConfigManager( this );
private final IItemHandler itemHandler = new ItemHandler();
private final IItemHandler inputSlot = new CondenseItemHandler();
private final IFluidHandler fluidHandler = new FluidHandler();
private final MEHandler meHandler = new MEHandler();
private final IItemHandler combinedInv = new WrapperChainedItemHandler( inputSlot, inv );
private double storedPower = 0;
public TileCondenser()
@@ -96,7 +94,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
public double getStorage()
{
final ItemStack is = this.inv.getStackInSlot( 2 );
final ItemStack is = this.inv.getStackInSlot( 1 );
if( !is.isEmpty() )
{
if( is.getItem() instanceof IStorageComponent )
@@ -134,9 +132,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
private boolean canAddOutput( final ItemStack output )
{
final ItemStack outputStack = this.getStackInSlot( 1 );
return outputStack.isEmpty() || ( Platform.itemComparisons().isEqualItem( outputStack,
output ) && outputStack.getCount() < outputStack.getMaxStackSize() );
return inv.insertItem( 0, output, true ).isEmpty();
}
/**
@@ -146,16 +142,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
*/
private void addOutput( final ItemStack output )
{
final ItemStack outputStack = this.getStackInSlot( 1 );
if( outputStack.isEmpty() )
{
this.setInventorySlotContents( 1, output.copy() );
}
else
{
outputStack.grow( 1 );
this.setInventorySlotContents( 1, outputStack );
}
inv.insertItem( 0, output, false );
}
private ItemStack getOutput()
@@ -182,63 +169,15 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.inv;
return this.combinedInv;
}
@Override
public void setInventorySlotContents( final int i, final ItemStack itemstack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( i == 0 )
{
if( !itemstack.isEmpty() )
{
this.addPower( itemstack.getCount() );
}
}
else
{
this.inv.setInventorySlotContents( 1, itemstack );
}
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return i == 0;
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( slot == 0 )
{
final ItemStack is = inv.getStackInSlot( 0 );
if( !is.isEmpty() )
{
this.addPower( is.getCount() );
inv.setInventorySlotContents( 0, ItemStack.EMPTY );
}
}
}
@Override
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
{
return slotIndex == 0;
}
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
return slotIndex != 0;
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing side )
{
return this.sides;
// nothing
}
@Override
@@ -266,11 +205,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
@Override
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return true;
}
else if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
return true;
}
@@ -287,7 +222,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
{
return (T) this.itemHandler;
return (T) inputSlot;
}
else if( capability == CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY )
{
@@ -300,7 +235,7 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
return super.getCapability( capability, facing );
}
private class ItemHandler implements IItemHandler
private class CondenseItemHandler implements IItemHandler
{
@Override
@@ -417,11 +352,4 @@ public class TileCondenser extends AEBaseInvTile implements IConfigManagerHost,
return this.fluidInventory;
}
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
+102 -250
View File
@@ -30,15 +30,13 @@ import com.google.common.collect.Lists;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import net.minecraftforge.items.IItemHandlerModifiable;
import appeng.api.AEApi;
import appeng.api.config.Actionable;
@@ -68,13 +66,13 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkPowerTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.InventoryAdaptor;
import appeng.util.Platform;
import appeng.util.inv.AdaptorIInventory;
import appeng.util.inv.WrapperInventoryRange;
import appeng.util.inv.InvOperation;
import appeng.util.inv.WrapperChainedItemHandler;
import appeng.util.inv.WrapperFilteredItemHandler;
import appeng.util.inv.filter.IAEItemFilter;
import appeng.util.item.AEItemStack;
@@ -86,17 +84,8 @@ import appeng.util.item.AEItemStack;
*/
public class TileInscriber extends AENetworkPowerTile implements IGridTickable, IUpgradeableHost, IConfigManagerHost
{
private static final int SLOT_TOP = 0;
private static final int SLOT_BOTTOM = 1;
private static final int SLOT_MIDDLE = 2;
private static final int SLOT_OUT = 3;
private final int maxProcessingTime = 100;
private final int[] top = { SLOT_TOP };
private final int[] bottom = { SLOT_BOTTOM };
private final int[] sides = { SLOT_MIDDLE, SLOT_OUT };
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 4 );
private final IConfigManager settings;
private final UpgradeInventory upgrades;
private int processingTime = 0;
@@ -104,9 +93,12 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
private boolean smash;
private int finalStep;
private long clientStart;
private final IItemHandler topItemHandler = new ItemHandler( 0, 0 );
private final IItemHandler bottomItemHandler = new ItemHandler( 1, 1 );
private final IItemHandler sideItemHandler = new ItemHandler( 2, 3 );
private final AppEngInternalInventory topItemHandler = new AppEngInternalInventory( this, 1, 1 );
private final AppEngInternalInventory bottomItemHandler = new AppEngInternalInventory( this, 1, 1 );
private final AppEngInternalInventory sideItemHandler = new AppEngInternalInventory( this, 2, 1 );
private final IItemHandler sideItemHandlerExtern;
private final IItemHandlerModifiable inv = new WrapperChainedItemHandler( topItemHandler, bottomItemHandler, sideItemHandler );
@Reflected
public TileInscriber()
@@ -118,6 +110,12 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
final ITileDefinition inscriberDefinition = AEApi.instance().definitions().blocks().inscriber();
this.upgrades = new DefinitionUpgradeInventory( inscriberDefinition, this, this.getUpgradeSlots() );
final IAEItemFilter filter = new ItemHandlerFilter();
topItemHandler.setFilter( filter );
bottomItemHandler.setFilter( filter );
sideItemHandlerExtern = new WrapperFilteredItemHandler( sideItemHandler, filter );
}
private int getUpgradeSlots()
@@ -134,7 +132,9 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
@TileEvent( TileEventType.WORLD_NBT_WRITE )
public void writeToNBT_TileInscriber( final NBTTagCompound data )
{
this.inv.writeToNBT( data, "inscriberInv" );
this.topItemHandler.writeToNBT( data, "inscriberInvTop" );
this.bottomItemHandler.writeToNBT( data, "inscriberInvBottom" );
this.sideItemHandler.writeToNBT( data, "inscriberInvSided" );
this.upgrades.writeToNBT( data, "upgrades" );
this.settings.writeToNBT( data );
}
@@ -142,7 +142,9 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
@TileEvent( TileEventType.WORLD_NBT_READ )
public void readFromNBT_TileInscriber( final NBTTagCompound data )
{
this.inv.readFromNBT( data, "inscriberInv" );
this.topItemHandler.readFromNBT( data, "inscriberInvTop" );
this.bottomItemHandler.readFromNBT( data, "inscriberInvBottom" );
this.sideItemHandler.readFromNBT( data, "inscriberInvSided" );
this.upgrades.readFromNBT( data, "upgrades" );
this.settings.readFromNBT( data );
}
@@ -161,15 +163,15 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
this.setClientStart( System.currentTimeMillis() );
}
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
for( int num = 0; num < this.inv.getSlots(); num++ )
{
if( ( slot & ( 1 << num ) ) > 0 )
{
this.inv.setInventorySlotContents( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
this.inv.setStackInSlot( num, AEItemStack.loadItemStackFromPacket( data ).getItemStack() );
}
else
{
this.inv.setInventorySlotContents( num, ItemStack.EMPTY );
this.inv.setStackInSlot( num, ItemStack.EMPTY );
}
}
@@ -181,7 +183,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
{
int slot = this.isSmash() ? 64 : 0;
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
for( int num = 0; num < this.inv.getSlots(); num++ )
{
if( !this.inv.getStackInSlot( num ).isEmpty() )
{
@@ -190,7 +192,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
data.writeByte( slot );
for( int num = 0; num < this.inv.getSizeInventory(); num++ )
for( int num = 0; num < this.inv.getSlots(); num++ )
{
if( ( slot & ( 1 << num ) ) > 0 )
{
@@ -213,7 +215,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
{
super.getDrops( w, pos, drops );
for( int h = 0; h < this.upgrades.getSizeInventory(); h++ )
for( int h = 0; h < this.upgrades.getSlots(); h++ )
{
final ItemStack is = this.upgrades.getStackInSlot( h );
if( !is.isEmpty() )
@@ -230,112 +232,36 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.inv;
return inv;
}
@Override
public int getInventoryStackLimit()
{
return 1;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
if( this.isSmash() )
{
return false;
}
if( i == SLOT_TOP || i == SLOT_BOTTOM )
{
if( AEApi.instance().definitions().materials().namePress().isSameAs( itemstack ) )
{
return true;
}
for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() )
{
if( Platform.itemComparisons().isSameItem( optionals, itemstack ) )
{
return true;
}
}
}
return i == SLOT_MIDDLE;
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
try
{
if( mc != InvOperation.markDirty )
if( slot == 0 )
{
if( slot != SLOT_OUT )
{
this.setProcessingTime( 0 );
}
if( !this.isSmash() )
{
this.markForUpdate();
}
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
this.setProcessingTime( 0 );
}
if( !this.isSmash() )
{
this.markForUpdate();
}
this.getProxy().getTick().wakeDevice( this.getProxy().getNode() );
}
catch( final GridAccessException e )
{
// :P
}
}
//
// @Override
// public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
// {
// if( !this.isItemValidForSlot( slotIndex, insertingItem ) )
// {
// return false;
// }
// if( !getStackInSlot( slotIndex ).isEmpty() )
// {
// return false;
// }
// return true;
// }
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
if( this.isSmash() )
{
return false;
}
return slotIndex == SLOT_TOP || slotIndex == SLOT_BOTTOM || slotIndex == SLOT_OUT;
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing d )
{
if( d == EnumFacing.UP )
{
return this.top;
}
if( d == EnumFacing.DOWN )
{
return this.bottom;
}
return this.sides;
}
@Override
public TickingRequest getTickingRequest( final IGridNode node )
{
return new TickingRequest( TickRates.Inscriber.getMin(), TickRates.Inscriber.getMax(), !this.hasWork(), false );
@@ -355,9 +281,9 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
@Nullable
public IInscriberRecipe getTask()
{
final ItemStack plateA = this.getStackInSlot( 0 );
final ItemStack plateB = this.getStackInSlot( 1 );
ItemStack renamedItem = this.getStackInSlot( 2 );
final ItemStack plateA = this.topItemHandler.getStackInSlot( 0 );
final ItemStack plateB = this.bottomItemHandler.getStackInSlot( 0 );
ItemStack renamedItem = this.sideItemHandler.getStackInSlot( 0 );
if( !plateA.isEmpty() && plateA.getCount() > 1 )
{
@@ -434,19 +360,19 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
final boolean matchA = ( plateA.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateA,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( plateB.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateB,
( plateB.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateB,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
final boolean matchB = ( plateB.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateB,
recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and...
( plateA.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( plateA,
( plateA.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( plateA,
recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) );
if( matchA || matchB )
{
for( final ItemStack option : recipe.getInputs() )
{
if( Platform.itemComparisons().isSameItem( option, this.getStackInSlot( 2 ) ) )
if( Platform.itemComparisons().isSameItem( option, this.sideItemHandler.getStackInSlot( 0 ) ) )
{
return recipe;
}
@@ -468,17 +394,16 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
if( out != null )
{
final ItemStack outputCopy = out.getOutput().copy();
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, SLOT_OUT, 1, true ), EnumFacing.UP );
if( ad.addItems( outputCopy ).isEmpty() )
if( this.sideItemHandler.insertItem( 1, outputCopy, false ).isEmpty() )
{
this.setProcessingTime( 0 );
if( out.getProcessType() == InscriberProcessType.PRESS )
{
this.setInventorySlotContents( SLOT_TOP, ItemStack.EMPTY );
this.setInventorySlotContents( SLOT_BOTTOM, ItemStack.EMPTY );
this.topItemHandler.setStackInSlot( 0, ItemStack.EMPTY );
this.bottomItemHandler.setStackInSlot( 0, ItemStack.EMPTY );
}
this.setInventorySlotContents( SLOT_MIDDLE, ItemStack.EMPTY );
this.sideItemHandler.setStackInSlot( 0, ItemStack.EMPTY );
}
}
@@ -536,8 +461,7 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
if( out != null )
{
final ItemStack outputCopy = out.getOutput().copy();
final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this.inv, SLOT_OUT, 1, true ), EnumFacing.UP );
if( ad.simulateAdd( outputCopy ).isEmpty() )
if( sideItemHandler.insertItem( 1, outputCopy, true ).isEmpty() )
{
this.setSmash( true );
this.finalStep = 0;
@@ -557,11 +481,11 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
if( name.equals( "inv" ) )
{
return this.inv;
return this.getInternalInventory();
}
if( name.equals( "upgrades" ) )
@@ -573,37 +497,20 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
}
@Override
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
protected IItemHandler getItemHandlerForSide( @Nonnull EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
if( facing == getUp() )
{
return true;
return topItemHandler;
}
return super.hasCapability( capability, facing );
}
@SuppressWarnings( "unchecked" )
@Override
public <T> T getCapability( Capability<T> capability, @Nullable EnumFacing facing )
{
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
else if( facing == getUp().getOpposite() )
{
if( facing == this.getUp() )
{
return (T) this.topItemHandler;
}
else if( facing == this.getUp().getOpposite() )
{
return (T) this.bottomItemHandler;
}
else
{
return (T) this.sideItemHandler;
}
return bottomItemHandler;
}
else
{
return sideItemHandlerExtern;
}
return super.getCapability( capability, facing );
}
@Override
@@ -657,104 +564,49 @@ public class TileInscriber extends AENetworkPowerTile implements IGridTickable,
* reset the progress if there's already an item in a slot. Previously, the progress of the inscriber was reset when
* another mod attempted insertion of items when there were already items in the slot.
*/
private class ItemHandler implements IItemHandler
private class ItemHandlerFilter implements IAEItemFilter
{
private final int insertSlot;
private final int extractSlot;
private ItemHandler( int insertSlot, int extractSlot )
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
this.insertSlot = insertSlot;
this.extractSlot = extractSlot;
if( TileInscriber.this.isSmash() )
{
return false;
}
return slot == 1;
}
@Override
public int getSlots()
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return this.insertSlot != this.extractSlot ? 2 : 1;
// output slot
if( slot == 1 )
{
return false;
}
if( TileInscriber.this.isSmash() )
{
return false;
}
if( inv == topItemHandler || inv == bottomItemHandler )
{
if( AEApi.instance().definitions().materials().namePress().isSameAs( stack ) )
{
return true;
}
for( final ItemStack optionals : AEApi.instance().registries().inscriber().getOptionals() )
{
if( Platform.itemComparisons().isSameItem( optionals, stack ) )
{
return true;
}
}
return false;
}
return true;
}
@Override
@Nonnull
public ItemStack getStackInSlot( int slot )
{
if( slot == 0 )
{
return TileInscriber.this.inv.getStackInSlot( this.insertSlot );
}
else if( this.insertSlot != this.extractSlot && slot == 1 )
{
return TileInscriber.this.inv.getStackInSlot( this.extractSlot );
}
return ItemStack.EMPTY;
}
@Override
@Nonnull
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
{
if( slot != 0 || stack.isEmpty() )
{
return stack;
}
// If there's already an item stack in the slot, we don't allow insertion and don't do any other checks
if( !TileInscriber.this.inv.getStackInSlot( this.insertSlot ).isEmpty() )
{
return stack;
}
AdaptorIInventory adapter = new AdaptorIInventory( new WrapperInventoryRange( TileInscriber.this, this.insertSlot, 1, true ) );
if( simulate )
{
return adapter.simulateAdd( stack );
}
else
{
return adapter.addItems( stack );
}
}
@Override
@Nonnull
public ItemStack extractItem( int slot, int amount, boolean simulate )
{
final int validExtractSlot = ( this.insertSlot == this.extractSlot ) ? 0 : 1;
if( slot != validExtractSlot || amount == 0 )
{
return ItemStack.EMPTY;
}
AdaptorIInventory adapter = new AdaptorIInventory( new WrapperInventoryRange( TileInscriber.this, this.extractSlot, 1, true ) );
if( simulate )
{
return adapter.simulateRemove( amount, ItemStack.EMPTY, null );
}
else
{
return adapter.removeItems( amount, ItemStack.EMPTY, null );
}
}
@Override
public int getSlotLimit( int slot )
{
// TODO Auto-generated method stub
return 0;
}
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
@@ -28,7 +28,6 @@ import com.google.common.collect.ImmutableSet;
import io.netty.buffer.ByteBuf;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
@@ -37,6 +36,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.config.Upgrades;
@@ -61,9 +61,9 @@ import appeng.helpers.IPriorityHost;
import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.IInventoryDestination;
import appeng.util.inv.InvOperation;
public class TileInterface extends AENetworkInvTile implements IGridTickable, IInventoryDestination, IInterfaceHost, IPriorityHost
@@ -219,7 +219,7 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
}
@Override
public IInventory getInventoryByName( final String name )
public IItemHandler getInventoryByName( final String name )
{
return this.duality.getInventoryByName( name );
}
@@ -237,23 +237,17 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.duality.getInternalInventory();
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
this.duality.onChangeInventory( inv, slot, mc, removed, added );
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing side )
{
return this.duality.getSlotsForFace( side );
}
@Override
public DualityInterface getInterfaceDuality()
{
@@ -360,11 +354,4 @@ public class TileInterface extends AENetworkInvTile implements IGridTickable, II
}
return super.getCapability( capability, facing );
}
@Override
public boolean isEmpty()
{
// TODO Auto-generated method stub
return false;
}
}
@@ -26,7 +26,6 @@ import java.util.List;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTBase;
@@ -35,6 +34,7 @@ import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.items.IItemHandler;
import appeng.api.AEApi;
import appeng.api.config.SecurityPermissions;
@@ -72,11 +72,12 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.IAEAppEngInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.ConfigManager;
import appeng.util.IConfigManagerHost;
import appeng.util.Platform;
import appeng.util.helpers.ItemHandlerUtil;
import appeng.util.inv.IAEAppEngInventory;
import appeng.util.inv.InvOperation;
import appeng.util.item.AEItemStack;
@@ -110,7 +111,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack )
{
}
@@ -118,7 +119,7 @@ public class TileSecurityStation extends AENetworkTile implements ITerminalHost,
@Override
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
{
if( !this.getConfigSlot().isEmpty() )
if( !ItemHandlerUtil.isEmpty( this.getConfigSlot() ) )
{
drops.add( this.getConfigSlot().getStackInSlot( 0 ) );
}
@@ -22,11 +22,10 @@ package appeng.tile.misc;
import io.netty.buffer.ByteBuf;
import net.minecraft.init.Items;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.util.EnumFacing;
import net.minecraftforge.items.IItemHandler;
import appeng.api.config.Actionable;
import appeng.api.networking.IGridNode;
@@ -44,19 +43,18 @@ import appeng.tile.TileEvent;
import appeng.tile.events.TileEventType;
import appeng.tile.grid.AENetworkInvTile;
import appeng.tile.inventory.AppEngInternalInventory;
import appeng.tile.inventory.InvOperation;
import appeng.util.Platform;
import appeng.util.inv.InvOperation;
import appeng.util.inv.filter.IAEItemFilter;
public class TileVibrationChamber extends AENetworkInvTile implements IGridTickable
{
private static final int FUEL_SLOT_INDEX = 0;
private static final double POWER_PER_TICK = 5;
private static final int[] ACCESSIBLE_SLOTS = { FUEL_SLOT_INDEX };
private static final int MAX_BURN_SPEED = 200;
private static final double DILATION_SCALING = 100.0;
private static final int MIN_BURN_SPEED = 20;
private final IInventory inv = new AppEngInternalInventory( this, 1 );
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
private int burnSpeed = 100;
private double burnTime = 0;
@@ -67,6 +65,7 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
public TileVibrationChamber()
{
this.inv.setFilter( new FuelSlotFilter() );
this.getProxy().setIdlePowerUsage( 0 );
this.getProxy().setFlags();
}
@@ -112,19 +111,13 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
}
@Override
public IInventory getInternalInventory()
public IItemHandler getInternalInventory()
{
return this.inv;
}
@Override
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
{
return TileEntityFurnace.getItemBurnTime( itemstack ) > 0;
}
@Override
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
{
if( this.getBurnTime() <= 0 )
{
@@ -142,21 +135,9 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
}
}
@Override
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
{
return extractedItem.getItem() == Items.BUCKET;
}
@Override
public int[] getAccessibleSlotsBySide( final EnumFacing side )
{
return ACCESSIBLE_SLOTS;
}
private boolean canEatFuel()
{
final ItemStack is = this.getStackInSlot( FUEL_SLOT_INDEX );
final ItemStack is = this.inv.getStackInSlot( 0 );
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
@@ -243,7 +224,7 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
private void eatFuel()
{
final ItemStack is = this.getStackInSlot( FUEL_SLOT_INDEX );
final ItemStack is = this.inv.getStackInSlot( 0 );
if( !is.isEmpty() )
{
final int newBurnTime = TileEntityFurnace.getItemBurnTime( is );
@@ -261,11 +242,11 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
container = is.getItem().getContainerItem( is );
}
this.setInventorySlotContents( 0, container );
this.inv.setStackInSlot( 0, container );
}
else
{
this.setInventorySlotContents( 0, is );
this.inv.setStackInSlot( 0, is );
}
this.markDirty();
@@ -327,10 +308,18 @@ public class TileVibrationChamber extends AENetworkInvTile implements IGridTicka
this.burnTime = burnTime;
}
@Override
public boolean isEmpty()
private class FuelSlotFilter implements IAEItemFilter
{
// TODO Auto-generated method stub
return false;
@Override
public boolean allowExtract( IItemHandler inv, int slot, int amount )
{
return inv.getStackInSlot( slot ).getItem() == Items.BUCKET;
}
@Override
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
{
return TileEntityFurnace.getItemBurnTime( stack ) > 0;
}
}
}