Use IItemHandler instead of IInventory internally (#2971)
* Use IItemHandler instead of IInventory internally
This commit is contained in:
@@ -19,223 +19,119 @@
|
||||
package appeng.tile;
|
||||
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.ISidedInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraft.util.text.TextComponentString;
|
||||
import net.minecraft.util.text.TextComponentTranslation;
|
||||
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.wrapper.InvWrapper;
|
||||
import net.minecraftforge.items.wrapper.SidedInvWrapper;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.tile.events.TileEventType;
|
||||
import appeng.tile.inventory.IAEAppEngInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
|
||||
public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventory, IAEAppEngInventory
|
||||
public abstract class AEBaseInvTile extends AEBaseTile implements IAEAppEngInventory
|
||||
{
|
||||
|
||||
private EnumMap<EnumFacing, IItemHandler> sidedItemHandler = new EnumMap<>( EnumFacing.class );
|
||||
|
||||
private IItemHandler itemHandler;
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return this.getCustomInventoryName();
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_READ )
|
||||
public void readFromNBT_AEBaseInvTile( final net.minecraft.nbt.NBTTagCompound data )
|
||||
{
|
||||
final IInventory inv = this.getInternalInventory();
|
||||
final NBTTagCompound opt = data.getCompoundTag( "inv" );
|
||||
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
final IItemHandler inv = this.getInternalInventory();
|
||||
if( inv != EmptyHandler.INSTANCE )
|
||||
{
|
||||
final NBTTagCompound item = opt.getCompoundTag( "item" + x );
|
||||
inv.setInventorySlotContents( x, new ItemStack( item ) );
|
||||
final NBTTagCompound opt = data.getCompoundTag( "inv" );
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
final NBTTagCompound item = opt.getCompoundTag( "item" + x );
|
||||
ItemHandlerUtil.setStackInSlot( inv, x, new ItemStack( item ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public abstract IInventory getInternalInventory();
|
||||
public abstract @Nonnull IItemHandler getInternalInventory();
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_AEBaseInvTile( final net.minecraft.nbt.NBTTagCompound data )
|
||||
{
|
||||
final IInventory inv = this.getInternalInventory();
|
||||
final NBTTagCompound opt = new NBTTagCompound();
|
||||
for( int x = 0; x < inv.getSizeInventory(); x++ )
|
||||
final IItemHandler inv = this.getInternalInventory();
|
||||
if( inv != EmptyHandler.INSTANCE )
|
||||
{
|
||||
final NBTTagCompound item = new NBTTagCompound();
|
||||
final ItemStack is = this.getStackInSlot( x );
|
||||
final NBTTagCompound opt = new NBTTagCompound();
|
||||
for( int x = 0; x < inv.getSlots(); x++ )
|
||||
{
|
||||
final NBTTagCompound item = new NBTTagCompound();
|
||||
final ItemStack is = inv.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
is.writeToNBT( item );
|
||||
}
|
||||
opt.setTag( "item" + x, item );
|
||||
}
|
||||
data.setTag( "inv", opt );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
|
||||
{
|
||||
final IItemHandler inv = getInternalInventory();
|
||||
|
||||
for( int l = 0; l < inv.getSlots(); l++ )
|
||||
{
|
||||
final ItemStack is = inv.getStackInSlot( l );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
is.writeToNBT( item );
|
||||
drops.add( is );
|
||||
}
|
||||
opt.setTag( "item" + x, item );
|
||||
}
|
||||
data.setTag( "inv", opt );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.getInternalInventory().getSizeInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int i )
|
||||
{
|
||||
return this.getInternalInventory().getStackInSlot( i );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int i, final int j )
|
||||
{
|
||||
return this.getInternalInventory().decrStackSize( i, j );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int i )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int i, @Nullable final ItemStack itemstack )
|
||||
{
|
||||
this.getInternalInventory().setInventorySlotContents( i, itemstack );
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if the inventory is named
|
||||
*/
|
||||
@Override
|
||||
public boolean hasCustomInventoryName()
|
||||
{
|
||||
return super.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return this.hasCustomInventoryName();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 64;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer p )
|
||||
{
|
||||
final double squaredMCReach = 64.0D;
|
||||
|
||||
return this.world.getTileEntity( this.pos ) == this && p.getDistanceSq( this.pos.getX() + 0.5D, this.pos.getY() + 0.5D,
|
||||
this.pos.getZ() + 0.5D ) <= squaredMCReach;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
;
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public abstract void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
|
||||
|
||||
@Override
|
||||
public int[] getSlotsForFace( final EnumFacing side )
|
||||
{
|
||||
final Block blk = this.world.getBlockState( this.pos ).getBlock();
|
||||
if( blk instanceof AEBaseBlock )
|
||||
{
|
||||
return this.getAccessibleSlotsBySide( ( (AEBaseBlock) blk ).mapRotation( this, side ) );
|
||||
}
|
||||
return this.getAccessibleSlotsBySide( side );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
|
||||
{
|
||||
return this.isItemValidForSlot( slotIndex, insertingItem );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
this.getInternalInventory().clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
public abstract void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removed, ItemStack added );
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
if( this.hasCustomName() )
|
||||
if( this.hasCustomInventoryName() )
|
||||
{
|
||||
return new TextComponentString( this.getCustomInventoryName() );
|
||||
}
|
||||
return new TextComponentTranslation( this.getBlockType().getUnlocalizedName() );
|
||||
}
|
||||
|
||||
public abstract int[] getAccessibleSlotsBySide( EnumFacing whichSide );
|
||||
protected @Nonnull IItemHandler getItemHandlerForSide( @Nonnull EnumFacing side )
|
||||
{
|
||||
return getInternalInventory();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCapability( Capability<?> capability, EnumFacing facing )
|
||||
{
|
||||
return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY || super.hasCapability( capability, facing );
|
||||
if( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY )
|
||||
{
|
||||
if( facing == null )
|
||||
{
|
||||
return getInternalInventory() != EmptyHandler.INSTANCE;
|
||||
}
|
||||
else
|
||||
{
|
||||
return getItemHandlerForSide( facing ) != EmptyHandler.INSTANCE;
|
||||
}
|
||||
}
|
||||
return super.hasCapability( capability, facing );
|
||||
}
|
||||
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@@ -246,15 +142,11 @@ public abstract class AEBaseInvTile extends AEBaseTile implements ISidedInventor
|
||||
{
|
||||
if( facing == null )
|
||||
{
|
||||
if( this.itemHandler == null )
|
||||
{
|
||||
this.itemHandler = new InvWrapper( this.getInternalInventory() );
|
||||
}
|
||||
return (T) this.itemHandler;
|
||||
return (T) getInternalInventory();
|
||||
}
|
||||
else
|
||||
{
|
||||
return (T) this.sidedItemHandler.computeIfAbsent( facing, side -> new SidedInvWrapper( this, side ) );
|
||||
return (T) getItemHandlerForSide( facing );
|
||||
}
|
||||
}
|
||||
return super.getCapability( capability, facing );
|
||||
|
||||
@@ -36,7 +36,6 @@ import io.netty.buffer.Unpooled;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.NetworkManager;
|
||||
@@ -45,6 +44,7 @@ import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.implementations.tiles.ISegmentedInventory;
|
||||
import appeng.api.util.ICommonTile;
|
||||
@@ -508,15 +508,15 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
|
||||
if( this instanceof ISegmentedInventory )
|
||||
{
|
||||
final IInventory inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
|
||||
final IItemHandler inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
|
||||
if( inv instanceof AppEngInternalAEInventory )
|
||||
{
|
||||
final AppEngInternalAEInventory target = (AppEngInternalAEInventory) inv;
|
||||
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSizeInventory() );
|
||||
final AppEngInternalAEInventory tmp = new AppEngInternalAEInventory( null, target.getSlots() );
|
||||
tmp.readFromNBT( compound, "config" );
|
||||
for( int x = 0; x < tmp.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < tmp.getSlots(); x++ )
|
||||
{
|
||||
target.setInventorySlotContents( x, tmp.getStackInSlot( x ) );
|
||||
target.setStackInSlot( x, tmp.getStackInSlot( x ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -534,19 +534,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
@Override
|
||||
public void getDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
|
||||
{
|
||||
if( this instanceof IInventory )
|
||||
{
|
||||
final IInventory inv = (IInventory) this;
|
||||
|
||||
for( int l = 0; l < inv.getSizeInventory(); l++ )
|
||||
{
|
||||
final ItemStack is = inv.getStackInSlot( l );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
drops.add( is );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getNoDrops( final World w, final BlockPos pos, final List<ItemStack> drops )
|
||||
@@ -594,7 +582,7 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
|
||||
if( this instanceof ISegmentedInventory )
|
||||
{
|
||||
final IInventory inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
|
||||
final IItemHandler inv = ( (ISegmentedInventory) this ).getInventoryByName( "config" );
|
||||
if( inv instanceof AppEngInternalAEInventory )
|
||||
{
|
||||
( (AppEngInternalAEInventory) inv ).writeToNBT( output, "config" );
|
||||
|
||||
@@ -24,7 +24,6 @@ import java.util.List;
|
||||
|
||||
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;
|
||||
@@ -35,6 +34,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraftforge.fml.common.FMLCommonHandler;
|
||||
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -69,20 +69,23 @@ 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.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperChainedItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import appeng.util.item.AEItemStack;
|
||||
|
||||
|
||||
public class TileMolecularAssembler extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable, ICraftingMachine, IPowerChannelState
|
||||
{
|
||||
private static final int[] SIDES = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
private final InventoryCrafting craftingInv;
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 + 2 );
|
||||
private final AppEngInternalInventory gridInv = new AppEngInternalInventory( this, 9 + 1, 1, new CraftingGridFilter() );
|
||||
private final AppEngInternalInventory patternInv = new AppEngInternalInventory( this, 1, 1 );
|
||||
private final IItemHandler internalInv = new WrapperChainedItemHandler( gridInv, patternInv );
|
||||
private final IConfigManager settings;
|
||||
private final UpgradeInventory upgrades;
|
||||
private boolean isPowered = false;
|
||||
@@ -100,10 +103,10 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
this.settings = new ConfigManager( this );
|
||||
this.settings.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.inv.setMaxStackSize( 1 );
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
this.upgrades = new DefinitionUpgradeInventory( assembler, this, this.getUpgradeSlots() );
|
||||
this.craftingInv = new InventoryCrafting( new ContainerNull(), 3, 3 );
|
||||
|
||||
}
|
||||
|
||||
private int getUpgradeSlots()
|
||||
@@ -116,11 +119,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
if( this.myPattern.isEmpty() )
|
||||
{
|
||||
boolean isEmpty = true;
|
||||
for( int x = 0; x < this.inv.getSizeInventory(); x++ )
|
||||
{
|
||||
isEmpty = this.inv.getStackInSlot( x ).isEmpty() && isEmpty;
|
||||
}
|
||||
boolean isEmpty = ItemHandlerUtil.isEmpty( gridInv ) && ItemHandlerUtil.isEmpty( patternInv );
|
||||
|
||||
if( isEmpty && patternDetails.isCraftable() )
|
||||
{
|
||||
@@ -130,7 +129,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
for( int x = 0; x < table.getSizeInventory(); x++ )
|
||||
{
|
||||
this.inv.setInventorySlotContents( x, table.getStackInSlot( x ) );
|
||||
this.gridInv.setStackInSlot( x, table.getStackInSlot( x ) );
|
||||
}
|
||||
|
||||
this.updateSleepiness();
|
||||
@@ -167,7 +166,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
private boolean canPush()
|
||||
{
|
||||
return !this.inv.getStackInSlot( 9 ).isEmpty();
|
||||
return !this.gridInv.getStackInSlot( 9 ).isEmpty();
|
||||
}
|
||||
|
||||
private boolean hasMats()
|
||||
@@ -179,7 +178,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
{
|
||||
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
|
||||
this.craftingInv.setInventorySlotContents( x, this.gridInv.getStackInSlot( x ) );
|
||||
}
|
||||
|
||||
return !this.myPlan.getOutput( this.craftingInv, this.getWorld() ).isEmpty();
|
||||
@@ -188,7 +187,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
@Override
|
||||
public boolean acceptsPlans()
|
||||
{
|
||||
return this.inv.getStackInSlot( 10 ).isEmpty();
|
||||
return ItemHandlerUtil.isEmpty( this.patternInv );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,7 +226,8 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
this.upgrades.writeToNBT( data, "upgrades" );
|
||||
this.inv.writeToNBT( data, "inv" );
|
||||
this.gridInv.writeToNBT( data, "inv" );
|
||||
this.patternInv.writeToNBT( data, "pattern" );
|
||||
this.settings.writeToNBT( data );
|
||||
}
|
||||
|
||||
@@ -253,7 +253,8 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
this.inv.readFromNBT( data, "inv" );
|
||||
this.gridInv.readFromNBT( data, "inv" );
|
||||
this.patternInv.readFromNBT( data, "pattern" );
|
||||
this.settings.readFromNBT( data );
|
||||
this.recalculatePlan();
|
||||
}
|
||||
@@ -267,7 +268,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
return;
|
||||
}
|
||||
|
||||
final ItemStack is = this.inv.getStackInSlot( 10 );
|
||||
final ItemStack is = this.patternInv.getStackInSlot( 0 );
|
||||
|
||||
if( !is.isEmpty() && is.getItem() instanceof ItemEncodedPattern )
|
||||
{
|
||||
@@ -316,7 +317,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName( final String name )
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "upgrades" ) )
|
||||
{
|
||||
@@ -325,7 +326,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
if( name.equals( "mac" ) )
|
||||
{
|
||||
return this.inv;
|
||||
return this.internalInv;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -338,59 +339,26 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
return this.internalInv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
protected IItemHandler getItemHandlerForSide( EnumFacing side )
|
||||
{
|
||||
return 1;
|
||||
return gridInv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( 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 >= 9 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.hasPattern() )
|
||||
{
|
||||
return this.myPlan.isValidItemForSlot( i, itemstack, this.getWorld() );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean hasPattern()
|
||||
{
|
||||
return this.myPlan != null && !this.inv.getStackInSlot( 10 ).isEmpty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
|
||||
{
|
||||
if( inv == this.inv )
|
||||
if( inv == this.gridInv || inv == this.patternInv )
|
||||
{
|
||||
this.recalculatePlan();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
return slotIndex == 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing whichSide )
|
||||
{
|
||||
return SIDES;
|
||||
}
|
||||
|
||||
public int getCraftingProgress()
|
||||
{
|
||||
return (int) this.progress;
|
||||
@@ -401,7 +369,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
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() )
|
||||
@@ -422,12 +390,12 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
@Override
|
||||
public TickRateModulation tickingRequest( final IGridNode node, int ticksSinceLastCall )
|
||||
{
|
||||
if( !this.inv.getStackInSlot( 9 ).isEmpty() )
|
||||
if( !this.gridInv.getStackInSlot( 9 ).isEmpty() )
|
||||
{
|
||||
this.pushOut( this.inv.getStackInSlot( 9 ) );
|
||||
this.pushOut( this.gridInv.getStackInSlot( 9 ) );
|
||||
|
||||
// did it eject?
|
||||
if( this.inv.getStackInSlot( 9 ).isEmpty() )
|
||||
if( this.gridInv.getStackInSlot( 9 ).isEmpty() )
|
||||
{
|
||||
this.markDirty();
|
||||
}
|
||||
@@ -482,7 +450,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
{
|
||||
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
{
|
||||
this.craftingInv.setInventorySlotContents( x, this.inv.getStackInSlot( x ) );
|
||||
this.craftingInv.setInventorySlotContents( x, this.gridInv.getStackInSlot( x ) );
|
||||
}
|
||||
|
||||
this.progress = 0;
|
||||
@@ -495,10 +463,10 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
for( int x = 0; x < this.craftingInv.getSizeInventory(); x++ )
|
||||
{
|
||||
this.inv.setInventorySlotContents( x, Platform.getContainerItem( this.craftingInv.getStackInSlot( x ) ) );
|
||||
this.gridInv.setStackInSlot( x, Platform.getContainerItem( this.craftingInv.getStackInSlot( x ) ) );
|
||||
}
|
||||
|
||||
if( this.inv.getStackInSlot( 10 ).isEmpty() )
|
||||
if( ItemHandlerUtil.isEmpty( this.patternInv ) )
|
||||
{
|
||||
this.forcePlan = false;
|
||||
this.myPlan = null;
|
||||
@@ -529,17 +497,17 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
|
||||
private void ejectHeldItems()
|
||||
{
|
||||
if( this.inv.getStackInSlot( 9 ).isEmpty() )
|
||||
if( this.gridInv.getStackInSlot( 9 ).isEmpty() )
|
||||
{
|
||||
for( int x = 0; x < 9; x++ )
|
||||
{
|
||||
final ItemStack is = this.inv.getStackInSlot( x );
|
||||
final ItemStack is = this.gridInv.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
if( this.myPlan == null || !this.myPlan.isValidItemForSlot( x, is, this.world ) )
|
||||
{
|
||||
this.inv.setInventorySlotContents( 9, is );
|
||||
this.inv.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
this.gridInv.setStackInSlot( 9, is );
|
||||
this.gridInv.setStackInSlot( x, ItemStack.EMPTY );
|
||||
this.markDirty();
|
||||
return;
|
||||
}
|
||||
@@ -581,7 +549,7 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
this.recalculatePlan();
|
||||
}
|
||||
|
||||
this.inv.setInventorySlotContents( 9, output );
|
||||
this.gridInv.setStackInSlot( 9, output );
|
||||
}
|
||||
|
||||
private ItemStack pushTo( ItemStack output, final EnumFacing d )
|
||||
@@ -655,11 +623,32 @@ public class TileMolecularAssembler extends AENetworkInvTile implements IUpgrade
|
||||
return this.isPowered;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
private class CraftingGridFilter implements IAEItemFilter
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
private boolean hasPattern()
|
||||
{
|
||||
return TileMolecularAssembler.this.myPlan != null && !ItemHandlerUtil.isEmpty( TileMolecularAssembler.this.patternInv );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return slot == 9;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
if( slot >= 9 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( hasPattern() )
|
||||
{
|
||||
return TileMolecularAssembler.this.myPlan.isValidItemForSlot( slot, stack, TileMolecularAssembler.this.getWorld() );
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,17 +99,4 @@ public abstract class AENetworkInvTile extends AEBaseInvTile implements IActionH
|
||||
{
|
||||
return this.getProxy().getNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,27 +23,28 @@ import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.RangedWrapper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.features.IGrinderRecipe;
|
||||
import appeng.api.implementations.tiles.ICrankable;
|
||||
import appeng.tile.AEBaseInvTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperInventoryRange;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperFilteredItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
{
|
||||
|
||||
private final int[] inputs = { 0, 1, 2 };
|
||||
private final int[] sides = { 0, 1, 2, 3, 4, 5 };
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 7 );
|
||||
private final IItemHandler invExt = new WrapperFilteredItemHandler( inv, new GrinderFilter() );
|
||||
private int points;
|
||||
|
||||
@Override
|
||||
@@ -55,38 +56,21 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
|
||||
protected IItemHandler getItemHandlerForSide( EnumFacing side )
|
||||
{
|
||||
|
||||
return this.invExt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
|
||||
public void onChangeInventory( final IItemHandler inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
|
||||
{
|
||||
if( AEApi.instance().registries().grinder().getRecipeForInput( insertingItem ) == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return slotIndex >= 0 && slotIndex <= 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
return slotIndex >= 3 && slotIndex <= 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -97,12 +81,11 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
return false;
|
||||
}
|
||||
|
||||
if( this.getStackInSlot( 6 ).isEmpty() ) // Add if there isn't one...
|
||||
if( this.inv.getStackInSlot( 6 ).isEmpty() ) // Add if there isn't one...
|
||||
{
|
||||
final IInventory src = new WrapperInventoryRange( this, this.inputs, true );
|
||||
for( int x = 0; x < src.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < 3; x++ )
|
||||
{
|
||||
ItemStack item = src.getStackInSlot( x );
|
||||
ItemStack item = inv.getStackInSlot( x );
|
||||
if( item.isEmpty() )
|
||||
{
|
||||
continue;
|
||||
@@ -122,8 +105,8 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
item = ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
src.setInventorySlotContents( x, item );
|
||||
this.setInventorySlotContents( 6, ais );
|
||||
inv.setStackInSlot( x, item );
|
||||
inv.setStackInSlot( 6, ais );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -143,7 +126,7 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
|
||||
this.points++;
|
||||
|
||||
final ItemStack processing = this.getStackInSlot( 6 );
|
||||
final ItemStack processing = inv.getStackInSlot( 6 );
|
||||
final IGrinderRecipe r = AEApi.instance().registries().grinder().getRecipeForInput( processing );
|
||||
if( r != null )
|
||||
{
|
||||
@@ -153,7 +136,7 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
}
|
||||
|
||||
this.points = 0;
|
||||
final InventoryAdaptor sia = InventoryAdaptor.getAdaptor( new WrapperInventoryRange( this, 3, 3, true ), EnumFacing.EAST );
|
||||
final InventoryAdaptor sia = new AdaptorItemHandler( new RangedWrapper( inv, 3, 6 ) );
|
||||
|
||||
this.addItem( sia, r.getOutput() );
|
||||
|
||||
@@ -177,7 +160,7 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
}
|
||||
} );
|
||||
|
||||
this.setInventorySlotContents( 6, ItemStack.EMPTY );
|
||||
inv.setStackInSlot( 6, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,10 +187,24 @@ public class TileGrinder extends AEBaseInvTile implements ICrankable
|
||||
return this.getUp() == directionToCrank;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
private class GrinderFilter implements IAEItemFilter
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slotIndex, int amount )
|
||||
{
|
||||
return slotIndex >= 3 && slotIndex <= 5;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slotIndex, ItemStack stack )
|
||||
{
|
||||
if( AEApi.instance().registries().grinder().getRecipeForInput( stack ) == null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return slotIndex >= 0 && slotIndex <= 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,24 +21,26 @@ package appeng.tile.inventory;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInternalItemHandler;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.item.AEItemStack;
|
||||
import appeng.util.iterators.AEInvIterator;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
|
||||
|
||||
public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack>
|
||||
public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable<ItemStack>
|
||||
{
|
||||
|
||||
private final IAEAppEngInventory te;
|
||||
private final IAEItemStack[] inv;
|
||||
private final int size;
|
||||
@@ -52,19 +54,6 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
||||
this.inv = new IAEItemStack[s];
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
if( !this.getStackInSlot( x ).isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setMaxStackSize( final int s )
|
||||
{
|
||||
this.maxStack = s;
|
||||
@@ -132,8 +121,13 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
||||
}
|
||||
}
|
||||
|
||||
protected int getStackLimit( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
return Math.min( getSlotLimit( slot ), stack.getMaxStackSize() );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
public int getSlots()
|
||||
{
|
||||
return this.size;
|
||||
}
|
||||
@@ -150,42 +144,79 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int slot, final int qty )
|
||||
public ItemStack insertItem( int slot, ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( stack.isEmpty() )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
ItemStack existing = getStackInSlot( slot );
|
||||
int limit = getStackLimit( slot, stack );
|
||||
|
||||
if( !existing.isEmpty() )
|
||||
{
|
||||
if( !ItemHandlerHelper.canItemStacksStack( stack, existing ) )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
limit -= existing.getCount();
|
||||
}
|
||||
|
||||
if( limit <= 0 )
|
||||
{
|
||||
return stack;
|
||||
}
|
||||
|
||||
boolean reachedLimit = stack.getCount() > limit;
|
||||
|
||||
if( !simulate )
|
||||
{
|
||||
if( existing.isEmpty() )
|
||||
{
|
||||
this.inv[slot] = AEApi.instance().storage().createItemStack( reachedLimit ? ItemHandlerHelper.copyStackWithSize( stack, limit ) : stack );
|
||||
}
|
||||
else
|
||||
{
|
||||
existing.grow( reachedLimit ? limit : stack.getCount() );
|
||||
}
|
||||
fireOnChangeInventory( slot, InvOperation.INSERT, ItemStack.EMPTY, reachedLimit ? ItemHandlerHelper.copyStackWithSize( stack, limit ) : stack );
|
||||
}
|
||||
return reachedLimit ? ItemHandlerHelper.copyStackWithSize( stack, stack.getCount() - limit ) : ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( this.inv[slot] != null )
|
||||
{
|
||||
final ItemStack split = this.getStackInSlot( slot );
|
||||
ItemStack ns = ItemStack.EMPTY;
|
||||
|
||||
if( qty >= split.getCount() )
|
||||
if( amount >= split.getCount() )
|
||||
{
|
||||
ns = this.getStackInSlot( slot );
|
||||
this.inv[slot] = null;
|
||||
if( !simulate )
|
||||
{
|
||||
this.inv[slot] = null;
|
||||
fireOnChangeInventory( slot, InvOperation.EXTRACT, split, ItemStack.EMPTY );
|
||||
}
|
||||
return split;
|
||||
}
|
||||
else
|
||||
{
|
||||
ns = split.splitStack( qty );
|
||||
if( !simulate )
|
||||
{
|
||||
split.grow( -amount );
|
||||
fireOnChangeInventory( slot, InvOperation.EXTRACT, ItemHandlerHelper.copyStackWithSize( split, amount ), ItemStack.EMPTY );
|
||||
}
|
||||
return ItemHandlerHelper.copyStackWithSize( split, amount );
|
||||
}
|
||||
|
||||
if( this.te != null && Platform.isServer() )
|
||||
{
|
||||
this.te.onChangeInventory( this, slot, InvOperation.decreaseStackSize, ns, ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
return ns;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int var1 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int slot, final ItemStack newItemStack )
|
||||
public void setStackInSlot( final int slot, final ItemStack newItemStack )
|
||||
{
|
||||
final ItemStack oldStack = this.getStackInSlot( slot );
|
||||
this.inv[slot] = AEApi.instance().storage().createItemStack( newItemStack );
|
||||
@@ -214,48 +245,22 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
||||
removed = added = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
this.te.onChangeInventory( this, slot, InvOperation.setInventorySlotContents, removed, added );
|
||||
fireOnChangeInventory( slot, InvOperation.SET, removed, added );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "appeng-internal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
private void fireOnChangeInventory( int slot, InvOperation op, ItemStack removed, ItemStack inserted )
|
||||
{
|
||||
if( this.te != null && Platform.isServer() )
|
||||
{
|
||||
this.te.onChangeInventory( this, -1, InvOperation.markDirty, ItemStack.EMPTY, ItemStack.EMPTY );
|
||||
this.te.onChangeInventory( this, slot, op, removed, inserted );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -270,47 +275,14 @@ public class AppEngInternalAEInventory implements IInventory, Iterable<ItemStack
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
return null;
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
public void markDirty( int slot )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
this.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
}
|
||||
fireOnChangeInventory( slot, InvOperation.DIRTY, ItemStack.EMPTY, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,88 +19,115 @@
|
||||
package appeng.tile.inventory;
|
||||
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
|
||||
import appeng.core.AELog;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.iterators.InvIterator;
|
||||
import appeng.util.inv.IAEAppEngInventory;
|
||||
import appeng.util.inv.IInternalItemHandler;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
public class AppEngInternalInventory extends ItemStackHandler implements IInternalItemHandler, Iterable<ItemStack>
|
||||
{
|
||||
private final int size;
|
||||
private final ItemStack[] inv;
|
||||
private boolean enableClientEvents = false;
|
||||
private IAEAppEngInventory te;
|
||||
private int maxStack;
|
||||
private InvOperation currentOp;
|
||||
private ItemStack previousStack = ItemStack.EMPTY;
|
||||
private IAEItemFilter filter;
|
||||
|
||||
public AppEngInternalInventory( final IAEAppEngInventory inventory, final int size, final int maxStack, IAEItemFilter filter )
|
||||
{
|
||||
super( size );
|
||||
this.setTileEntity( inventory );
|
||||
this.setFilter( filter );
|
||||
this.maxStack = maxStack;
|
||||
}
|
||||
|
||||
public AppEngInternalInventory( final IAEAppEngInventory inventory, final int size, final int maxStack )
|
||||
{
|
||||
this( inventory, size, maxStack, null );
|
||||
}
|
||||
|
||||
public AppEngInternalInventory( final IAEAppEngInventory inventory, final int size )
|
||||
{
|
||||
this.setTileEntity( inventory );
|
||||
this.size = size;
|
||||
this.maxStack = 64;
|
||||
this.inv = new ItemStack[size];
|
||||
this( inventory, size, 64 );
|
||||
}
|
||||
|
||||
public void setFilter( IAEItemFilter filter )
|
||||
{
|
||||
this.filter = filter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
public int getSlotLimit( int slot )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
return maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setStackInSlot( int slot, @Nonnull ItemStack stack )
|
||||
{
|
||||
currentOp = InvOperation.SET;
|
||||
previousStack = getStackInSlot( slot );
|
||||
super.setStackInSlot( slot, stack );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate )
|
||||
{
|
||||
if( filter != null && !filter.allowInsert( this, slot, stack ) )
|
||||
{
|
||||
if( !this.getStackInSlot( x ).isEmpty() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return this.size;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int var1 )
|
||||
{
|
||||
return this.inv[var1] == null ? ItemStack.EMPTY : this.inv[var1];
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int slot, final int qty )
|
||||
{
|
||||
if( this.inv[slot] != null )
|
||||
{
|
||||
final ItemStack split = this.getStackInSlot( slot );
|
||||
ItemStack ns = ItemStack.EMPTY;
|
||||
|
||||
if( qty >= split.getCount() )
|
||||
{
|
||||
ns = this.inv[slot];
|
||||
this.inv[slot] = ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
ns = split.splitStack( qty );
|
||||
}
|
||||
|
||||
if( this.getTileEntity() != null && this.eventsEnabled() )
|
||||
{
|
||||
this.getTileEntity().onChangeInventory( this, slot, InvOperation.decreaseStackSize, ns, ItemStack.EMPTY );
|
||||
}
|
||||
|
||||
this.markDirty();
|
||||
return ns;
|
||||
return stack;
|
||||
}
|
||||
|
||||
return ItemStack.EMPTY;
|
||||
currentOp = InvOperation.INSERT;
|
||||
previousStack = getStackInSlot( slot ).copy();
|
||||
return super.insertItem( slot, stack, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nonnull
|
||||
public ItemStack extractItem( int slot, int amount, boolean simulate )
|
||||
{
|
||||
if( filter != null && !filter.allowExtract( this, slot, amount ) )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
currentOp = InvOperation.EXTRACT;
|
||||
previousStack = getStackInSlot( slot );
|
||||
return super.extractItem( slot, amount, simulate );
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onContentsChanged( int slot )
|
||||
{
|
||||
if( this.getTileEntity() != null && this.eventsEnabled() )
|
||||
{
|
||||
ItemStack added = getStackInSlot( slot ).copy();
|
||||
ItemStack removed = previousStack.copy();
|
||||
|
||||
if( currentOp == InvOperation.INSERT )
|
||||
{
|
||||
added.grow( -removed.getCount() );
|
||||
}
|
||||
else if( currentOp == InvOperation.EXTRACT )
|
||||
{
|
||||
removed.grow( -added.getCount() );
|
||||
}
|
||||
this.getTileEntity().onChangeInventory( this, slot, currentOp, removed, added );
|
||||
}
|
||||
super.onContentsChanged( slot );
|
||||
}
|
||||
|
||||
protected boolean eventsEnabled()
|
||||
@@ -108,138 +135,36 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
return Platform.isServer() || this.isEnableClientEvents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int var1 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
private ItemStack getOldStack( int slot )
|
||||
{
|
||||
if( this.inv[slot] == null )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
return this.inv[slot];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int slot, final ItemStack newItemStack )
|
||||
{
|
||||
final ItemStack oldStack = this.getOldStack( slot );
|
||||
this.inv[slot] = newItemStack;
|
||||
|
||||
if( this.getTileEntity() != null && this.eventsEnabled() )
|
||||
{
|
||||
ItemStack removed = oldStack;
|
||||
ItemStack added = newItemStack;
|
||||
|
||||
if( !oldStack.isEmpty() && !newItemStack.isEmpty() && Platform.itemComparisons().isEqualItem( oldStack, newItemStack ) )
|
||||
{
|
||||
if( oldStack.getCount() > newItemStack.getCount() )
|
||||
{
|
||||
removed = removed.copy();
|
||||
removed.grow( -newItemStack.getCount() );
|
||||
added = ItemStack.EMPTY;
|
||||
}
|
||||
else if( oldStack.getCount() < newItemStack.getCount() )
|
||||
{
|
||||
added = added.copy();
|
||||
added.grow( -oldStack.getCount() );
|
||||
removed = ItemStack.EMPTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
removed = added = ItemStack.EMPTY;
|
||||
}
|
||||
}
|
||||
|
||||
this.getTileEntity().onChangeInventory( this, slot, InvOperation.setInventorySlotContents, removed, added );
|
||||
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "appeng-internal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return this.maxStack > 64 ? 64 : this.maxStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
if( this.getTileEntity() != null && this.eventsEnabled() )
|
||||
{
|
||||
this.getTileEntity().onChangeInventory( this, -1, InvOperation.markDirty, ItemStack.EMPTY, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void setMaxStackSize( final int s )
|
||||
{
|
||||
this.maxStack = s;
|
||||
}
|
||||
|
||||
// for guis...
|
||||
public void markDirty( final int slotIndex )
|
||||
public void markDirty( final int slot )
|
||||
{
|
||||
if( this.getTileEntity() != null && this.eventsEnabled() )
|
||||
{
|
||||
this.getTileEntity().onChangeInventory( this, slotIndex, InvOperation.markDirty, ItemStack.EMPTY, ItemStack.EMPTY );
|
||||
this.getTileEntity().onChangeInventory( this, slot, InvOperation.DIRTY, ItemStack.EMPTY, ItemStack.EMPTY );
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( int slot, ItemStack stack )
|
||||
{
|
||||
if( this.maxStack == 0 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if( this.filter != null )
|
||||
{
|
||||
return filter.allowInsert( this, slot, stack );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void writeToNBT( final NBTTagCompound data, final String name )
|
||||
{
|
||||
final NBTTagCompound c = new NBTTagCompound();
|
||||
this.writeToNBT( c );
|
||||
data.setTag( name, c );
|
||||
}
|
||||
|
||||
private void writeToNBT( final NBTTagCompound target )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTTagCompound c = new NBTTagCompound();
|
||||
|
||||
if( this.inv[x] != null )
|
||||
{
|
||||
this.inv[x].writeToNBT( c );
|
||||
}
|
||||
|
||||
target.setTag( "#" + x, c );
|
||||
}
|
||||
catch( final Exception ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
data.setTag( name, serializeNBT() );
|
||||
}
|
||||
|
||||
public void readFromNBT( final NBTTagCompound data, final String name )
|
||||
@@ -247,78 +172,19 @@ public class AppEngInternalInventory implements IInventory, Iterable<ItemStack>
|
||||
final NBTTagCompound c = data.getCompoundTag( name );
|
||||
if( c != null )
|
||||
{
|
||||
this.readFromNBT( c );
|
||||
readFromNBT( c );
|
||||
}
|
||||
}
|
||||
|
||||
public void readFromNBT( final NBTTagCompound target )
|
||||
public void readFromNBT( final NBTTagCompound data )
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
try
|
||||
{
|
||||
final NBTTagCompound c = target.getCompoundTag( "#" + x );
|
||||
|
||||
if( c != null )
|
||||
{
|
||||
this.inv[x] = new ItemStack( c );
|
||||
}
|
||||
}
|
||||
catch( final Exception e )
|
||||
{
|
||||
AELog.debug( e );
|
||||
}
|
||||
}
|
||||
deserializeNBT( data );
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<ItemStack> iterator()
|
||||
{
|
||||
return new InvIterator( this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
for( int x = 0; x < this.size; x++ )
|
||||
{
|
||||
this.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
}
|
||||
return Collections.unmodifiableList( super.stacks ).iterator();
|
||||
}
|
||||
|
||||
private boolean isEnableClientEvents()
|
||||
|
||||
@@ -1,153 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.text.ITextComponent;
|
||||
|
||||
|
||||
public class AppEngNullInventory implements IInventory
|
||||
{
|
||||
|
||||
public AppEngNullInventory()
|
||||
{
|
||||
}
|
||||
|
||||
public void writeToNBT( final NBTTagCompound target )
|
||||
{
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getStackInSlot( final int var1 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack decrStackSize( final int slot, final int qty )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack removeStackFromSlot( final int var1 )
|
||||
{
|
||||
return ItemStack.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInventorySlotContents( final int slot, final ItemStack newItemStack )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "appeng-internal";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasCustomName()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getInventoryStackLimit()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void markDirty()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isUsableByPlayer( final EntityPlayer var1 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITextComponent getDisplayName()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getField( final int id )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setField( final int id, final int value )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getFieldCount()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
|
||||
public interface IAEAppEngInventory
|
||||
{
|
||||
|
||||
void saveChanges();
|
||||
|
||||
void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack );
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
/*
|
||||
* This file is part of Applied Energistics 2.
|
||||
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
|
||||
*
|
||||
* Applied Energistics 2 is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Applied Energistics 2 is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
|
||||
*/
|
||||
|
||||
package appeng.tile.inventory;
|
||||
|
||||
|
||||
public enum InvOperation
|
||||
{
|
||||
decreaseStackSize, setInventorySlotContents, markDirty
|
||||
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,10 +21,11 @@ package appeng.tile.networking;
|
||||
|
||||
import java.util.EnumSet;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.GridFlags;
|
||||
@@ -40,15 +41,11 @@ import appeng.block.networking.BlockController;
|
||||
import appeng.block.networking.BlockController.ControllerBlockState;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
|
||||
public class TileController extends AENetworkPowerTile
|
||||
{
|
||||
private static final IInventory NULL_INVENTORY = new AppEngInternalInventory( null, 0 );
|
||||
private static final int[] ACCESSIBLE_SLOTS_BY_SIDE = {};
|
||||
|
||||
private boolean isValid = false;
|
||||
|
||||
public TileController()
|
||||
@@ -194,21 +191,14 @@ public class TileController extends AENetworkPowerTile
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return NULL_INVENTORY;
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@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 )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing whichSide )
|
||||
{
|
||||
return ACCESSIBLE_SLOTS_BY_SIDE;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -226,11 +216,4 @@ public class TileController extends AENetworkPowerTile
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,10 +19,10 @@
|
||||
package appeng.tile.networking;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.networking.energy.IEnergyGrid;
|
||||
@@ -30,16 +30,11 @@ import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.tile.grid.AENetworkPowerTile;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.tile.inventory.InvOperation;
|
||||
import appeng.util.inv.InvOperation;
|
||||
|
||||
|
||||
public class TileEnergyAcceptor extends AENetworkPowerTile
|
||||
{
|
||||
|
||||
private static final AppEngInternalInventory INTERNAL_INVENTORY = new AppEngInternalInventory( null, 0 );
|
||||
private final int[] sides = {};
|
||||
|
||||
public TileEnergyAcceptor()
|
||||
{
|
||||
this.getProxy().setIdlePowerUsage( 0.0 );
|
||||
@@ -102,28 +97,14 @@ public class TileEnergyAcceptor extends AENetworkPowerTile
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return INTERNAL_INVENTORY;
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
|
||||
@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 )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -23,9 +23,9 @@ import java.util.EnumSet;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
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.implementations.IPowerChannelState;
|
||||
@@ -44,8 +44,9 @@ 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.AEItemDefinitionFilter;
|
||||
|
||||
|
||||
public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoint, IPowerChannelState
|
||||
@@ -54,13 +55,13 @@ public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoi
|
||||
public static final int POWERED_FLAG = 1;
|
||||
public static final int CHANNEL_FLAG = 2;
|
||||
|
||||
private final int[] sides = { 0 };
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 1 );
|
||||
|
||||
private int clientFlags = 0;
|
||||
|
||||
public TileWireless()
|
||||
{
|
||||
this.inv.setFilter( new AEItemDefinitionFilter( AEApi.instance().definitions().materials().wirelessBooster() ) );
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.getProxy().setValidSides( EnumSet.noneOf( EnumFacing.class ) );
|
||||
}
|
||||
@@ -131,29 +132,17 @@ public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoi
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return AEApi.instance().definitions().materials().wirelessBooster().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 )
|
||||
{
|
||||
// :P
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReady()
|
||||
{
|
||||
@@ -223,11 +212,4 @@ public class TileWireless extends AENetworkInvTile implements IWirelessAccessPoi
|
||||
{
|
||||
this.clientFlags = clientFlags;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import javax.annotation.Nullable;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
import net.minecraftforge.energy.CapabilityEnergy;
|
||||
import net.minecraftforge.energy.IEnergyStorage;
|
||||
|
||||
import appeng.api.config.AccessRestriction;
|
||||
|
||||
@@ -25,12 +25,13 @@ import java.util.Optional;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
import net.minecraftforge.items.wrapper.EmptyHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.definitions.IBlockDefinition;
|
||||
@@ -49,15 +50,13 @@ 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;
|
||||
|
||||
|
||||
public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock, ITickable
|
||||
{
|
||||
private final byte corner = 16;
|
||||
private final int[] sidesRing = {};
|
||||
private final int[] sidesLink = { 0 };
|
||||
private final AppEngInternalInventory internalInventory = new AppEngInternalInventory( this, 1 );
|
||||
private final byte hasSingularity = 32;
|
||||
private final byte powered = 64;
|
||||
@@ -94,7 +93,7 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
{
|
||||
int out = this.constructed;
|
||||
|
||||
if( !this.getStackInSlot( 0 ).isEmpty() && this.constructed != -1 )
|
||||
if( !internalInventory.getStackInSlot( 0 ).isEmpty() && this.constructed != -1 )
|
||||
{
|
||||
out |= this.hasSingularity;
|
||||
}
|
||||
@@ -116,13 +115,13 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.internalInventory;
|
||||
}
|
||||
|
||||
@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.cluster != null )
|
||||
{
|
||||
@@ -131,13 +130,13 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
protected IItemHandler getItemHandlerForSide( EnumFacing side )
|
||||
{
|
||||
if( this.isCenter() )
|
||||
{
|
||||
return this.sidesLink;
|
||||
return this.internalInventory;
|
||||
}
|
||||
return this.sidesRing;
|
||||
return EmptyHandler.INSTANCE;
|
||||
}
|
||||
|
||||
private boolean isCenter()
|
||||
@@ -349,11 +348,4 @@ public class TileQuantumBridge extends AENetworkInvTile implements IAEMultiBlock
|
||||
{
|
||||
return this.corner;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,11 +19,10 @@
|
||||
package appeng.tile.spatial;
|
||||
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.config.Actionable;
|
||||
import appeng.api.config.PowerMultiplier;
|
||||
@@ -45,21 +44,22 @@ 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.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
|
||||
|
||||
public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallable<Void>
|
||||
{
|
||||
|
||||
private final int[] sides = { 0, 1 };
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
||||
private YesNo lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
public TileSpatialIOPort()
|
||||
{
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
inv.setFilter( new SpatialIOFilter() );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
@@ -104,7 +104,7 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
|
||||
{
|
||||
if( Platform.isServer() )
|
||||
{
|
||||
final ItemStack cell = this.getStackInSlot( 0 );
|
||||
final ItemStack cell = this.inv.getStackInSlot( 0 );
|
||||
if( this.isSpatialCell( cell ) )
|
||||
{
|
||||
TickHandler.INSTANCE.addCallable( null, this );// this needs to be cross world synced.
|
||||
@@ -125,8 +125,8 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
|
||||
@Override
|
||||
public Void call( final World world ) throws Exception
|
||||
{
|
||||
final ItemStack cell = this.getStackInSlot( 0 );
|
||||
if( this.isSpatialCell( cell ) && this.getStackInSlot( 1 ).isEmpty() )
|
||||
final ItemStack cell = this.inv.getStackInSlot( 0 );
|
||||
if( this.isSpatialCell( cell ) && this.inv.getStackInSlot( 1 ).isEmpty() )
|
||||
{
|
||||
final IGrid gi = this.getProxy().getGrid();
|
||||
final IEnergyGrid energy = this.getProxy().getEnergy();
|
||||
@@ -147,8 +147,8 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
|
||||
if( tr.success )
|
||||
{
|
||||
energy.extractAEPower( req, Actionable.MODULATE, PowerMultiplier.CONFIG );
|
||||
this.setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
this.setInventorySlotContents( 1, cell );
|
||||
this.inv.setStackInSlot( 0, ItemStack.EMPTY );
|
||||
this.inv.setStackInSlot( 1, cell );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,45 +171,30 @@ public class TileSpatialIOPort extends AENetworkInvTile implements IWorldCallabl
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return( i == 0 && this.isSpatialCell( 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 )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
|
||||
private class SpatialIOFilter implements IAEItemFilter
|
||||
{
|
||||
return this.isItemValidForSlot( slotIndex, insertingItem );
|
||||
}
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return slot == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
return slotIndex == 1;
|
||||
}
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return( slot == 0 && TileSpatialIOPort.this.isSpatialCell( stack ) );
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,12 +23,12 @@ import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
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.NBTTagCompound;
|
||||
@@ -40,6 +40,7 @@ import net.minecraftforge.fluids.capability.CapabilityFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.FluidTankProperties;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fluids.capability.IFluidTankProperties;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.AccessRestriction;
|
||||
@@ -92,10 +93,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.Platform;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperChainedItemHandler;
|
||||
import appeng.util.inv.filter.IAEItemFilter;
|
||||
import appeng.util.item.AEFluidStack;
|
||||
|
||||
|
||||
@@ -103,10 +107,11 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
{
|
||||
|
||||
private static final ChestNoHandler NO_HANDLER = new ChestNoHandler();
|
||||
private static final int[] SIDES = { 0 };
|
||||
private static final int[] FRONT = { 1 };
|
||||
private static final int[] NO_SLOTS = {};
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 2 );
|
||||
|
||||
private final AppEngInternalInventory inputInventory = new AppEngInternalInventory( this, 1 );
|
||||
private final AppEngInternalInventory cellInventory = new AppEngInternalInventory( this, 1 );
|
||||
private final IItemHandler internalInventory = new WrapperChainedItemHandler( inputInventory, cellInventory );
|
||||
|
||||
private final BaseActionSource mySrc = new MachineSource( this );
|
||||
private final IConfigManager config = new ConfigManager( this );
|
||||
private ItemStack storageType = ItemStack.EMPTY;
|
||||
@@ -132,6 +137,14 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
|
||||
this.setInternalPublicPowerStorage( true );
|
||||
this.setInternalPowerFlow( AccessRestriction.WRITE );
|
||||
|
||||
this.inputInventory.setFilter( new InputInventoryFilter() );
|
||||
this.cellInventory.setFilter( new CellInventoryFilter() );
|
||||
}
|
||||
|
||||
public ItemStack getCell()
|
||||
{
|
||||
return cellInventory.getStackInSlot( 0 );
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -208,7 +221,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
this.accessor = null;
|
||||
this.fluidHandler = null;
|
||||
|
||||
final ItemStack is = this.inv.getStackInSlot( 1 );
|
||||
final ItemStack is = this.cellInventory.getStackInSlot( 0 );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
this.isCached = true;
|
||||
@@ -292,7 +305,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
return ( this.state >> ( slot * 3 ) ) & 3;
|
||||
}
|
||||
|
||||
final ItemStack cell = this.inv.getStackInSlot( 1 );
|
||||
final ItemStack cell = this.cellInventory.getStackInSlot( 0 );
|
||||
final ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell );
|
||||
|
||||
if( ch != null )
|
||||
@@ -414,7 +427,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
}
|
||||
}
|
||||
|
||||
if( !this.inv.getStackInSlot( 0 ).isEmpty() )
|
||||
if( !ItemHandlerUtil.isEmpty( this.inputInventory ) )
|
||||
{
|
||||
this.tryToStoreContents();
|
||||
}
|
||||
@@ -449,7 +462,7 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
data.writeByte( this.state );
|
||||
data.writeByte( this.paintedColor.ordinal() );
|
||||
|
||||
final ItemStack is = this.inv.getStackInSlot( 1 );
|
||||
final ItemStack is = this.cellInventory.getStackInSlot( 1 );
|
||||
|
||||
if( is.isEmpty() )
|
||||
{
|
||||
@@ -532,22 +545,15 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
return this.internalInventory;
|
||||
}
|
||||
|
||||
@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 )
|
||||
{
|
||||
this.inv.setInventorySlotContents( i, itemstack );
|
||||
this.tryToStoreContents();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removed, final ItemStack added )
|
||||
{
|
||||
if( slot == 1 )
|
||||
if( inv == cellInventory )
|
||||
{
|
||||
this.itemCell = null;
|
||||
this.fluidCell = null;
|
||||
@@ -572,87 +578,44 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
this.markForUpdate();
|
||||
}
|
||||
}
|
||||
if( inv == inputInventory && mc == InvOperation.INSERT )
|
||||
{
|
||||
this.tryToStoreContents();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
|
||||
protected IItemHandler getItemHandlerForSide( @Nonnull EnumFacing side )
|
||||
{
|
||||
if( slotIndex == 1 )
|
||||
if( side == this.getForward() )
|
||||
{
|
||||
if( AEApi.instance().registries().cell().getCellInventory( insertingItem, this, StorageChannel.ITEMS ) != null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if( AEApi.instance().registries().cell().getCellInventory( insertingItem, this, StorageChannel.FLUIDS ) != null )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return cellInventory;
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
final IMEInventory<IAEItemStack> cell = this.getHandler( StorageChannel.ITEMS );
|
||||
final IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ), Actionable.SIMULATE,
|
||||
this.mySrc );
|
||||
return returns == null || returns.getStackSize() != insertingItem.getCount();
|
||||
}
|
||||
catch( final ChestNoHandler ignored )
|
||||
{
|
||||
}
|
||||
return inputInventory;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
return slotIndex == 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
if( EnumFacing.SOUTH == side )
|
||||
{
|
||||
return FRONT;
|
||||
}
|
||||
|
||||
if( this.isPowered() )
|
||||
{
|
||||
try
|
||||
{
|
||||
if( this.getHandler( StorageChannel.ITEMS ) != null )
|
||||
{
|
||||
return SIDES;
|
||||
}
|
||||
}
|
||||
catch( final ChestNoHandler e )
|
||||
{
|
||||
// nope!
|
||||
}
|
||||
}
|
||||
return NO_SLOTS;
|
||||
}
|
||||
|
||||
private void tryToStoreContents()
|
||||
{
|
||||
try
|
||||
{
|
||||
if( !this.getStackInSlot( 0 ).isEmpty() )
|
||||
if( !ItemHandlerUtil.isEmpty( this.inputInventory ) )
|
||||
{
|
||||
final IMEInventory<IAEItemStack> cell = this.getHandler( StorageChannel.ITEMS );
|
||||
|
||||
final IAEItemStack returns = Platform.poweredInsert( this, cell, AEApi.instance().storage().createItemStack( this.inv.getStackInSlot( 0 ) ),
|
||||
final IAEItemStack returns = Platform.poweredInsert( this, cell,
|
||||
AEApi.instance().storage().createItemStack( this.inputInventory.getStackInSlot( 0 ) ),
|
||||
this.mySrc );
|
||||
|
||||
if( returns == null )
|
||||
{
|
||||
this.inv.setInventorySlotContents( 0, ItemStack.EMPTY );
|
||||
this.inputInventory.setStackInSlot( 0, ItemStack.EMPTY );
|
||||
}
|
||||
else
|
||||
{
|
||||
this.inv.setInventorySlotContents( 0, returns.getItemStack() );
|
||||
this.inputInventory.setStackInSlot( 0, returns.getItemStack() );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -971,13 +934,6 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
|
||||
private class FluidHandler implements IFluidHandler
|
||||
{
|
||||
|
||||
@@ -1043,4 +999,53 @@ public class TileChest extends AENetworkPowerTile implements IMEChest, ITerminal
|
||||
}
|
||||
}
|
||||
|
||||
private class InputInventoryFilter implements IAEItemFilter
|
||||
{
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
if( isPowered() )
|
||||
{
|
||||
try
|
||||
{
|
||||
final IMEInventory<IAEItemStack> cell = getHandler( StorageChannel.ITEMS );
|
||||
if( cell != null )
|
||||
{
|
||||
final IAEItemStack returns = cell.injectItems( AEApi.instance().storage().createItemStack( stack ), Actionable.SIMULATE, mySrc );
|
||||
return returns == null || returns.getStackSize() != stack.getCount();
|
||||
}
|
||||
}
|
||||
catch( final ChestNoHandler ignored )
|
||||
{
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private class CellInventoryFilter implements IAEItemFilter
|
||||
{
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return AEApi.instance().registries().cell().getCellInventory( stack, TileChest.this,
|
||||
StorageChannel.ITEMS ) != null || AEApi.instance().registries().cell().getCellInventory( stack, TileChest.this,
|
||||
StorageChannel.FLUIDS ) != null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ import java.util.List;
|
||||
|
||||
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.minecraftforge.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.implementations.tiles.IChestOrDrive;
|
||||
@@ -56,8 +55,9 @@ 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 TileDrive extends AENetworkInvTile implements IChestOrDrive, IPriorityHost
|
||||
@@ -67,8 +67,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
private static final int BIT_BLINK_MASK = 0x24924924;
|
||||
private static final int BIT_STATE_MASK = 0xDB6DB6DB;
|
||||
|
||||
private final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 10 );
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 10, 1 );
|
||||
private final ICellHandler[] handlersBySlot = new ICellHandler[10];
|
||||
private final DriveWatcher<IAEItemStack>[] invBySlot = new DriveWatcher[10];
|
||||
private final BaseActionSource mySrc;
|
||||
@@ -97,6 +96,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
{
|
||||
this.mySrc = new MachineSource( this );
|
||||
this.getProxy().setFlags( GridFlags.REQUIRE_CHANNEL );
|
||||
this.inv.setFilter( new CellValidInventoryFilter() );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.NETWORK_WRITE )
|
||||
@@ -257,19 +257,13 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot( final int i, final ItemStack itemstack )
|
||||
{
|
||||
return !itemstack.isEmpty() && AEApi.instance().registries().cell().isCellHandled( 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 )
|
||||
{
|
||||
if( this.isCached )
|
||||
{
|
||||
@@ -291,12 +285,6 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
this.markForUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
private void updateState()
|
||||
{
|
||||
if( !this.isCached )
|
||||
@@ -306,7 +294,7 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
|
||||
double power = 2.0;
|
||||
|
||||
for( int x = 0; x < this.inv.getSizeInventory(); x++ )
|
||||
for( int x = 0; x < this.inv.getSlots(); x++ )
|
||||
{
|
||||
final ItemStack is = this.inv.getStackInSlot( x );
|
||||
this.invBySlot[x] = null;
|
||||
@@ -410,10 +398,20 @@ public class TileDrive extends AENetworkInvTile implements IChestOrDrive, IPrior
|
||||
this.world.markChunkDirty( this.pos, this );
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
private class CellValidInventoryFilter implements IAEItemFilter
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
|
||||
@Override
|
||||
public boolean allowExtract( IItemHandler inv, int slot, int amount )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack )
|
||||
{
|
||||
return !stack.isEmpty() && AEApi.instance().registries().cell().isCellHandled( stack );
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,12 +22,12 @@ package appeng.tile.storage;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
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.items.IItemHandler;
|
||||
|
||||
import appeng.api.AEApi;
|
||||
import appeng.api.config.Actionable;
|
||||
@@ -66,38 +66,25 @@ 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.ConfigManager;
|
||||
import appeng.util.IConfigManagerHost;
|
||||
import appeng.util.InventoryAdaptor;
|
||||
import appeng.util.Platform;
|
||||
import appeng.util.inv.WrapperInventoryRange;
|
||||
import appeng.util.helpers.ItemHandlerUtil;
|
||||
import appeng.util.inv.AdaptorItemHandler;
|
||||
import appeng.util.inv.InvOperation;
|
||||
import appeng.util.inv.WrapperChainedItemHandler;
|
||||
import appeng.util.inv.filter.AEItemFilters;
|
||||
|
||||
|
||||
public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IConfigManagerHost, IGridTickable
|
||||
{
|
||||
private static final int INPUT_SLOT_INDEX_TOP_LEFT = 0;
|
||||
private static final int INPUT_SLOT_INDEX_TOP_RIGHT = 1;
|
||||
private static final int INPUT_SLOT_INDEX_CENTER_LEFT = 2;
|
||||
private static final int INPUT_SLOT_INDEX_CENTER_RIGHT = 3;
|
||||
private static final int INPUT_SLOT_INDEX_BOTTOM_LEFT = 4;
|
||||
private static final int INPUT_SLOT_INDEX_BOTTOM_RIGHT = 5;
|
||||
|
||||
private static final int OUTPUT_SLOT_INDEX_TOP_LEFT = 6;
|
||||
private static final int OUTPUT_SLOT_INDEX_TOP_RIGHT = 7;
|
||||
private static final int OUTPUT_SLOT_INDEX_CENTER_LEFT = 8;
|
||||
private static final int OUTPUT_SLOT_INDEX_CENTER_RIGHT = 9;
|
||||
private static final int OUTPUT_SLOT_INDEX_BOTTOM_LEFT = 10;
|
||||
private static final int OUTPUT_SLOT_INDEX_BOTTOM_RIGHT = 11;
|
||||
|
||||
private final ConfigManager manager;
|
||||
|
||||
private final int[] input = { INPUT_SLOT_INDEX_TOP_LEFT, INPUT_SLOT_INDEX_TOP_RIGHT, INPUT_SLOT_INDEX_CENTER_LEFT, INPUT_SLOT_INDEX_CENTER_RIGHT,
|
||||
INPUT_SLOT_INDEX_BOTTOM_LEFT, INPUT_SLOT_INDEX_BOTTOM_RIGHT };
|
||||
private final int[] output = { OUTPUT_SLOT_INDEX_TOP_LEFT, OUTPUT_SLOT_INDEX_TOP_RIGHT, OUTPUT_SLOT_INDEX_CENTER_LEFT, OUTPUT_SLOT_INDEX_CENTER_RIGHT,
|
||||
OUTPUT_SLOT_INDEX_BOTTOM_LEFT, OUTPUT_SLOT_INDEX_BOTTOM_RIGHT };
|
||||
private final AppEngInternalInventory inputCells = new AppEngInternalInventory( this, 6 );
|
||||
private final AppEngInternalInventory outputCells = new AppEngInternalInventory( this, 6 );
|
||||
private final IItemHandler combinedInventory = new WrapperChainedItemHandler( inputCells, outputCells );
|
||||
|
||||
private final AppEngInternalInventory cells;
|
||||
private final UpgradeInventory upgrades;
|
||||
|
||||
private final BaseActionSource mySrc;
|
||||
@@ -115,19 +102,22 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
this.manager.registerSetting( Settings.REDSTONE_CONTROLLED, RedstoneMode.IGNORE );
|
||||
this.manager.registerSetting( Settings.FULLNESS_MODE, FullnessMode.EMPTY );
|
||||
this.manager.registerSetting( Settings.OPERATION_MODE, OperationMode.EMPTY );
|
||||
this.cells = new AppEngInternalInventory( this, 12 );
|
||||
this.mySrc = new MachineSource( this );
|
||||
this.lastRedstoneState = YesNo.UNDECIDED;
|
||||
|
||||
final Block ioPortBlock = AEApi.instance().definitions().blocks().iOPort().maybeBlock().get();
|
||||
this.upgrades = new BlockUpgradeInventory( ioPortBlock, this, 3 );
|
||||
|
||||
inputCells.setFilter( AEItemFilters.INSERT_ONLY );
|
||||
outputCells.setFilter( AEItemFilters.EXTRACT_ONLY );
|
||||
}
|
||||
|
||||
@TileEvent( TileEventType.WORLD_NBT_WRITE )
|
||||
public void writeToNBT_TileIOPort( final NBTTagCompound data )
|
||||
{
|
||||
this.manager.writeToNBT( data );
|
||||
this.cells.writeToNBT( data, "cells" );
|
||||
this.inputCells.writeToNBT( data, "cellsInput" );
|
||||
this.outputCells.writeToNBT( data, "cellsOutput" );
|
||||
this.upgrades.writeToNBT( data, "upgrades" );
|
||||
data.setInteger( "lastRedstoneState", this.lastRedstoneState.ordinal() );
|
||||
}
|
||||
@@ -136,7 +126,8 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
public void readFromNBT_TileIOPort( final NBTTagCompound data )
|
||||
{
|
||||
this.manager.readFromNBT( data );
|
||||
this.cells.readFromNBT( data, "cells" );
|
||||
this.inputCells.readFromNBT( data, "cellsInput" );
|
||||
this.outputCells.readFromNBT( data, "cellsOutput" );
|
||||
this.upgrades.readFromNBT( data, "upgrades" );
|
||||
if( data.hasKey( "lastRedstoneState" ) )
|
||||
{
|
||||
@@ -217,7 +208,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInventoryByName( final String name )
|
||||
public IItemHandler getInventoryByName( final String name )
|
||||
{
|
||||
if( name.equals( "upgrades" ) )
|
||||
{
|
||||
@@ -226,7 +217,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
if( name.equals( "cells" ) )
|
||||
{
|
||||
return this.cells;
|
||||
return this.combinedInventory;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -242,70 +233,38 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
if( this.isEnabled() )
|
||||
{
|
||||
for( int x = 0; x < 6; x++ )
|
||||
{
|
||||
if( !this.cells.getStackInSlot( x ).isEmpty() )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return !ItemHandlerUtil.isEmpty( inputCells );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.cells;
|
||||
return this.combinedInventory;
|
||||
}
|
||||
|
||||
@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.cells == inv )
|
||||
if( this.inputCells == inv )
|
||||
{
|
||||
this.updateTask();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canInsertItem( final int slotIndex, final ItemStack insertingItem, final EnumFacing side )
|
||||
protected IItemHandler getItemHandlerForSide( final EnumFacing facing )
|
||||
{
|
||||
for( final int inputSlotIndex : this.input )
|
||||
if( facing == getUp() || facing == getUp().getOpposite() )
|
||||
{
|
||||
if( inputSlotIndex == slotIndex )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return inputCells;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canExtractItem( final int slotIndex, final ItemStack extractedItem, final EnumFacing side )
|
||||
{
|
||||
for( final int outputSlotIndex : this.output )
|
||||
else
|
||||
{
|
||||
if( outputSlotIndex == slotIndex )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return outputCells;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing d )
|
||||
{
|
||||
if( d == EnumFacing.UP || d == EnumFacing.DOWN )
|
||||
{
|
||||
return this.input;
|
||||
}
|
||||
|
||||
return this.output;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -344,7 +303,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
final IEnergySource energy = this.getProxy().getEnergy();
|
||||
for( int x = 0; x < 6; x++ )
|
||||
{
|
||||
final ItemStack is = this.cells.getStackInSlot( x );
|
||||
final ItemStack is = this.inputCells.getStackInSlot( x );
|
||||
if( !is.isEmpty() )
|
||||
{
|
||||
if( ItemsToMove > 0 )
|
||||
@@ -512,15 +471,12 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
|
||||
private boolean moveSlot( final int x )
|
||||
{
|
||||
final WrapperInventoryRange wir = new WrapperInventoryRange( this, this.output, true );
|
||||
final ItemStack result = InventoryAdaptor.getAdaptor( wir, EnumFacing.UP ).addItems( this.getStackInSlot( x ) );
|
||||
|
||||
if( result.isEmpty() )
|
||||
final InventoryAdaptor ad = new AdaptorItemHandler( outputCells );
|
||||
if( ad.addItems( inputCells.getStackInSlot( x ) ).isEmpty() )
|
||||
{
|
||||
this.setInventorySlotContents( x, ItemStack.EMPTY );
|
||||
inputCells.setStackInSlot( x, ItemStack.EMPTY );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -570,7 +526,7 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
{
|
||||
super.getDrops( w, pos, drops );
|
||||
|
||||
for( int upgradeIndex = 0; upgradeIndex < this.upgrades.getSizeInventory(); upgradeIndex++ )
|
||||
for( int upgradeIndex = 0; upgradeIndex < this.upgrades.getSlots(); upgradeIndex++ )
|
||||
{
|
||||
final ItemStack stackInSlot = this.upgrades.getStackInSlot( upgradeIndex );
|
||||
|
||||
@@ -580,11 +536,4 @@ public class TileIOPort extends AENetworkInvTile implements IUpgradeableHost, IC
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,59 +23,21 @@ import io.netty.buffer.ByteBuf;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.SoundEvents;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.SoundCategory;
|
||||
import net.minecraftforge.items.IItemHandler;
|
||||
|
||||
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.inv.InvOperation;
|
||||
|
||||
|
||||
public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||
{
|
||||
|
||||
private final int[] sides = {
|
||||
0,
|
||||
1,
|
||||
2,
|
||||
3,
|
||||
4,
|
||||
5,
|
||||
6,
|
||||
7,
|
||||
8,
|
||||
9,
|
||||
10,
|
||||
11,
|
||||
12,
|
||||
13,
|
||||
14,
|
||||
15,
|
||||
16,
|
||||
17,
|
||||
18,
|
||||
19,
|
||||
20,
|
||||
21,
|
||||
22,
|
||||
23,
|
||||
24,
|
||||
25,
|
||||
26,
|
||||
27,
|
||||
28,
|
||||
29,
|
||||
30,
|
||||
31,
|
||||
32,
|
||||
33,
|
||||
34,
|
||||
35 };
|
||||
private final AppEngInternalInventory inv = new AppEngInternalInventory( this, 9 * 4 );
|
||||
// server
|
||||
private int numPlayersUsing;
|
||||
@@ -117,12 +79,11 @@ public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||
}
|
||||
|
||||
@Override
|
||||
public IInventory getInternalInventory()
|
||||
public IItemHandler getInternalInventory()
|
||||
{
|
||||
return this.inv;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openInventory( final EntityPlayer player )
|
||||
{
|
||||
if( !player.isSpectator() )
|
||||
@@ -141,7 +102,6 @@ public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void closeInventory( final EntityPlayer player )
|
||||
{
|
||||
if( !player.isSpectator() )
|
||||
@@ -203,17 +163,11 @@ public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||
}
|
||||
|
||||
@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 )
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsBySide( final EnumFacing side )
|
||||
{
|
||||
return this.sides;
|
||||
}
|
||||
|
||||
public float getLidAngle()
|
||||
{
|
||||
// System.out.println( lidAngle );
|
||||
@@ -254,11 +208,4 @@ public class TileSkyChest extends AEBaseInvTile implements ITickable
|
||||
{
|
||||
this.lastEvent = lastEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty()
|
||||
{
|
||||
// TODO Auto-generated method stub
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user