Use IItemHandler instead of IInventory internally (#2971)
* Use IItemHandler instead of IInventory internally
This commit is contained in:
@@ -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