From 52d28fabe3d3de70892fba32e1e0a22bf0b174db Mon Sep 17 00:00:00 2001 From: fscan Date: Fri, 28 Jul 2017 22:04:32 +0200 Subject: [PATCH] Use IItemHandler instead of IInventory internally (#2971) * Use IItemHandler instead of IInventory internally --- .../guiobjects/INetworkTool.java | 7 +- .../tiles/ISegmentedInventory.java | 5 +- .../tiles/IViewCellStorage.java | 5 +- .../appeng/api/storage/ICellInventory.java | 6 +- .../api/storage/ICellWorkbenchItem.java | 6 +- .../java/appeng/block/AEBaseTileBlock.java | 14 +- .../block/crafting/BlockCraftingStorage.java | 1 + .../java/appeng/block/misc/BlockCharger.java | 4 +- .../networking/BlockDenseEnergyCell.java | 1 + .../java/appeng/block/storage/BlockChest.java | 2 +- .../java/appeng/client/gui/AEBaseGui.java | 2 +- .../java/appeng/client/gui/Size1Slot.java | 9 +- .../gui/implementations/GuiCellWorkbench.java | 6 +- .../implementations/GuiInterfaceTerminal.java | 8 +- src/main/java/appeng/client/me/SlotME.java | 4 +- .../render/model/BiometricCardBakedModel.java | 3 +- .../client/render/tesr/InscriberTESR.java | 17 +- .../appeng/container/AEBaseContainer.java | 25 +- .../ContainerCellWorkbench.java | 166 +------- .../implementations/ContainerChest.java | 4 +- .../implementations/ContainerCondenser.java | 10 +- .../ContainerCraftingTerm.java | 21 +- .../implementations/ContainerDrive.java | 5 +- .../ContainerFormationPlane.java | 6 +- .../implementations/ContainerGrinder.java | 17 +- .../implementations/ContainerIOPort.java | 6 +- .../implementations/ContainerInscriber.java | 25 +- .../ContainerInterfaceTerminal.java | 64 ++- .../ContainerLevelEmitter.java | 6 +- .../implementations/ContainerMAC.java | 8 +- .../implementations/ContainerNetworkTool.java | 5 +- .../implementations/ContainerPatternTerm.java | 29 +- .../implementations/ContainerQNB.java | 5 +- .../implementations/ContainerQuartzKnife.java | 244 ++++-------- .../ContainerSecurityStation.java | 8 +- .../implementations/ContainerSkyChest.java | 2 +- .../ContainerSpatialIOPort.java | 5 +- .../implementations/ContainerStorageBus.java | 21 +- .../implementations/ContainerUpgradeable.java | 10 +- .../ContainerVibrationChamber.java | 3 +- .../implementations/ContainerWireless.java | 5 +- .../container/slot/AppEngCraftingSlot.java | 22 +- .../appeng/container/slot/AppEngSlot.java | 72 +++- .../container/slot/OptionalSlotFake.java | 4 +- .../slot/OptionalSlotFakeTypeOnly.java | 4 +- .../container/slot/OptionalSlotNormal.java | 4 +- .../slot/OptionalSlotRestrictedInput.java | 4 +- .../container/slot/SlotCraftingMatrix.java | 18 +- .../container/slot/SlotCraftingTerm.java | 36 +- .../appeng/container/slot/SlotDisabled.java | 4 +- .../java/appeng/container/slot/SlotFake.java | 4 +- .../container/slot/SlotFakeBlacklist.java | 4 +- .../slot/SlotFakeCraftingMatrix.java | 4 +- .../container/slot/SlotFakeTypeOnly.java | 4 +- .../container/slot/SlotInaccessible.java | 4 +- .../container/slot/SlotInaccessibleHD.java | 4 +- .../appeng/container/slot/SlotMACPattern.java | 4 +- .../appeng/container/slot/SlotNormal.java | 4 +- .../appeng/container/slot/SlotOutput.java | 4 +- .../container/slot/SlotPatternOutputs.java | 4 +- .../container/slot/SlotPatternTerm.java | 4 +- .../container/slot/SlotPlayerHotBar.java | 4 +- .../appeng/container/slot/SlotPlayerInv.java | 4 +- .../container/slot/SlotRestrictedInput.java | 7 +- .../registries/P2PTunnelRegistry.java | 1 - .../core/sync/packets/PacketJEIRecipe.java | 21 +- .../sync/packets/PacketPartPlacement.java | 3 +- .../core/sync/packets/PacketPatternSlot.java | 4 +- .../java/appeng/helpers/DualityInterface.java | 61 +-- .../helpers/IContainerCraftingPacket.java | 4 +- .../theoneprobe/tile/ChargerInfoProvider.java | 4 +- .../waila/tile/ChargerWailaDataProvider.java | 4 +- .../appeng/items/contents/CellConfig.java | 2 +- .../appeng/items/contents/CellUpgrades.java | 2 +- .../items/contents/NetworkToolViewer.java | 133 ++----- .../appeng/items/materials/ItemMaterial.java | 20 +- .../items/storage/ItemBasicStorageCell.java | 12 +- .../storage/ItemCreativeStorageCell.java | 6 +- .../appeng/items/storage/ItemViewCell.java | 14 +- .../tools/powered/ToolColorApplicator.java | 6 +- .../items/tools/powered/ToolMatterCannon.java | 6 +- .../items/tools/powered/ToolPortableCell.java | 6 +- .../powersink/PoweredItemCapabilities.java | 1 - .../java/appeng/me/storage/CellInventory.java | 6 +- .../me/storage/CellInventoryHandler.java | 10 +- src/main/java/appeng/parts/AEBasePart.java | 14 +- .../automation/BlockUpgradeInventory.java | 2 +- .../DefinitionUpgradeInventory.java | 2 +- .../parts/automation/PartFormationPlane.java | 11 +- .../parts/automation/PartLevelEmitter.java | 8 +- .../parts/automation/PartSharedItemBus.java | 6 +- .../parts/automation/PartUpgradeable.java | 10 +- .../automation/StackUpgradeInventory.java | 2 +- .../parts/automation/UpgradeInventory.java | 66 ++-- .../java/appeng/parts/misc/PartInterface.java | 148 +------ .../appeng/parts/misc/PartStorageBus.java | 9 +- .../java/appeng/parts/p2p/PartP2PFEPower.java | 29 +- .../java/appeng/parts/p2p/PartP2PItems.java | 317 +++------------ .../parts/reporting/AbstractPartTerminal.java | 10 +- .../reporting/PartConversionMonitor.java | 3 +- .../parts/reporting/PartCraftingTerminal.java | 4 +- .../parts/reporting/PartPatternTerminal.java | 18 +- .../recipes/loader/RecipeResourceCopier.java | 2 +- src/main/java/appeng/tile/AEBaseInvTile.java | 236 +++-------- src/main/java/appeng/tile/AEBaseTile.java | 24 +- .../tile/crafting/TileMolecularAssembler.java | 141 ++++--- .../appeng/tile/grid/AENetworkInvTile.java | 13 - .../appeng/tile/grindstone/TileGrinder.java | 77 ++-- .../inventory/AppEngInternalAEInventory.java | 188 ++++----- .../inventory/AppEngInternalInventory.java | 350 +++++------------ .../appeng/tile/misc/TileCellWorkbench.java | 51 +-- .../java/appeng/tile/misc/TileCharger.java | 97 ++--- .../java/appeng/tile/misc/TileCondenser.java | 106 +---- .../java/appeng/tile/misc/TileInscriber.java | 352 +++++------------ .../java/appeng/tile/misc/TileInterface.java | 23 +- .../appeng/tile/misc/TileSecurityStation.java | 11 +- .../tile/misc/TileVibrationChamber.java | 57 ++- .../tile/networking/TileController.java | 29 +- .../tile/networking/TileEnergyAcceptor.java | 31 +- .../appeng/tile/networking/TileWireless.java | 30 +- .../tile/powersink/AERootPoweredTile.java | 1 - .../appeng/tile/qnb/TileQuantumBridge.java | 26 +- .../tile/spatial/TileSpatialIOPort.java | 59 ++- .../java/appeng/tile/storage/TileChest.java | 173 ++++---- .../java/appeng/tile/storage/TileDrive.java | 46 ++- .../java/appeng/tile/storage/TileIOPort.java | 117 ++---- .../appeng/tile/storage/TileSkyChest.java | 61 +-- .../java/appeng/util/InventoryAdaptor.java | 68 +--- src/main/java/appeng/util/Lazy.java | 44 +++ src/main/java/appeng/util/Platform.java | 82 ---- .../appeng/util/helpers/ItemHandlerUtil.java | 115 ++++++ .../appeng/util/inv/AdaptorIInventory.java | 368 ------------------ .../appeng/util/inv/AdaptorItemHandler.java | 6 + .../java/appeng/util/inv/AdaptorList.java | 6 + .../appeng/util/inv/AdaptorPlayerHand.java | 237 ----------- .../util/inv/AdaptorPlayerInventory.java | 162 -------- .../inv}/IAEAppEngInventory.java | 7 +- ...Wrapper.java => IInternalItemHandler.java} | 8 +- src/main/java/appeng/util/inv/IMEAdaptor.java | 6 + .../inventory => util/inv}/InvOperation.java | 5 +- .../util/inv/WrapperChainedInventory.java | 275 ------------- .../util/inv/WrapperChainedItemHandler.java | 178 +++++++++ .../util/inv/WrapperCursorItemHandler.java | 43 ++ .../util/inv/WrapperFilteredItemHandler.java | 103 +++++ .../inv/WrapperInvItemHandler.java} | 160 ++++---- .../java/appeng/util/inv/WrapperInvSlot.java | 175 --------- .../util/inv/WrapperInventoryRange.java | 216 ---------- .../util/inv/WrapperLazyItemHandler.java | 87 +++++ .../util/inv/WrapperMCISidedInventory.java | 77 ---- .../util/inv/WrapperRangeItemHandler.java | 129 ++++++ .../inv/filter/AEItemDefinitionFilter.java | 49 +++ .../appeng/util/inv/filter/AEItemFilters.java | 64 +++ .../inv/filter/IAEItemFilter.java} | 15 +- .../appeng/util/iterators/AEInvIterator.java | 2 +- .../appeng/util/iterators/InvIterator.java | 8 +- .../java/appeng/worldgen/MeteoritePlacer.java | 6 +- 156 files changed, 2410 insertions(+), 4604 deletions(-) create mode 100644 src/main/java/appeng/util/Lazy.java create mode 100644 src/main/java/appeng/util/helpers/ItemHandlerUtil.java delete mode 100644 src/main/java/appeng/util/inv/AdaptorIInventory.java delete mode 100644 src/main/java/appeng/util/inv/AdaptorPlayerHand.java delete mode 100644 src/main/java/appeng/util/inv/AdaptorPlayerInventory.java rename src/main/java/appeng/{tile/inventory => util/inv}/IAEAppEngInventory.java (83%) rename src/main/java/appeng/util/inv/{IInventoryWrapper.java => IInternalItemHandler.java} (74%) rename src/main/java/appeng/{tile/inventory => util/inv}/InvOperation.java (90%) delete mode 100644 src/main/java/appeng/util/inv/WrapperChainedInventory.java create mode 100644 src/main/java/appeng/util/inv/WrapperChainedItemHandler.java create mode 100644 src/main/java/appeng/util/inv/WrapperCursorItemHandler.java create mode 100644 src/main/java/appeng/util/inv/WrapperFilteredItemHandler.java rename src/main/java/appeng/{tile/inventory/AppEngNullInventory.java => util/inv/WrapperInvItemHandler.java} (52%) delete mode 100644 src/main/java/appeng/util/inv/WrapperInvSlot.java delete mode 100644 src/main/java/appeng/util/inv/WrapperInventoryRange.java create mode 100644 src/main/java/appeng/util/inv/WrapperLazyItemHandler.java delete mode 100644 src/main/java/appeng/util/inv/WrapperMCISidedInventory.java create mode 100644 src/main/java/appeng/util/inv/WrapperRangeItemHandler.java create mode 100644 src/main/java/appeng/util/inv/filter/AEItemDefinitionFilter.java create mode 100644 src/main/java/appeng/util/inv/filter/AEItemFilters.java rename src/main/java/appeng/{container/slot/QuartzKnifeOutput.java => util/inv/filter/IAEItemFilter.java} (68%) diff --git a/src/api/java/appeng/api/implementations/guiobjects/INetworkTool.java b/src/api/java/appeng/api/implementations/guiobjects/INetworkTool.java index 4e0dc9589..078ac8e96 100644 --- a/src/api/java/appeng/api/implementations/guiobjects/INetworkTool.java +++ b/src/api/java/appeng/api/implementations/guiobjects/INetworkTool.java @@ -24,7 +24,7 @@ package appeng.api.implementations.guiobjects; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; import appeng.api.networking.IGridHost; @@ -32,8 +32,9 @@ import appeng.api.networking.IGridHost; /** * Obtained via {@link IGuiItem} getGuiObject */ -public interface INetworkTool extends IInventory, IGuiItemObject +public interface INetworkTool extends IGuiItemObject { - IGridHost getGridHost(); // null for most purposes. + + IItemHandler getInventory(); } diff --git a/src/api/java/appeng/api/implementations/tiles/ISegmentedInventory.java b/src/api/java/appeng/api/implementations/tiles/ISegmentedInventory.java index c73a8a53f..50ee03974 100644 --- a/src/api/java/appeng/api/implementations/tiles/ISegmentedInventory.java +++ b/src/api/java/appeng/api/implementations/tiles/ISegmentedInventory.java @@ -23,8 +23,7 @@ package appeng.api.implementations.tiles; - -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public interface ISegmentedInventory @@ -38,5 +37,5 @@ public interface ISegmentedInventory * * @return inventory with inventory name */ - IInventory getInventoryByName( String name ); + IItemHandler getInventoryByName( String name ); } diff --git a/src/api/java/appeng/api/implementations/tiles/IViewCellStorage.java b/src/api/java/appeng/api/implementations/tiles/IViewCellStorage.java index 4a81ae12b..3a932a5ff 100644 --- a/src/api/java/appeng/api/implementations/tiles/IViewCellStorage.java +++ b/src/api/java/appeng/api/implementations/tiles/IViewCellStorage.java @@ -23,8 +23,7 @@ package appeng.api.implementations.tiles; - -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public interface IViewCellStorage @@ -35,5 +34,5 @@ public interface IViewCellStorage * * @return inventory with at least 5 slot */ - IInventory getViewCellStorage(); + IItemHandler getViewCellStorage(); } diff --git a/src/api/java/appeng/api/storage/ICellInventory.java b/src/api/java/appeng/api/storage/ICellInventory.java index 13494b8d1..122541c01 100644 --- a/src/api/java/appeng/api/storage/ICellInventory.java +++ b/src/api/java/appeng/api/storage/ICellInventory.java @@ -24,8 +24,8 @@ package appeng.api.storage; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; import appeng.api.storage.data.IAEItemStack; @@ -52,12 +52,12 @@ public interface ICellInventory extends IMEInventory /** * @return access configured list */ - IInventory getConfigInventory(); + IItemHandler getConfigInventory(); /** * @return access installed upgrades. */ - IInventory getUpgradesInventory(); + IItemHandler getUpgradesInventory(); /** * @return How many bytes are used for each type? diff --git a/src/api/java/appeng/api/storage/ICellWorkbenchItem.java b/src/api/java/appeng/api/storage/ICellWorkbenchItem.java index 668095c6e..d55efc2ae 100644 --- a/src/api/java/appeng/api/storage/ICellWorkbenchItem.java +++ b/src/api/java/appeng/api/storage/ICellWorkbenchItem.java @@ -24,8 +24,8 @@ package appeng.api.storage; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; @@ -48,7 +48,7 @@ public interface ICellWorkbenchItem * * onInventoryChange will be called when saving is needed. */ - IInventory getUpgradesInventory( ItemStack is ); + IItemHandler getUpgradesInventory( ItemStack is ); /** * Used to extract, or mirror the contents of the work bench onto the cell. @@ -57,7 +57,7 @@ public interface ICellWorkbenchItem * * onInventoryChange will be called when saving is needed. */ - IInventory getConfigInventory( ItemStack is ); + IItemHandler getConfigInventory( ItemStack is ); /** * @return the current fuzzy status. diff --git a/src/main/java/appeng/block/AEBaseTileBlock.java b/src/main/java/appeng/block/AEBaseTileBlock.java index 5bf4ae07b..0f19c57bf 100644 --- a/src/main/java/appeng/block/AEBaseTileBlock.java +++ b/src/main/java/appeng/block/AEBaseTileBlock.java @@ -34,8 +34,6 @@ import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -48,6 +46,7 @@ import net.minecraft.world.World; import net.minecraftforge.common.property.ExtendedBlockState; import net.minecraftforge.common.property.IExtendedBlockState; import net.minecraftforge.common.property.IUnlistedProperty; +import net.minecraftforge.items.ItemHandlerHelper; import appeng.api.implementations.items.IMemoryCard; import appeng.api.implementations.items.MemoryCardMessages; @@ -56,6 +55,7 @@ import appeng.api.util.AEColor; import appeng.api.util.IOrientable; import appeng.block.networking.BlockCableBus; import appeng.helpers.ICustomCollision; +import appeng.tile.AEBaseInvTile; import appeng.tile.AEBaseTile; import appeng.tile.networking.TileCableBus; import appeng.tile.storage.TileSkyChest; @@ -115,7 +115,7 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity public void setTileEntity( final Class c ) { this.tileEntityType = c; - this.setInventory( IInventory.class.isAssignableFrom( c ) ); + this.setInventory( AEBaseInvTile.class.isAssignableFrom( c ) ); } @Override @@ -241,9 +241,13 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity public int getComparatorInputOverride( IBlockState state, final World w, final BlockPos pos ) { final TileEntity te = this.getTileEntity( w, pos ); - if( te instanceof IInventory ) + if( te instanceof AEBaseInvTile ) { - return Container.calcRedstoneFromInventory( (IInventory) te ); + AEBaseInvTile invTile = (AEBaseInvTile) te; + if( invTile.getInternalInventory().getSlots() > 0 ) + { + return ItemHandlerHelper.calcRedstoneFromInventory( invTile.getInternalInventory() ); + } } return 0; } diff --git a/src/main/java/appeng/block/crafting/BlockCraftingStorage.java b/src/main/java/appeng/block/crafting/BlockCraftingStorage.java index 5940ab0d3..103387560 100644 --- a/src/main/java/appeng/block/crafting/BlockCraftingStorage.java +++ b/src/main/java/appeng/block/crafting/BlockCraftingStorage.java @@ -18,6 +18,7 @@ package appeng.block.crafting; + public class BlockCraftingStorage extends BlockCraftingUnit { diff --git a/src/main/java/appeng/block/misc/BlockCharger.java b/src/main/java/appeng/block/misc/BlockCharger.java index 4cacad5e5..82755d98a 100644 --- a/src/main/java/appeng/block/misc/BlockCharger.java +++ b/src/main/java/appeng/block/misc/BlockCharger.java @@ -109,7 +109,7 @@ public class BlockCharger extends AEBaseTileBlock implements ICustomCollision { final TileCharger tc = (TileCharger) tile; - if( AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( tc.getStackInSlot( 0 ) ) ) + if( AEApi.instance().definitions().materials().certusQuartzCrystalCharged().isSameAs( tc.getInternalInventory().getStackInSlot( 0 ) ) ) { final double xOff = 0.0; final double yOff = 0.0; @@ -201,7 +201,7 @@ public class BlockCharger extends AEBaseTileBlock implements ICustomCollision { Matrix4f transform = new Matrix4f(); transform.translate( new Vector3f( 0.5f, 0.4f, 0.5f ) ); - return new ImmutablePair<>( tile.getStackInSlot( 0 ), transform ); + return new ImmutablePair<>( tile.getInternalInventory().getStackInSlot( 0 ), transform ); } } diff --git a/src/main/java/appeng/block/networking/BlockDenseEnergyCell.java b/src/main/java/appeng/block/networking/BlockDenseEnergyCell.java index 5a263993a..7ff50c435 100644 --- a/src/main/java/appeng/block/networking/BlockDenseEnergyCell.java +++ b/src/main/java/appeng/block/networking/BlockDenseEnergyCell.java @@ -18,6 +18,7 @@ package appeng.block.networking; + public class BlockDenseEnergyCell extends BlockEnergyCell { diff --git a/src/main/java/appeng/block/storage/BlockChest.java b/src/main/java/appeng/block/storage/BlockChest.java index c450708da..f38ef7b1a 100644 --- a/src/main/java/appeng/block/storage/BlockChest.java +++ b/src/main/java/appeng/block/storage/BlockChest.java @@ -108,7 +108,7 @@ public class BlockChest extends AEBaseTileBlock } else { - final ItemStack cell = tg.getStackInSlot( 1 ); + final ItemStack cell = tg.getCell(); if( !cell.isEmpty() ) { final ICellHandler ch = AEApi.instance().registries().cell().getHandler( cell ); diff --git a/src/main/java/appeng/client/gui/AEBaseGui.java b/src/main/java/appeng/client/gui/AEBaseGui.java index 7b919c2c9..0a0476787 100644 --- a/src/main/java/appeng/client/gui/AEBaseGui.java +++ b/src/main/java/appeng/client/gui/AEBaseGui.java @@ -713,7 +713,7 @@ public abstract class AEBaseGui extends GuiContainer this.itemRender.zLevel = 0.0F; // Annoying but easier than trying to splice into render item - super.drawSlot( new Size1Slot( s ) ); + super.drawSlot( new Size1Slot( (SlotME) s ) ); this.stackSizeRenderer.renderStackSize( this.fontRenderer, ( (SlotME) s ).getAEStack(), s.getStack(), s.xPos, s.yPos ); diff --git a/src/main/java/appeng/client/gui/Size1Slot.java b/src/main/java/appeng/client/gui/Size1Slot.java index 13170958c..c969651a4 100644 --- a/src/main/java/appeng/client/gui/Size1Slot.java +++ b/src/main/java/appeng/client/gui/Size1Slot.java @@ -13,20 +13,21 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.SlotItemHandler; /** * A proxy for a slot that will always return an itemstack with size 1, if there is an item in the slot. * Used to prevent the default item count from rendering. */ -class Size1Slot extends Slot +class Size1Slot extends SlotItemHandler { - private final Slot delegate; + private final SlotItemHandler delegate; - public Size1Slot( Slot delegate ) + public Size1Slot( SlotItemHandler delegate ) { - super( delegate.inventory, delegate.getSlotIndex(), delegate.xPos, delegate.yPos ); + super( delegate.getItemHandler(), delegate.getSlotIndex(), delegate.xPos, delegate.yPos ); this.delegate = delegate; } diff --git a/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java index 972f71ab0..80aa32481 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java +++ b/src/main/java/appeng/client/gui/implementations/GuiCellWorkbench.java @@ -25,8 +25,8 @@ import org.lwjgl.input.Mouse; import net.minecraft.client.gui.GuiButton; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.ActionItems; import appeng.api.config.CopyMode; @@ -137,8 +137,8 @@ public class GuiCellWorkbench extends GuiUpgradeable this.copyMode.setState( this.workbench.getCopyMode() == CopyMode.CLEAR_ON_REMOVE ); boolean hasFuzzy = false; - final IInventory inv = this.workbench.getCellUpgradeInventory(); - for( int x = 0; x < inv.getSizeInventory(); x++ ) + final IItemHandler inv = this.workbench.getCellUpgradeInventory(); + for( int x = 0; x < inv.getSlots(); x++ ) { final ItemStack is = inv.getStackInSlot( x ); if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule ) diff --git a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java index 9b233f3cd..d009f430d 100644 --- a/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java +++ b/src/main/java/appeng/client/gui/implementations/GuiInterfaceTerminal.java @@ -119,7 +119,7 @@ public class GuiInterfaceTerminal extends AEBaseGui if( lineObj instanceof ClientDCInternalInv ) { final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj; - for( int z = 0; z < inv.getInventory().getSizeInventory(); z++ ) + for( int z = 0; z < inv.getInventory().getSlots(); z++ ) { this.inventorySlots.inventorySlots.add( new SlotDisconnected( inv, z, z * 18 + 8, 1 + offset ) ); } @@ -175,7 +175,7 @@ public class GuiInterfaceTerminal extends AEBaseGui final ClientDCInternalInv inv = (ClientDCInternalInv) lineObj; GlStateManager.color( 1, 1, 1, 1 ); - final int width = inv.getInventory().getSizeInventory() * 18; + final int width = inv.getInventory().getSlots() * 18; this.drawTexturedModalRect( offsetX + 7, offsetY + offset, 7, 139, width, 18 ); } offset += 18; @@ -227,12 +227,12 @@ public class GuiInterfaceTerminal extends AEBaseGui final NBTTagCompound invData = in.getCompoundTag( key ); final ClientDCInternalInv current = this.getById( id, invData.getLong( "sortBy" ), invData.getString( "un" ) ); - for( int x = 0; x < current.getInventory().getSizeInventory(); x++ ) + for( int x = 0; x < current.getInventory().getSlots(); x++ ) { final String which = Integer.toString( x ); if( invData.hasKey( which ) ) { - current.getInventory().setInventorySlotContents( x, new ItemStack( invData.getCompoundTag( which ) ) ); + current.getInventory().setStackInSlot( x, new ItemStack( invData.getCompoundTag( which ) ) ); } } } diff --git a/src/main/java/appeng/client/me/SlotME.java b/src/main/java/appeng/client/me/SlotME.java index d0fc27768..1be6fdb5d 100644 --- a/src/main/java/appeng/client/me/SlotME.java +++ b/src/main/java/appeng/client/me/SlotME.java @@ -21,13 +21,13 @@ package appeng.client.me; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.SlotItemHandler; import appeng.api.storage.data.IAEItemStack; -public class SlotME extends Slot +public class SlotME extends SlotItemHandler { private final InternalSlotME mySlot; diff --git a/src/main/java/appeng/client/render/model/BiometricCardBakedModel.java b/src/main/java/appeng/client/render/model/BiometricCardBakedModel.java index a8c17b8f0..f8db65e87 100644 --- a/src/main/java/appeng/client/render/model/BiometricCardBakedModel.java +++ b/src/main/java/appeng/client/render/model/BiometricCardBakedModel.java @@ -200,7 +200,8 @@ class BiometricCardBakedModel implements IBakedModel try { - return BiometricCardBakedModel.this.modelCache.get( hash, () -> new BiometricCardBakedModel( BiometricCardBakedModel.this.format, BiometricCardBakedModel.this.baseModel, BiometricCardBakedModel.this.texture, hash, BiometricCardBakedModel.this.modelCache ) ); + return BiometricCardBakedModel.this.modelCache.get( hash, + () -> new BiometricCardBakedModel( BiometricCardBakedModel.this.format, BiometricCardBakedModel.this.baseModel, BiometricCardBakedModel.this.texture, hash, BiometricCardBakedModel.this.modelCache ) ); } catch( ExecutionException e ) { diff --git a/src/main/java/appeng/client/render/tesr/InscriberTESR.java b/src/main/java/appeng/client/render/tesr/InscriberTESR.java index ef665449b..fb74f9584 100644 --- a/src/main/java/appeng/client/render/tesr/InscriberTESR.java +++ b/src/main/java/appeng/client/render/tesr/InscriberTESR.java @@ -19,6 +19,7 @@ import net.minecraft.init.Blocks; import net.minecraft.item.ItemStack; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.TextureStitchEvent; +import net.minecraftforge.items.IItemHandler; import appeng.api.features.IInscriberRecipe; import appeng.client.render.FacingToRotation; @@ -133,16 +134,18 @@ public class InscriberTESR extends TileEntitySpecialRenderer // render items. GlStateManager.color( 1.0F, 1.0F, 1.0F, 1.0F ); + IItemHandler tileInv = tile.getInternalInventory(); + int items = 0; - if( !tile.getStackInSlot( 0 ).isEmpty() ) + if( !tileInv.getStackInSlot( 0 ).isEmpty() ) { items++; } - if( !tile.getStackInSlot( 1 ).isEmpty() ) + if( !tileInv.getStackInSlot( 1 ).isEmpty() ) { items++; } - if( !tile.getStackInSlot( 2 ).isEmpty() ) + if( !tileInv.getStackInSlot( 2 ).isEmpty() ) { items++; } @@ -151,7 +154,7 @@ public class InscriberTESR extends TileEntitySpecialRenderer if( relativeProgress > 1.0f || items == 0 ) { - ItemStack is = tile.getStackInSlot( 3 ); + ItemStack is = tileInv.getStackInSlot( 3 ); if( is.isEmpty() ) { @@ -166,9 +169,9 @@ public class InscriberTESR extends TileEntitySpecialRenderer } else { - this.renderItem( tile.getStackInSlot( 0 ), press, tile, buffer, x, y, z ); - this.renderItem( tile.getStackInSlot( 1 ), -press, tile, buffer, x, y, z ); - this.renderItem( tile.getStackInSlot( 2 ), 0.0f, tile, buffer, x, y, z ); + this.renderItem( tileInv.getStackInSlot( 0 ), press, tile, buffer, x, y, z ); + this.renderItem( tileInv.getStackInSlot( 1 ), -press, tile, buffer, x, y, z ); + this.renderItem( tileInv.getStackInSlot( 2 ), 0.0f, tile, buffer, x, y, z ); } // Tessellator.getInstance().draw(); diff --git a/src/main/java/appeng/container/AEBaseContainer.java b/src/main/java/appeng/container/AEBaseContainer.java index 91db0c810..0d2c27e53 100644 --- a/src/main/java/appeng/container/AEBaseContainer.java +++ b/src/main/java/appeng/container/AEBaseContainer.java @@ -40,7 +40,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerInvWrapper; import appeng.api.AEApi; import appeng.api.config.Actionable; @@ -78,13 +79,13 @@ import appeng.helpers.ICustomNameObject; import appeng.helpers.InventoryAction; import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; +import appeng.util.inv.AdaptorItemHandler; +import appeng.util.inv.WrapperCursorItemHandler; import appeng.util.item.AEItemStack; public abstract class AEBaseContainer extends Container { - private final InventoryPlayer invPlayer; private final BaseActionSource mySrc; private final HashSet locked = new HashSet<>(); @@ -386,6 +387,8 @@ public abstract class AEBaseContainer extends Container protected void bindPlayerInventory( final InventoryPlayer inventoryPlayer, final int offsetX, final int offsetY ) { + IItemHandler ih = new PlayerInvWrapper( inventoryPlayer ); + // bind player inventory for( int i = 0; i < 3; i++ ) { @@ -393,11 +396,11 @@ public abstract class AEBaseContainer extends Container { if( this.locked.contains( j + i * 9 + 9 ) ) { - this.addSlotToContainer( new SlotDisabled( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) ); + this.addSlotToContainer( new SlotDisabled( ih, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) ); } else { - this.addSlotToContainer( new SlotPlayerInv( inventoryPlayer, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) ); + this.addSlotToContainer( new SlotPlayerInv( ih, j + i * 9 + 9, 8 + j * 18 + offsetX, offsetY + i * 18 ) ); } } } @@ -407,11 +410,11 @@ public abstract class AEBaseContainer extends Container { if( this.locked.contains( i ) ) { - this.addSlotToContainer( new SlotDisabled( inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY ) ); + this.addSlotToContainer( new SlotDisabled( ih, i, 8 + i * 18 + offsetX, 58 + offsetY ) ); } else { - this.addSlotToContainer( new SlotPlayerHotBar( inventoryPlayer, i, 8 + i * 18 + offsetX, 58 + offsetY ) ); + this.addSlotToContainer( new SlotPlayerHotBar( ih, i, 8 + i * 18 + offsetX, 58 + offsetY ) ); } } } @@ -862,7 +865,7 @@ public abstract class AEBaseContainer extends Container ais.setStackSize( myItem.getMaxStackSize() ); - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); + final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player ); myItem.setCount( (int) ais.getStackSize() ); myItem = adp.simulateAdd( myItem ); @@ -896,7 +899,7 @@ public abstract class AEBaseContainer extends Container ais = Platform.poweredInsert( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais == null ) { - final InventoryAdaptor ia = new AdaptorPlayerHand( player ); + final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) ); final ItemStack fail = ia.removeItems( 1, extracted.getItemStack(), null ); if( fail.isEmpty() ) @@ -940,7 +943,7 @@ public abstract class AEBaseContainer extends Container ais = Platform.poweredExtraction( this.getPowerSource(), this.getCellInventory(), ais, this.getActionSource() ); if( ais != null ) { - final InventoryAdaptor ia = new AdaptorPlayerHand( player ); + final InventoryAdaptor ia = new AdaptorItemHandler( new WrapperCursorItemHandler( player.inventory ) ); final ItemStack fail = ia.addItems( ais.getItemStack() ); if( !fail.isEmpty() ) @@ -1070,7 +1073,7 @@ public abstract class AEBaseContainer extends Container ais.setStackSize( myItem.getMaxStackSize() ); - final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); + final InventoryAdaptor adp = InventoryAdaptor.getAdaptor( player ); myItem.setCount( (int) ais.getStackSize() ); myItem = adp.simulateAdd( myItem ); diff --git a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java index 28659bd80..5b078d437 100644 --- a/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java +++ b/src/main/java/appeng/container/implementations/ContainerCellWorkbench.java @@ -21,14 +21,13 @@ package appeng.container.implementations; import java.util.Iterator; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.EmptyHandler; import appeng.api.AEApi; import appeng.api.config.CopyMode; @@ -43,16 +42,16 @@ import appeng.container.guisync.GuiSync; import appeng.container.slot.OptionalSlotRestrictedInput; import appeng.container.slot.SlotFakeTypeOnly; import appeng.container.slot.SlotRestrictedInput; -import appeng.tile.inventory.AppEngNullInventory; import appeng.tile.misc.TileCellWorkbench; import appeng.util.Platform; +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.WrapperLazyItemHandler; import appeng.util.iterators.NullIterator; public class ContainerCellWorkbench extends ContainerUpgradeable { private final TileCellWorkbench workBench; - private final AppEngNullInventory nullInventory = new AppEngNullInventory(); @GuiSync( 2 ) public CopyMode copyMode = CopyMode.CLEAR_ON_REMOVE; private ItemStack prevStack = ItemStack.EMPTY; @@ -92,11 +91,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable @Override protected void setupConfig() { - final IInventory cell = this.getUpgradeable().getInventoryByName( "cell" ); + final IItemHandler cell = this.getUpgradeable().getInventoryByName( "cell" ); this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.WORKBENCH_CELL, cell, 0, 152, 8, this.getPlayerInv() ) ); - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); - final IInventory upgradeInventory = new Upgrades(); + final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" ); + final WrapperLazyItemHandler upgradeInventory = new WrapperLazyItemHandler( this::getCellUpgradeInventory ); // null, 3 * 8 ); int offset = 0; @@ -138,7 +137,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable if( this.prevStack != is ) { this.prevStack = is; - this.lastUpgrades = this.getCellUpgradeInventory().getSizeInventory(); + this.lastUpgrades = this.getCellUpgradeInventory().getSlots(); } return this.lastUpgrades; } @@ -189,11 +188,11 @@ public class ContainerCellWorkbench extends ContainerUpgradeable return idx < this.availableUpgrades(); } - public IInventory getCellUpgradeInventory() + public IItemHandler getCellUpgradeInventory() { - final IInventory upgradeInventory = this.workBench.getCellUpgradeInventory(); + final IItemHandler upgradeInventory = this.workBench.getCellUpgradeInventory(); - return upgradeInventory == null ? this.nullInventory : upgradeInventory; + return upgradeInventory == null ? EmptyHandler.INSTANCE : upgradeInventory; } @Override @@ -209,11 +208,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable public void clear() { - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); - for( int x = 0; x < inv.getSizeInventory(); x++ ) - { - inv.setInventorySlotContents( x, ItemStack.EMPTY ); - } + ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) ); this.detectAndSendChanges(); } @@ -229,7 +224,7 @@ public class ContainerCellWorkbench extends ContainerUpgradeable public void partition() { - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" ); final IMEInventory cellInv = AEApi.instance().registries().cell().getCellInventory( this.getUpgradeable().getInventoryByName( "cell" ).getStackInSlot( 0 ), null, StorageChannel.ITEMS ); @@ -241,17 +236,17 @@ public class ContainerCellWorkbench extends ContainerUpgradeable i = list.iterator(); } - for( int x = 0; x < inv.getSizeInventory(); x++ ) + for( int x = 0; x < inv.getSlots(); x++ ) { if( i.hasNext() ) { final ItemStack g = i.next().getItemStack(); g.setCount( 1 ); - inv.setInventorySlotContents( x, g ); + ItemHandlerUtil.setStackInSlot( inv, x, g ); } else { - inv.setInventorySlotContents( x, ItemStack.EMPTY ); + ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY ); } } @@ -267,131 +262,4 @@ public class ContainerCellWorkbench extends ContainerUpgradeable { this.copyMode = copyMode; } - - private class Upgrades implements IInventory - { - - @Override - public int getSizeInventory() - { - return ContainerCellWorkbench.this.getCellUpgradeInventory().getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot( final int i ) - { - return ContainerCellWorkbench.this.getCellUpgradeInventory().getStackInSlot( i ); - } - - @Override - public ItemStack decrStackSize( final int i, final int j ) - { - final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory(); - final ItemStack is = inv.decrStackSize( i, j ); - inv.markDirty(); - return is; - } - - @Override - public ItemStack removeStackFromSlot( final int i ) - { - final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory(); - final ItemStack is = inv.removeStackFromSlot( i ); - inv.markDirty(); - return is; - } - - @Override - public void setInventorySlotContents( final int i, final ItemStack itemstack ) - { - final IInventory inv = ContainerCellWorkbench.this.getCellUpgradeInventory(); - inv.setInventorySlotContents( i, itemstack ); - inv.markDirty(); - } - - @Override - public String getName() - { - return "Upgrades"; - } - - @Override - public boolean hasCustomName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public void markDirty() - { - - } - - @Override - public boolean isUsableByPlayer( EntityPlayer player ) - { - return false; - } - - @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 ContainerCellWorkbench.this.getCellUpgradeInventory().isItemValidForSlot( i, itemstack ); - } - - @Override - public ITextComponent getDisplayName() - { - return null; - } - - @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() - { - ContainerCellWorkbench.this.getCellUpgradeInventory().clear(); - } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } - } -} +} \ No newline at end of file diff --git a/src/main/java/appeng/container/implementations/ContainerChest.java b/src/main/java/appeng/container/implementations/ContainerChest.java index b2a5a3e84..5659071da 100644 --- a/src/main/java/appeng/container/implementations/ContainerChest.java +++ b/src/main/java/appeng/container/implementations/ContainerChest.java @@ -36,8 +36,8 @@ public class ContainerChest extends AEBaseContainer super( ip, chest, null ); this.chest = chest; - this.addSlotToContainer( - new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest, 1, 80, 37, this.getInventoryPlayer() ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, this.chest.getInternalInventory(), 1, 80, 37, this + .getInventoryPlayer() ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerCondenser.java b/src/main/java/appeng/container/implementations/ContainerCondenser.java index 555f1cf77..44c19eee9 100644 --- a/src/main/java/appeng/container/implementations/ContainerCondenser.java +++ b/src/main/java/appeng/container/implementations/ContainerCondenser.java @@ -20,6 +20,7 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.CondenserOutput; import appeng.api.config.Settings; @@ -48,11 +49,12 @@ public class ContainerCondenser extends AEBaseContainer implements IProgressProv super( ip, condenser, null ); this.condenser = condenser; - this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, condenser, 0, 51, 52, ip ) ); - this.addSlotToContainer( new SlotOutput( condenser, 1, 105, 52, -1 ) ); + IItemHandler inv = condenser.getInternalInventory(); + + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.TRASH, inv, 0, 51, 52, ip ) ); + this.addSlotToContainer( new SlotOutput( inv, 1, 105, 52, -1 ) ); this.addSlotToContainer( - ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, condenser.getInternalInventory(), 2, 101, 26, ip ) ) - .setStackLimit( 1 ) ); + ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_COMPONENT, inv, 2, 101, 26, ip ) ).setStackLimit( 1 ) ); this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java b/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java index 2da47e172..d2f07db85 100644 --- a/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerCraftingTerm.java @@ -24,6 +24,8 @@ import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerInvWrapper; import appeng.api.storage.ITerminalHost; import appeng.container.ContainerNull; @@ -32,8 +34,9 @@ import appeng.container.slot.SlotCraftingTerm; import appeng.helpers.IContainerCraftingPacket; import appeng.parts.reporting.PartCraftingTerminal; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; +import appeng.util.inv.WrapperInvItemHandler; public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAEAppEngInventory, IContainerCraftingPacket @@ -49,7 +52,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE super( ip, monitorable, false ); this.ct = (PartCraftingTerminal) monitorable; - final IInventory crafting = this.ct.getInventoryByName( "crafting" ); + final IItemHandler crafting = this.ct.getInventoryByName( "crafting" ); for( int y = 0; y < 3; y++ ) { @@ -64,14 +67,15 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE this.bindPlayerInventory( ip, 0, 0 ); - this.onCraftMatrixChanged( crafting ); + this.onCraftMatrixChanged( new WrapperInvItemHandler( crafting ) ); } /** * Callback for when the crafting matrix is changed. */ + @Override - public void onCraftMatrixChanged( final IInventory par1IInventory ) + public void onCraftMatrixChanged( IInventory inventory ) { final ContainerNull cn = new ContainerNull(); final InventoryCrafting ic = new InventoryCrafting( cn, 3, 3 ); @@ -82,6 +86,7 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE } this.outputSlot.putStack( CraftingManager.findMatchingResult( ic, this.getPlayerInv().player.world ) ); + super.onCraftMatrixChanged( inventory ); } @Override @@ -91,17 +96,17 @@ public class ContainerCraftingTerm extends ContainerMEMonitorable implements IAE } @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 ) { } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "player" ) ) { - return this.getInventoryPlayer(); + return new PlayerInvWrapper( this.getInventoryPlayer() ); } return this.ct.getInventoryByName( name ); } diff --git a/src/main/java/appeng/container/implementations/ContainerDrive.java b/src/main/java/appeng/container/implementations/ContainerDrive.java index 4313a4d32..d6d77f373 100644 --- a/src/main/java/appeng/container/implementations/ContainerDrive.java +++ b/src/main/java/appeng/container/implementations/ContainerDrive.java @@ -37,9 +37,8 @@ public class ContainerDrive extends AEBaseContainer { for( int x = 0; x < 2; x++ ) { - this.addSlotToContainer( - new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive, x + y * 2, 71 + x * 18, 14 + y * 18, this - .getInventoryPlayer() ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.STORAGE_CELLS, drive + .getInternalInventory(), x + y * 2, 71 + x * 18, 14 + y * 18, this.getInventoryPlayer() ) ); } } diff --git a/src/main/java/appeng/container/implementations/ContainerFormationPlane.java b/src/main/java/appeng/container/implementations/ContainerFormationPlane.java index c2f1ae049..b884251b6 100644 --- a/src/main/java/appeng/container/implementations/ContainerFormationPlane.java +++ b/src/main/java/appeng/container/implementations/ContainerFormationPlane.java @@ -20,7 +20,7 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; import appeng.api.config.SecurityPermissions; @@ -58,7 +58,7 @@ public class ContainerFormationPlane extends ContainerUpgradeable final int xo = 8; final int yo = 23 + 6; - final IInventory config = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" ); for( int y = 0; y < 7; y++ ) { for( int x = 0; x < 9; x++ ) @@ -74,7 +74,7 @@ public class ContainerFormationPlane extends ContainerUpgradeable } } - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ) .setNotDraggable() ); this.addSlotToContainer( diff --git a/src/main/java/appeng/container/implementations/ContainerGrinder.java b/src/main/java/appeng/container/implementations/ContainerGrinder.java index d3569093d..051d19428 100644 --- a/src/main/java/appeng/container/implementations/ContainerGrinder.java +++ b/src/main/java/appeng/container/implementations/ContainerGrinder.java @@ -20,6 +20,7 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.items.IItemHandler; import appeng.container.AEBaseContainer; import appeng.container.slot.SlotInaccessible; @@ -35,15 +36,17 @@ public class ContainerGrinder extends AEBaseContainer { super( ip, grinder, null ); - this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 0, 12, 17, this.getInventoryPlayer() ) ); - this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 1, 12 + 18, 17, this.getInventoryPlayer() ) ); - this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, grinder, 2, 12 + 36, 17, this.getInventoryPlayer() ) ); + IItemHandler inv = grinder.getInternalInventory(); - this.addSlotToContainer( new SlotInaccessible( grinder, 6, 80, 40 ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 0, 12, 17, this.getInventoryPlayer() ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 1, 12 + 18, 17, this.getInventoryPlayer() ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.ORE, inv, 2, 12 + 36, 17, this.getInventoryPlayer() ) ); - this.addSlotToContainer( new SlotOutput( grinder, 3, 112, 63, 2 * 16 + 15 ) ); - this.addSlotToContainer( new SlotOutput( grinder, 4, 112 + 18, 63, 2 * 16 + 15 ) ); - this.addSlotToContainer( new SlotOutput( grinder, 5, 112 + 36, 63, 2 * 16 + 15 ) ); + this.addSlotToContainer( new SlotInaccessible( inv, 6, 80, 40 ) ); + + this.addSlotToContainer( new SlotOutput( inv, 3, 112, 63, 2 * 16 + 15 ) ); + this.addSlotToContainer( new SlotOutput( inv, 4, 112 + 18, 63, 2 * 16 + 15 ) ); + this.addSlotToContainer( new SlotOutput( inv, 5, 112 + 36, 63, 2 * 16 + 15 ) ); this.bindPlayerInventory( ip, 0, 176 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerIOPort.java b/src/main/java/appeng/container/implementations/ContainerIOPort.java index 787ff8ea0..f0a69e514 100644 --- a/src/main/java/appeng/container/implementations/ContainerIOPort.java +++ b/src/main/java/appeng/container/implementations/ContainerIOPort.java @@ -20,7 +20,7 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FullnessMode; import appeng.api.config.OperationMode; @@ -59,7 +59,7 @@ public class ContainerIOPort extends ContainerUpgradeable int offX = 19; int offY = 17; - final IInventory cells = this.getUpgradeable().getInventoryByName( "cells" ); + final IItemHandler cells = this.getUpgradeable().getInventoryByName( "cells" ); for( int y = 0; y < 3; y++ ) { @@ -82,7 +82,7 @@ public class ContainerIOPort extends ContainerUpgradeable } } - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ) .setNotDraggable() ); this.addSlotToContainer( diff --git a/src/main/java/appeng/container/implementations/ContainerInscriber.java b/src/main/java/appeng/container/implementations/ContainerInscriber.java index 04d119314..dd6341475 100644 --- a/src/main/java/appeng/container/implementations/ContainerInscriber.java +++ b/src/main/java/appeng/container/implementations/ContainerInscriber.java @@ -22,6 +22,7 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.definitions.IItemDefinition; @@ -60,14 +61,16 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres super( ip, te ); this.ti = te; - this.addSlotToContainer( - this.top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, this.ti, 0, 45, 16, this.getInventoryPlayer() ) ); - this.addSlotToContainer( - this.bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, this.ti, 1, 45, 62, this.getInventoryPlayer() ) ); - this.addSlotToContainer( - this.middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, this.ti, 2, 63, 39, this.getInventoryPlayer() ) ); + IItemHandler inv = te.getInternalInventory(); - this.addSlotToContainer( new SlotOutput( this.ti, 3, 113, 40, -1 ) ); + this.addSlotToContainer( + this.top = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 0, 45, 16, this.getInventoryPlayer() ) ); + this.addSlotToContainer( + this.bottom = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_PLATE, inv, 1, 45, 62, this.getInventoryPlayer() ) ); + this.addSlotToContainer( + this.middle = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.INSCRIBER_INPUT, inv, 2, 63, 39, this.getInventoryPlayer() ) ); + + this.addSlotToContainer( new SlotOutput( inv, 3, 113, 40, -1 ) ); } @Override @@ -112,8 +115,8 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres @Override public boolean isValidForSlot( final Slot s, final ItemStack is ) { - final ItemStack top = this.ti.getStackInSlot( 0 ); - final ItemStack bot = this.ti.getStackInSlot( 1 ); + final ItemStack top = this.ti.getInternalInventory().getStackInSlot( 0 ); + final ItemStack bot = this.ti.getInternalInventory().getStackInSlot( 1 ); if( s == this.middle ) { @@ -132,12 +135,12 @@ public class ContainerInscriber extends ContainerUpgradeable implements IProgres { final boolean matchA = ( top.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and... - ( bot.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( bot, + ( bot.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ); final boolean matchB = ( bot.isEmpty() && !recipe.getTopOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( bot, recipe.getTopOptional().orElse( ItemStack.EMPTY ) ) ) && // and... - ( top.isEmpty() && !recipe.getBottomOptional().isPresent() ) | ( Platform.itemComparisons().isSameItem( top, + ( top.isEmpty() && !recipe.getBottomOptional().isPresent() ) || ( Platform.itemComparisons().isSameItem( top, recipe.getBottomOptional().orElse( ItemStack.EMPTY ) ) ); if( matchA || matchB ) diff --git a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java index 26d602054..ce9ec2c98 100644 --- a/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java +++ b/src/main/java/appeng/container/implementations/ContainerInterfaceTerminal.java @@ -26,10 +26,9 @@ import java.util.Map.Entry; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; -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.config.Settings; import appeng.api.config.YesNo; @@ -49,9 +48,11 @@ import appeng.tile.inventory.AppEngInternalInventory; import appeng.tile.misc.TileInterface; import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; -import appeng.util.inv.AdaptorPlayerHand; -import appeng.util.inv.WrapperInvSlot; +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.AdaptorItemHandler; +import appeng.util.inv.WrapperFilteredItemHandler; +import appeng.util.inv.WrapperRangeItemHandler; +import appeng.util.inv.filter.IAEItemFilter; public final class ContainerInterfaceTerminal extends AEBaseContainer @@ -172,7 +173,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer for( final Entry en : this.diList.entrySet() ) { final InvTracker inv = en.getValue(); - for( int x = 0; x < inv.server.getSizeInventory(); x++ ) + for( int x = 0; x < inv.server.getSlots(); x++ ) { if( this.isDifferent( inv.server.getStackInSlot( x ), inv.client.getStackInSlot( x ) ) ) { @@ -206,12 +207,10 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer final ItemStack is = inv.server.getStackInSlot( slot ); final boolean hasItemInHand = !player.inventory.getItemStack().isEmpty(); - final InventoryAdaptor playerHand = new AdaptorPlayerHand( player ); + final InventoryAdaptor playerHand = InventoryAdaptor.getAdaptor( player ); - final WrapperInvSlot slotInv = new PatternInvSlot( inv.server ); - - final IInventory theSlot = slotInv.getWrapper( slot ); - final InventoryAdaptor interfaceSlot = new AdaptorIInventory( theSlot ); + final IItemHandler theSlot = new WrapperFilteredItemHandler( new WrapperRangeItemHandler( inv.server, slot, slot + 1 ), new PatternSlotFilter() ); + final InventoryAdaptor interfaceSlot = new AdaptorItemHandler( theSlot ); switch( action ) { @@ -229,7 +228,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer inSlot = inSlot.copy(); final ItemStack inHand = player.inventory.getItemStack().copy(); - theSlot.setInventorySlotContents( 0, ItemStack.EMPTY ); + ItemHandlerUtil.setStackInSlot( theSlot, 0, ItemStack.EMPTY ); player.inventory.setItemStack( ItemStack.EMPTY ); player.inventory.setItemStack( interfaceSlot.addItems( inHand.copy() ) ); @@ -241,14 +240,13 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer else { player.inventory.setItemStack( inHand ); - theSlot.setInventorySlotContents( 0, inSlot ); + ItemHandlerUtil.setStackInSlot( theSlot, 0, inSlot ); } } } else { - final IInventory mySlot = slotInv.getWrapper( slot ); - mySlot.setInventorySlotContents( 0, playerHand.addItems( mySlot.getStackInSlot( 0 ) ) ); + ItemHandlerUtil.setStackInSlot( theSlot, 0, playerHand.addItems( theSlot.getStackInSlot( 0 ) ) ); } break; @@ -282,17 +280,17 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer break; case SHIFT_CLICK: - final IInventory mySlot = slotInv.getWrapper( slot ); - final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); - mySlot.setInventorySlotContents( 0, playerInv.addItems( mySlot.getStackInSlot( 0 ) ) ); + final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( player ); + + ItemHandlerUtil.setStackInSlot( theSlot, 0, playerInv.addItems( theSlot.getStackInSlot( 0 ) ) ); break; case MOVE_REGION: - final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); - for( int x = 0; x < inv.server.getSizeInventory(); x++ ) + final InventoryAdaptor playerInvAd = InventoryAdaptor.getAdaptor( player ); + for( int x = 0; x < inv.server.getSlots(); x++ ) { - inv.server.setInventorySlotContents( x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) ); + ItemHandlerUtil.setStackInSlot( inv.server, x, playerInvAd.addItems( inv.server.getStackInSlot( x ) ) ); } break; @@ -351,7 +349,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer { final InvTracker inv = en.getValue(); this.byId.put( inv.which, inv ); - this.addItems( data, inv, 0, inv.server.getSizeInventory() ); + this.addItems( data, inv, 0, inv.server.getSlots() ); } } @@ -388,7 +386,7 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer final ItemStack is = inv.server.getStackInSlot( x + offset ); // "update" client side. - inv.client.setInventorySlotContents( x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() ); + ItemHandlerUtil.setStackInSlot( inv.client, x + offset, is.isEmpty() ? ItemStack.EMPTY : is.copy() ); if( !is.isEmpty() ) { @@ -407,30 +405,30 @@ public final class ContainerInterfaceTerminal extends AEBaseContainer private final long sortBy; private final long which = autoBase++; private final String unlocalizedName; - private final IInventory client; - private final IInventory server; + private final IItemHandler client; + private final IItemHandler server; - public InvTracker( final DualityInterface dual, final IInventory patterns, final String unlocalizedName ) + public InvTracker( final DualityInterface dual, final IItemHandler patterns, final String unlocalizedName ) { this.server = patterns; - this.client = new AppEngInternalInventory( null, this.server.getSizeInventory() ); + this.client = new AppEngInternalInventory( null, this.server.getSlots() ); this.unlocalizedName = unlocalizedName; this.sortBy = dual.getSortValue(); } } - private static class PatternInvSlot extends WrapperInvSlot + private static class PatternSlotFilter implements IAEItemFilter { - - public PatternInvSlot( final IInventory inv ) + @Override + public boolean allowExtract( IItemHandler inv, int slot, int amount ) { - super( inv ); + return true; } @Override - public boolean isItemValid( final ItemStack itemstack ) + public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack ) { - return !itemstack.isEmpty() && itemstack.getItem() instanceof ItemEncodedPattern; + return !stack.isEmpty() && stack.getItem() instanceof ItemEncodedPattern; } } } diff --git a/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java index ed24f869b..93903bbcd 100644 --- a/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java +++ b/src/main/java/appeng/container/implementations/ContainerLevelEmitter.java @@ -22,9 +22,9 @@ package appeng.container.implementations; import net.minecraft.client.gui.GuiTextField; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; import appeng.api.config.LevelType; @@ -75,7 +75,7 @@ public class ContainerLevelEmitter extends ContainerUpgradeable @Override protected void setupConfig() { - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); if( this.availableUpgrades() > 0 ) { this.addSlotToContainer( @@ -101,7 +101,7 @@ public class ContainerLevelEmitter extends ContainerUpgradeable .setNotDraggable() ); } - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" ); final int y = 40; final int x = 80 + 44; this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) ); diff --git a/src/main/java/appeng/container/implementations/ContainerMAC.java b/src/main/java/appeng/container/implementations/ContainerMAC.java index 1e5fe6fd7..25fe1d9f5 100644 --- a/src/main/java/appeng/container/implementations/ContainerMAC.java +++ b/src/main/java/appeng/container/implementations/ContainerMAC.java @@ -20,9 +20,9 @@ package appeng.container.implementations; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.RedstoneMode; import appeng.api.config.SecurityPermissions; @@ -54,7 +54,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi public boolean isValidItemForSlot( final int slotIndex, final ItemStack i ) { - final IInventory mac = this.getUpgradeable().getInventoryByName( "mac" ); + final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" ); final ItemStack is = mac.getStackInSlot( 10 ); if( is.isEmpty() ) @@ -88,7 +88,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi int offX = 29; int offY = 30; - final IInventory mac = this.getUpgradeable().getInventoryByName( "mac" ); + final IItemHandler mac = this.getUpgradeable().getInventoryByName( "mac" ); for( int y = 0; y < 3; y++ ) { @@ -109,7 +109,7 @@ public class ContainerMAC extends ContainerUpgradeable implements IProgressProvi offX = 122; offY = 17; - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ) .setNotDraggable() ); this.addSlotToContainer( diff --git a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java index 592e00ed4..0a024b052 100644 --- a/src/main/java/appeng/container/implementations/ContainerNetworkTool.java +++ b/src/main/java/appeng/container/implementations/ContainerNetworkTool.java @@ -49,9 +49,8 @@ public class ContainerNetworkTool extends AEBaseContainer { for( int x = 0; x < 3; x++ ) { - this.addSlotToContainer( - ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te, y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this - .getInventoryPlayer() ) ) ); + this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, te + .getInventory(), y * 3 + x, 80 - 18 + x * 18, 37 - 18 + y * 18, this.getInventoryPlayer() ) ) ); } } diff --git a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java index 44d731905..2415b2be3 100644 --- a/src/main/java/appeng/container/implementations/ContainerPatternTerm.java +++ b/src/main/java/appeng/container/implementations/ContainerPatternTerm.java @@ -27,7 +27,6 @@ import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCraftResult; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.Slot; @@ -38,7 +37,8 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.EnumFacing; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerInvWrapper; import appeng.api.AEApi; import appeng.api.config.Actionable; @@ -61,11 +61,12 @@ import appeng.helpers.IContainerCraftingPacket; import appeng.items.storage.ItemViewCell; import appeng.parts.reporting.PartPatternTerminal; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; +import appeng.util.inv.AdaptorItemHandler; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; +import appeng.util.inv.WrapperCursorItemHandler; import appeng.util.item.AEItemStack; @@ -74,7 +75,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA private final PartPatternTerminal patternTerminal; private final AppEngInternalInventory cOut = new AppEngInternalInventory( null, 1 ); - private final IInventory crafting; + private final IItemHandler crafting; private final SlotFakeCraftingMatrix[] craftingSlots = new SlotFakeCraftingMatrix[9]; private final OptionalSlotFake[] outputSlots = new OptionalSlotFake[3]; private final SlotPatternTerm craftSlot; @@ -90,8 +91,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA super( ip, monitorable, false ); this.patternTerminal = (PartPatternTerminal) monitorable; - final IInventory patternInv = this.getPatternTerminal().getInventoryByName( "pattern" ); - final IInventory output = this.getPatternTerminal().getInventoryByName( "output" ); + final IItemHandler patternInv = this.getPatternTerminal().getInventoryByName( "pattern" ); + final IItemHandler output = this.getPatternTerminal().getInventoryByName( "output" ); this.crafting = this.getPatternTerminal().getInventoryByName( "crafting" ); @@ -166,7 +167,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA } final ItemStack is = CraftingManager.findMatchingResult( ic, this.getPlayerInv().player.world ); - this.cOut.setInventorySlotContents( 0, is ); + this.cOut.setStackInSlot( 0, is ); return is; } @@ -177,7 +178,7 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA } @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 ) { } @@ -355,8 +356,8 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA if( packetPatternSlot.slotItem != null && this.getCellInventory() != null ) { final IAEItemStack out = packetPatternSlot.slotItem.copy(); - InventoryAdaptor inv = new AdaptorPlayerHand( this.getPlayerInv().player ); - final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player, EnumFacing.UP ); + InventoryAdaptor inv = new AdaptorItemHandler( new WrapperCursorItemHandler( this.getPlayerInv().player.inventory ) ); + final InventoryAdaptor playerInv = InventoryAdaptor.getAdaptor( this.getPlayerInv().player ); if( packetPatternSlot.shift ) { @@ -527,11 +528,11 @@ public class ContainerPatternTerm extends ContainerMEMonitorable implements IAEA } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "player" ) ) { - return this.getInventoryPlayer(); + return new PlayerInvWrapper( this.getInventoryPlayer() ); } return this.getPatternTerminal().getInventoryByName( name ); } diff --git a/src/main/java/appeng/container/implementations/ContainerQNB.java b/src/main/java/appeng/container/implementations/ContainerQNB.java index 8386d8726..876740ad1 100644 --- a/src/main/java/appeng/container/implementations/ContainerQNB.java +++ b/src/main/java/appeng/container/implementations/ContainerQNB.java @@ -33,9 +33,8 @@ public class ContainerQNB extends AEBaseContainer { super( ip, quantumBridge, null ); - this.addSlotToContainer( - ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge, 0, 80, 37, this.getInventoryPlayer() ) ) - .setStackLimit( 1 ) ); + this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.QE_SINGULARITY, quantumBridge + .getInternalInventory(), 0, 80, 37, this.getInventoryPlayer() ) ).setStackLimit( 1 ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java index e2a907f2b..c5d6ac455 100644 --- a/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java +++ b/src/main/java/appeng/container/implementations/ContainerQuartzKnife.java @@ -19,34 +19,31 @@ package appeng.container.implementations; +import javax.annotation.Nonnull; + import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.container.AEBaseContainer; -import appeng.container.slot.QuartzKnifeOutput; +import appeng.container.slot.SlotOutput; import appeng.container.slot.SlotRestrictedInput; import appeng.items.contents.QuartzKnifeObj; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; -public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngInventory, IInventory +public class ContainerQuartzKnife extends AEBaseContainer { private final QuartzKnifeObj toolInv; - private final AppEngInternalInventory inSlot = new AppEngInternalInventory( this, 1 ); - private final SlotRestrictedInput metals; - private final QuartzKnifeOutput output; + private final IItemHandler inSlot = new AppEngInternalInventory( null, 1, 1 ); private String myName = ""; public ContainerQuartzKnife( final InventoryPlayer ip, final QuartzKnifeObj te ) @@ -54,11 +51,8 @@ public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngIn super( ip, null, null ); this.toolInv = te; - this.metals = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ); - this.addSlotToContainer( this.metals ); - - this.output = new QuartzKnifeOutput( this, 0, 134, 44, -1 ); - this.addSlotToContainer( this.output ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.METAL_INGOTS, this.inSlot, 0, 94, 44, ip ) ); + this.addSlotToContainer( new QuartzKniveSlot( this.inSlot, 0, 134, 44, -1 ) ); this.lockPlayerInventorySlot( ip.currentItem ); @@ -106,179 +100,73 @@ public class ContainerQuartzKnife extends AEBaseContainer implements IAEAppEngIn } } - @Override - public void saveChanges() + private class QuartzKniveSlot extends SlotOutput { - - } - - @Override - public void onChangeInventory( final IInventory inv, final int slot, final InvOperation mc, final ItemStack removedStack, final ItemStack newStack ) - { - - } - - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot( final int var1 ) - { - final ItemStack input = this.inSlot.getStackInSlot( 0 ); - if( input == ItemStack.EMPTY ) + QuartzKniveSlot( IItemHandler a, int b, int c, int d, int i ) { + super( a, b, c, d, i ); + } + + @Override + public ItemStack getStack() + { + final IItemHandler baseInv = getItemHandler(); + final ItemStack input = baseInv.getStackInSlot( 0 ); + if( input == ItemStack.EMPTY ) + { + return ItemStack.EMPTY; + } + + if( SlotRestrictedInput.isMetalIngot( input ) ) + { + if( ContainerQuartzKnife.this.myName.length() > 0 ) + { + return AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).map( namePressStack -> + { + final NBTTagCompound compound = Platform.openNbtData( namePressStack ); + compound.setString( "InscribeName", ContainerQuartzKnife.this.myName ); + + return namePressStack; + } ).orElse( ItemStack.EMPTY ); + } + } return ItemStack.EMPTY; } - if( SlotRestrictedInput.isMetalIngot( input ) ) + @Override + @Nonnull + public ItemStack decrStackSize( int amount ) { - if( this.myName.length() > 0 ) + ItemStack ret = getStack(); + if( !ret.isEmpty() ) { - return AEApi.instance().definitions().materials().namePress().maybeStack( 1 ).map( namePressStack -> + makePlate(); + } + return ret; + } + + @Override + public void putStack( final ItemStack stack ) + { + if( stack.isEmpty() ) + { + makePlate(); + } + } + + private void makePlate() + { + if( !getItemHandler().extractItem( 0, 1, false ).isEmpty() ) + { + final ItemStack item = ContainerQuartzKnife.this.toolInv.getItemStack(); + item.damageItem( 1, getPlayerInv().player ); + + if( item.getCount() == 0 ) { - final NBTTagCompound compound = Platform.openNbtData( namePressStack ); - compound.setString( "InscribeName", this.myName ); - - return namePressStack; - } ).orElse( ItemStack.EMPTY ); + getPlayerInv().mainInventory.add( getPlayerInv().currentItem, ItemStack.EMPTY ); + MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( getPlayerInv().player, item, null ) ); + } } } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack decrStackSize( final int var1, final int var2 ) - { - final ItemStack is = this.getStackInSlot( 0 ); - if( !is.isEmpty() ) - { - if( this.makePlate() ) - { - return is; - } - } - return ItemStack.EMPTY; - } - - private boolean makePlate() - { - if( this.inSlot.decrStackSize( 0, 1 ) != null ) - { - final ItemStack item = this.toolInv.getItemStack(); - item.damageItem( 1, this.getPlayerInv().player ); - - if( item.getCount() == 0 ) - { - this.getPlayerInv().mainInventory.add( this.getPlayerInv().currentItem, ItemStack.EMPTY ); - MinecraftForge.EVENT_BUS.post( new PlayerDestroyItemEvent( this.getPlayerInv().player, item, null ) ); - } - - return true; - } - return false; - } - - @Override - public ItemStack removeStackFromSlot( final int var1 ) - { - return ItemStack.EMPTY; - } - - @Override - public void setInventorySlotContents( final int var1, final ItemStack var2 ) - { - if( var2.isEmpty() && Platform.isServer() ) - { - this.makePlate(); - } - } - - @Override - public String getName() - { - return "Quartz Knife Output"; - } - - @Override - public boolean hasCustomName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public void markDirty() - { - - } - - @Override - public boolean isUsableByPlayer( EntityPlayer player ) - { - return false; - } - - @Override - public void openInventory( final EntityPlayer player ) - { - - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - - } - - @Override - public boolean isItemValidForSlot( final int var1, final ItemStack var2 ) - { - return false; - } - - @Override - public ITextComponent getDisplayName() - { - return null; - } - - @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() - { - this.inSlot.setInventorySlotContents( 0, ItemStack.EMPTY ); - } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; } } diff --git a/src/main/java/appeng/container/implementations/ContainerSecurityStation.java b/src/main/java/appeng/container/implementations/ContainerSecurityStation.java index 49a35202a..158d6d4df 100644 --- a/src/main/java/appeng/container/implementations/ContainerSecurityStation.java +++ b/src/main/java/appeng/container/implementations/ContainerSecurityStation.java @@ -22,8 +22,8 @@ package appeng.container.implementations; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.inventory.IContainerListener; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.SecurityPermissions; @@ -35,9 +35,9 @@ import appeng.container.guisync.GuiSync; import appeng.container.slot.SlotOutput; import appeng.container.slot.SlotRestrictedInput; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.tile.misc.TileSecurityStation; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; public class ContainerSecurityStation extends ContainerMEMonitorable implements IAEAppEngInventory @@ -142,7 +142,7 @@ public class ContainerSecurityStation extends ContainerMEMonitorable implements } @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( !this.wirelessOut.getHasStack() ) { diff --git a/src/main/java/appeng/container/implementations/ContainerSkyChest.java b/src/main/java/appeng/container/implementations/ContainerSkyChest.java index 1417fe212..9c838f346 100644 --- a/src/main/java/appeng/container/implementations/ContainerSkyChest.java +++ b/src/main/java/appeng/container/implementations/ContainerSkyChest.java @@ -41,7 +41,7 @@ public class ContainerSkyChest extends AEBaseContainer { for( int x = 0; x < 9; x++ ) { - this.addSlotToContainer( new SlotNormal( this.chest, y * 9 + x, 8 + 18 * x, 24 + 18 * y ) ); + this.addSlotToContainer( new SlotNormal( this.chest.getInternalInventory(), y * 9 + x, 8 + 18 * x, 24 + 18 * y ) ); } } diff --git a/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java index b735693af..6b8c53dbb 100644 --- a/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java +++ b/src/main/java/appeng/container/implementations/ContainerSpatialIOPort.java @@ -57,9 +57,10 @@ public class ContainerSpatialIOPort extends AEBaseContainer this.network = spatialIOPort.getGridNode( AEPartLocation.INTERNAL ).getGrid(); } + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort + .getInternalInventory(), 0, 52, 48, this.getInventoryPlayer() ) ); this.addSlotToContainer( - new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS, spatialIOPort, 0, 52, 48, this.getInventoryPlayer() ) ); - this.addSlotToContainer( new SlotOutput( spatialIOPort, 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) ); + new SlotOutput( spatialIOPort.getInternalInventory(), 1, 113, 48, SlotRestrictedInput.PlacableItemType.SPATIAL_STORAGE_CELLS.IIcon ) ); this.bindPlayerInventory( ip, 0, 197 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerStorageBus.java b/src/main/java/appeng/container/implementations/ContainerStorageBus.java index 156a1c754..17984377c 100644 --- a/src/main/java/appeng/container/implementations/ContainerStorageBus.java +++ b/src/main/java/appeng/container/implementations/ContainerStorageBus.java @@ -22,8 +22,8 @@ package appeng.container.implementations; import java.util.Iterator; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.AccessRestriction; @@ -41,6 +41,7 @@ import appeng.container.slot.SlotFakeTypeOnly; import appeng.container.slot.SlotRestrictedInput; import appeng.parts.misc.PartStorageBus; import appeng.util.Platform; +import appeng.util.helpers.ItemHandlerUtil; import appeng.util.iterators.NullIterator; @@ -73,7 +74,7 @@ public class ContainerStorageBus extends ContainerUpgradeable final int xo = 8; final int yo = 23 + 6; - final IInventory config = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler config = this.getUpgradeable().getInventoryByName( "config" ); for( int y = 0; y < 7; y++ ) { for( int x = 0; x < 9; x++ ) @@ -89,7 +90,7 @@ public class ContainerStorageBus extends ContainerUpgradeable } } - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, upgrades, 0, 187, 8, this.getInventoryPlayer() ) ) .setNotDraggable() ); this.addSlotToContainer( @@ -143,17 +144,13 @@ public class ContainerStorageBus extends ContainerUpgradeable public void clear() { - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); - for( int x = 0; x < inv.getSizeInventory(); x++ ) - { - inv.setInventorySlotContents( x, ItemStack.EMPTY ); - } + ItemHandlerUtil.clear( this.getUpgradeable().getInventoryByName( "config" ) ); this.detectAndSendChanges(); } public void partition() { - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" ); final IMEInventory cellInv = this.storageBus.getInternalHandler(); @@ -164,17 +161,17 @@ public class ContainerStorageBus extends ContainerUpgradeable i = list.iterator(); } - for( int x = 0; x < inv.getSizeInventory(); x++ ) + for( int x = 0; x < inv.getSlots(); x++ ) { if( i.hasNext() && this.isSlotEnabled( ( x / 9 ) - 2 ) ) { final ItemStack g = i.next().getItemStack(); g.setCount( 1 ); - inv.setInventorySlotContents( x, g ); + ItemHandlerUtil.setStackInSlot( inv, x, g ); } else { - inv.setInventorySlotContents( x, ItemStack.EMPTY ); + ItemHandlerUtil.setStackInSlot( inv, x, ItemStack.EMPTY ); } } diff --git a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java index 4a0bdf425..c876d17b0 100644 --- a/src/main/java/appeng/container/implementations/ContainerUpgradeable.java +++ b/src/main/java/appeng/container/implementations/ContainerUpgradeable.java @@ -25,6 +25,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; import appeng.api.config.RedstoneMode; @@ -112,9 +113,8 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl { for( int u = 0; u < 3; u++ ) { - this.addSlotToContainer( - ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory, u + v * 3, 186 + u * 18, this - .getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() ); + this.addSlotToContainer( ( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.UPGRADES, this.tbInventory + .getInternalInventory(), u + v * 3, 186 + u * 18, this.getHeight() - 82 + v * 18, this.getInventoryPlayer() ) ).setPlayerSide() ); } } } @@ -138,7 +138,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl { this.setupUpgrades(); - final IInventory inv = this.getUpgradeable().getInventoryByName( "config" ); + final IItemHandler inv = this.getUpgradeable().getInventoryByName( "config" ); final int y = 40; final int x = 80; this.addSlotToContainer( new SlotFakeTypeOnly( inv, 0, x, y ) ); @@ -159,7 +159,7 @@ public class ContainerUpgradeable extends AEBaseContainer implements IOptionalSl protected void setupUpgrades() { - final IInventory upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); + final IItemHandler upgrades = this.getUpgradeable().getInventoryByName( "upgrades" ); if( this.availableUpgrades() > 0 ) { this.addSlotToContainer( diff --git a/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java index 1636304f0..56d19adbb 100644 --- a/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java +++ b/src/main/java/appeng/container/implementations/ContainerVibrationChamber.java @@ -45,7 +45,8 @@ public class ContainerVibrationChamber extends AEBaseContainer implements IProgr super( ip, vibrationChamber, null ); this.vibrationChamber = vibrationChamber; - this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber, 0, 80, 37, this.getInventoryPlayer() ) ); + this.addSlotToContainer( new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.FUEL, vibrationChamber.getInternalInventory(), 0, 80, 37, this + .getInventoryPlayer() ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/implementations/ContainerWireless.java b/src/main/java/appeng/container/implementations/ContainerWireless.java index a6afba832..babe4d180 100644 --- a/src/main/java/appeng/container/implementations/ContainerWireless.java +++ b/src/main/java/appeng/container/implementations/ContainerWireless.java @@ -43,9 +43,8 @@ public class ContainerWireless extends AEBaseContainer super( ip, te, null ); this.wirelessTerminal = te; - this.addSlotToContainer( - this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal, 0, 80, 47, this - .getInventoryPlayer() ) ); + this.addSlotToContainer( this.boosterSlot = new SlotRestrictedInput( SlotRestrictedInput.PlacableItemType.RANGE_BOOSTER, this.wirelessTerminal + .getInternalInventory(), 0, 80, 47, this.getInventoryPlayer() ) ); this.bindPlayerInventory( ip, 0, 166 - /* height of player inventory */82 ); } diff --git a/src/main/java/appeng/container/slot/AppEngCraftingSlot.java b/src/main/java/appeng/container/slot/AppEngCraftingSlot.java index eb7f22419..be48b3e55 100644 --- a/src/main/java/appeng/container/slot/AppEngCraftingSlot.java +++ b/src/main/java/appeng/container/slot/AppEngCraftingSlot.java @@ -20,11 +20,14 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.util.NonNullList; +import net.minecraftforge.items.IItemHandler; + +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.WrapperInvItemHandler; public class AppEngCraftingSlot extends AppEngSlot @@ -33,7 +36,7 @@ public class AppEngCraftingSlot extends AppEngSlot /** * The craft matrix inventory linked to this result slot. */ - private final IInventory craftMatrix; + private final IItemHandler craftMatrix; /** * The player that is using the GUI where this slot resides. @@ -45,7 +48,7 @@ public class AppEngCraftingSlot extends AppEngSlot */ private int amountCrafted; - public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IInventory par2IInventory, final IInventory par3IInventory, final int par4, final int par5, final int par6 ) + public AppEngCraftingSlot( final EntityPlayer par1EntityPlayer, final IItemHandler par2IInventory, final IItemHandler par3IInventory, final int par4, final int par5, final int par6 ) { super( par3IInventory, par4, par5, par6 ); this.thePlayer = par1EntityPlayer; @@ -136,22 +139,19 @@ public class AppEngCraftingSlot extends AppEngSlot @Override public ItemStack onTake( final EntityPlayer playerIn, final ItemStack stack ) { - net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, this.craftMatrix ); + net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerCraftingEvent( playerIn, stack, new WrapperInvItemHandler( this.craftMatrix ) ); this.onCrafting( stack ); net.minecraftforge.common.ForgeHooks.setCraftingPlayer( playerIn ); final InventoryCrafting ic = new InventoryCrafting( this.getContainer(), 3, 3 ); - for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ ) + for( int x = 0; x < this.craftMatrix.getSlots(); x++ ) { ic.setInventorySlotContents( x, this.craftMatrix.getStackInSlot( x ) ); } final NonNullList aitemstack = CraftingManager.getRemainingItems( ic, playerIn.world ); - for( int x = 0; x < this.craftMatrix.getSizeInventory(); x++ ) - { - this.craftMatrix.setInventorySlotContents( x, ic.getStackInSlot( x ) ); - } + ItemHandlerUtil.copy( ic, this.craftMatrix, false ); net.minecraftforge.common.ForgeHooks.setCraftingPlayer( null ); @@ -162,14 +162,14 @@ public class AppEngCraftingSlot extends AppEngSlot if( !itemstack1.isEmpty() ) { - this.craftMatrix.decrStackSize( i, 1 ); + this.craftMatrix.extractItem( i, 1, false ); } if( !itemstack2.isEmpty() ) { if( this.craftMatrix.getStackInSlot( i ).isEmpty() ) { - this.craftMatrix.setInventorySlotContents( i, itemstack2 ); + ItemHandlerUtil.setStackInSlot( this.craftMatrix, i, itemstack2 ); } else if( !this.thePlayer.inventory.addItemStackToInventory( itemstack2 ) ) { diff --git a/src/main/java/appeng/container/slot/AppEngSlot.java b/src/main/java/appeng/container/slot/AppEngSlot.java index 976a3af76..244b6e1e0 100644 --- a/src/main/java/appeng/container/slot/AppEngSlot.java +++ b/src/main/java/appeng/container/slot/AppEngSlot.java @@ -23,17 +23,22 @@ import javax.annotation.Nonnull; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; +import net.minecraft.inventory.InventoryBasic; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.container.AEBaseContainer; -import appeng.tile.inventory.AppEngInternalInventory; +import appeng.util.helpers.ItemHandlerUtil; public class AppEngSlot extends Slot { + private static IInventory emptyInventory = new InventoryBasic( "[Null]", true, 0 ); + private final IItemHandler itemHandler; + private final int index; private final int defX; private final int defY; @@ -44,9 +49,12 @@ public class AppEngSlot extends Slot private hasCalculatedValidness isValid; private boolean isDisplay = false; - public AppEngSlot( final IInventory inv, final int idx, final int x, final int y ) + public AppEngSlot( final IItemHandler inv, final int idx, final int x, final int y ) { - super( inv, idx, x, y ); + super( emptyInventory, idx, x, y ); + this.itemHandler = inv; + this.index = idx; + this.defX = x; this.defY = y; this.setIsValid( hasCalculatedValidness.NotAvailable ); @@ -75,11 +83,11 @@ public class AppEngSlot extends Slot } @Override - public boolean isItemValid( final ItemStack par1ItemStack ) + public boolean isItemValid( @Nonnull final ItemStack par1ItemStack ) { if( this.isSlotEnabled() ) { - return super.isItemValid( par1ItemStack ); + return ItemHandlerUtil.isItemValidForSlot( this.itemHandler, this.index, par1ItemStack ); } return false; } @@ -93,7 +101,7 @@ public class AppEngSlot extends Slot return ItemStack.EMPTY; } - if( this.inventory.getSizeInventory() <= this.getSlotIndex() ) + if( this.itemHandler.getSlots() <= this.getSlotIndex() ) { return ItemStack.EMPTY; } @@ -103,15 +111,17 @@ public class AppEngSlot extends Slot this.setDisplay( false ); return this.getDisplayStack(); } - return super.getStack(); + + return this.itemHandler.getStackInSlot( index ); } @Override - public void putStack( final ItemStack par1ItemStack ) + public void putStack( final ItemStack stack ) { if( this.isSlotEnabled() ) { - super.putStack( par1ItemStack ); + ItemHandlerUtil.setStackInSlot( this.itemHandler, index, stack ); + this.onSlotChanged(); if( this.getContainer() != null ) { @@ -120,31 +130,53 @@ public class AppEngSlot extends Slot } } + public IItemHandler getItemHandler() + { + return this.itemHandler; + } + @Override public void onSlotChanged() { - if( this.inventory instanceof AppEngInternalInventory ) - { - ( (AppEngInternalInventory) this.inventory ).markDirty( this.getSlotIndex() ); - } - else - { - super.onSlotChanged(); - } - + ItemHandlerUtil.markDirty( this.itemHandler, this.index ); this.setIsValid( hasCalculatedValidness.NotAvailable ); } + @Override + public int getSlotStackLimit() + { + return this.itemHandler.getSlotLimit( this.index ); + } + + @Override + public int getItemStackLimit( @Nonnull ItemStack stack ) + { + return Math.min( getSlotStackLimit(), stack.getMaxStackSize() ); + } + @Override public boolean canTakeStack( final EntityPlayer par1EntityPlayer ) { if( this.isSlotEnabled() ) { - return super.canTakeStack( par1EntityPlayer ); + return !this.itemHandler.extractItem( index, 1, true ).isEmpty(); } return false; } + @Override + @Nonnull + public ItemStack decrStackSize( int amount ) + { + return this.itemHandler.extractItem( index, amount, false ); + } + + @Override + public boolean isSameInventory( Slot other ) + { + return other instanceof AppEngSlot && ( (AppEngSlot) other ).itemHandler == this.itemHandler; + } + @Override @SideOnly( Side.CLIENT ) public boolean isEnabled() @@ -159,7 +191,7 @@ public class AppEngSlot extends Slot public ItemStack getDisplayStack() { - return super.getStack(); + return this.itemHandler.getStackInSlot( index ); } public float getOpacityOfIcon() diff --git a/src/main/java/appeng/container/slot/OptionalSlotFake.java b/src/main/java/appeng/container/slot/OptionalSlotFake.java index 3f1150b31..df1af41f2 100644 --- a/src/main/java/appeng/container/slot/OptionalSlotFake.java +++ b/src/main/java/appeng/container/slot/OptionalSlotFake.java @@ -21,8 +21,8 @@ package appeng.container.slot; import javax.annotation.Nonnull; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class OptionalSlotFake extends SlotFake @@ -34,7 +34,7 @@ public class OptionalSlotFake extends SlotFake private final IOptionalSlotHost host; private boolean renderDisabled = true; - public OptionalSlotFake( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) + public OptionalSlotFake( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) { super( inv, idx, x + offX * 18, y + offY * 18 ); this.srcX = x; diff --git a/src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java b/src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java index 3be6ad6a2..7c86c8b53 100644 --- a/src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java +++ b/src/main/java/appeng/container/slot/OptionalSlotFakeTypeOnly.java @@ -19,14 +19,14 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class OptionalSlotFakeTypeOnly extends OptionalSlotFake { - public OptionalSlotFakeTypeOnly( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) + public OptionalSlotFakeTypeOnly( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) { super( inv, containerBus, idx, x, y, offX, offY, groupNum ); } diff --git a/src/main/java/appeng/container/slot/OptionalSlotNormal.java b/src/main/java/appeng/container/slot/OptionalSlotNormal.java index 30d441154..426396dbe 100644 --- a/src/main/java/appeng/container/slot/OptionalSlotNormal.java +++ b/src/main/java/appeng/container/slot/OptionalSlotNormal.java @@ -19,7 +19,7 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class OptionalSlotNormal extends AppEngSlot @@ -28,7 +28,7 @@ public class OptionalSlotNormal extends AppEngSlot private final int groupNum; private final IOptionalSlotHost host; - public OptionalSlotNormal( final IInventory inv, final IOptionalSlotHost containerBus, final int slot, final int xPos, final int yPos, final int groupNum ) + public OptionalSlotNormal( final IItemHandler inv, final IOptionalSlotHost containerBus, final int slot, final int xPos, final int yPos, final int groupNum ) { super( inv, slot, xPos, yPos ); this.groupNum = groupNum; diff --git a/src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java b/src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java index 59d439a24..c82406bd6 100644 --- a/src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/OptionalSlotRestrictedInput.java @@ -20,7 +20,7 @@ package appeng.container.slot; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class OptionalSlotRestrictedInput extends SlotRestrictedInput @@ -29,7 +29,7 @@ public class OptionalSlotRestrictedInput extends SlotRestrictedInput private final int groupNum; private final IOptionalSlotHost host; - public OptionalSlotRestrictedInput( final PlacableItemType valid, final IInventory i, final IOptionalSlotHost host, final int slotIndex, final int x, final int y, final int grpNum, final InventoryPlayer invPlayer ) + public OptionalSlotRestrictedInput( final PlacableItemType valid, final IItemHandler i, final IOptionalSlotHost host, final int slotIndex, final int x, final int y, final int grpNum, final InventoryPlayer invPlayer ) { super( valid, i, slotIndex, x, y, invPlayer ); this.groupNum = grpNum; diff --git a/src/main/java/appeng/container/slot/SlotCraftingMatrix.java b/src/main/java/appeng/container/slot/SlotCraftingMatrix.java index e87320a52..e33dff30f 100644 --- a/src/main/java/appeng/container/slot/SlotCraftingMatrix.java +++ b/src/main/java/appeng/container/slot/SlotCraftingMatrix.java @@ -19,34 +19,38 @@ package appeng.container.slot; -import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import appeng.container.AEBaseContainer; +import appeng.util.inv.WrapperInvItemHandler; public class SlotCraftingMatrix extends AppEngSlot { + private final AEBaseContainer c; + private final IInventory wrappedInventory; - private final Container c; - - public SlotCraftingMatrix( final Container c, final IInventory par1iInventory, final int par2, final int par3, final int par4 ) + public SlotCraftingMatrix( final AEBaseContainer c, final IItemHandler par1iInventory, final int par2, final int par3, final int par4 ) { super( par1iInventory, par2, par3, par4 ); this.c = c; + this.wrappedInventory = new WrapperInvItemHandler( par1iInventory ); } @Override public void clearStack() { super.clearStack(); - this.c.onCraftMatrixChanged( this.inventory ); + this.c.onCraftMatrixChanged( this.wrappedInventory ); } @Override public void putStack( final ItemStack par1ItemStack ) { super.putStack( par1ItemStack ); - this.c.onCraftMatrixChanged( this.inventory ); + this.c.onCraftMatrixChanged( this.wrappedInventory ); } @Override @@ -59,7 +63,7 @@ public class SlotCraftingMatrix extends AppEngSlot public ItemStack decrStackSize( final int par1 ) { final ItemStack is = super.decrStackSize( par1 ); - this.c.onCraftMatrixChanged( this.inventory ); + this.c.onCraftMatrixChanged( this.wrappedInventory ); return is; } } diff --git a/src/main/java/appeng/container/slot/SlotCraftingTerm.java b/src/main/java/appeng/container/slot/SlotCraftingTerm.java index 20911fdea..e3dffbe38 100644 --- a/src/main/java/appeng/container/slot/SlotCraftingTerm.java +++ b/src/main/java/appeng/container/slot/SlotCraftingTerm.java @@ -24,12 +24,12 @@ import java.util.Arrays; import java.util.List; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.util.math.BlockPos; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.Actionable; import appeng.api.networking.energy.IEnergySource; @@ -44,22 +44,25 @@ import appeng.helpers.InventoryAction; import appeng.items.storage.ItemViewCell; import appeng.util.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorPlayerHand; +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.AdaptorItemHandler; +import appeng.util.inv.WrapperCursorItemHandler; +import appeng.util.inv.WrapperInvItemHandler; import appeng.util.item.AEItemStack; public class SlotCraftingTerm extends AppEngCraftingSlot { - private final IInventory craftInv; - private final IInventory pattern; + private final IItemHandler craftInv; + private final IItemHandler pattern; private final BaseActionSource mySrc; private final IEnergySource energySrc; private final IStorageMonitorable storage; private final IContainerCraftingPacket container; - public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IInventory cMatrix, final IInventory secondMatrix, final IInventory output, final int x, final int y, final IContainerCraftingPacket ccp ) + public SlotCraftingTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IContainerCraftingPacket ccp ) { super( player, cMatrix, output, 0, x, y ); this.energySrc = energySrc; @@ -70,7 +73,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot this.container = ccp; } - public IInventory getCraftingMatrix() + public IItemHandler getCraftingMatrix() { return this.craftInv; } @@ -105,18 +108,18 @@ public class SlotCraftingTerm extends AppEngCraftingSlot InventoryAdaptor ia = null; if( action == InventoryAction.CRAFT_SHIFT ) // craft into player inventory... { - ia = InventoryAdaptor.getAdaptor( who, null ); + ia = InventoryAdaptor.getAdaptor( who ); maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft ); } else if( action == InventoryAction.CRAFT_STACK ) // craft into hand, full stack { - ia = new AdaptorPlayerHand( who ); + ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) ); maxTimesToCraft = (int) Math.floor( (double) this.getStack().getMaxStackSize() / (double) howManyPerCraft ); } else // pick up what was crafted... { - ia = new AdaptorPlayerHand( who ); + ia = new AdaptorItemHandler( new WrapperCursorItemHandler( who.inventory ) ); maxTimesToCraft = 1; } @@ -162,7 +165,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot if( !is.isEmpty() && Platform.itemComparisons().isEqualItem( request, is ) ) { - final ItemStack[] set = new ItemStack[this.getPattern().getSizeInventory()]; + final ItemStack[] set = new ItemStack[this.getPattern().getSlots()]; // Safeguard for empty slots in the inventory for now Arrays.fill( set, ItemStack.EMPTY ); @@ -199,7 +202,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot { super.onTake( p, is ); // actually necessary to cleanup this case... - p.openContainer.onCraftMatrixChanged( this.craftInv ); + p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) ); return request; } } @@ -210,7 +213,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot if( inv != null ) { - for( int x = 0; x < this.getPattern().getSizeInventory(); x++ ) + for( int x = 0; x < this.getPattern().getSlots(); x++ ) { if( !this.getPattern().getStackInSlot( x ).isEmpty() ) { @@ -229,8 +232,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot this.postCraft( p, inv, set, is ); } - // shouldn't be necessary... - p.openContainer.onCraftMatrixChanged( this.craftInv ); + p.openContainer.onCraftMatrixChanged( new WrapperInvItemHandler( this.craftInv ) ); return is; } @@ -256,11 +258,11 @@ public class SlotCraftingTerm extends AppEngCraftingSlot if( Platform.isServer() ) { // set new items onto the crafting table... - for( int x = 0; x < this.craftInv.getSizeInventory(); x++ ) + for( int x = 0; x < this.craftInv.getSlots(); x++ ) { if( this.craftInv.getStackInSlot( x ).isEmpty() ) { - this.craftInv.setInventorySlotContents( x, set[x] ); + ItemHandlerUtil.setStackInSlot( this.craftInv, x, set[x] ); } else if( !set[x].isEmpty() ) { @@ -280,7 +282,7 @@ public class SlotCraftingTerm extends AppEngCraftingSlot } } - IInventory getPattern() + IItemHandler getPattern() { return this.pattern; } diff --git a/src/main/java/appeng/container/slot/SlotDisabled.java b/src/main/java/appeng/container/slot/SlotDisabled.java index f298e6e7b..c57c086f6 100644 --- a/src/main/java/appeng/container/slot/SlotDisabled.java +++ b/src/main/java/appeng/container/slot/SlotDisabled.java @@ -20,14 +20,14 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class SlotDisabled extends AppEngSlot { - public SlotDisabled( final IInventory par1iInventory, final int slotIndex, final int x, final int y ) + public SlotDisabled( final IItemHandler par1iInventory, final int slotIndex, final int x, final int y ) { super( par1iInventory, slotIndex, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotFake.java b/src/main/java/appeng/container/slot/SlotFake.java index a3a9cc0c7..8abe0d2e9 100644 --- a/src/main/java/appeng/container/slot/SlotFake.java +++ b/src/main/java/appeng/container/slot/SlotFake.java @@ -20,14 +20,14 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class SlotFake extends AppEngSlot { - public SlotFake( final IInventory inv, final int idx, final int x, final int y ) + public SlotFake( final IItemHandler inv, final int idx, final int x, final int y ) { super( inv, idx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotFakeBlacklist.java b/src/main/java/appeng/container/slot/SlotFakeBlacklist.java index b9304dd78..e13318a47 100644 --- a/src/main/java/appeng/container/slot/SlotFakeBlacklist.java +++ b/src/main/java/appeng/container/slot/SlotFakeBlacklist.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotFakeBlacklist extends SlotFakeTypeOnly { - public SlotFakeBlacklist( final IInventory inv, final int idx, final int x, final int y ) + public SlotFakeBlacklist( final IItemHandler inv, final int idx, final int x, final int y ) { super( inv, idx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java b/src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java index e1bf15b22..f92cd4a99 100644 --- a/src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java +++ b/src/main/java/appeng/container/slot/SlotFakeCraftingMatrix.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotFakeCraftingMatrix extends SlotFake { - public SlotFakeCraftingMatrix( final IInventory inv, final int idx, final int x, final int y ) + public SlotFakeCraftingMatrix( final IItemHandler inv, final int idx, final int x, final int y ) { super( inv, idx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotFakeTypeOnly.java b/src/main/java/appeng/container/slot/SlotFakeTypeOnly.java index 5c739afc1..d93c0a183 100644 --- a/src/main/java/appeng/container/slot/SlotFakeTypeOnly.java +++ b/src/main/java/appeng/container/slot/SlotFakeTypeOnly.java @@ -19,14 +19,14 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class SlotFakeTypeOnly extends SlotFake { - public SlotFakeTypeOnly( final IInventory inv, final int idx, final int x, final int y ) + public SlotFakeTypeOnly( final IItemHandler inv, final int idx, final int x, final int y ) { super( inv, idx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotInaccessible.java b/src/main/java/appeng/container/slot/SlotInaccessible.java index 7fd2d88d9..e509f8ee2 100644 --- a/src/main/java/appeng/container/slot/SlotInaccessible.java +++ b/src/main/java/appeng/container/slot/SlotInaccessible.java @@ -20,8 +20,8 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class SlotInaccessible extends AppEngSlot @@ -29,7 +29,7 @@ public class SlotInaccessible extends AppEngSlot private ItemStack dspStack = ItemStack.EMPTY; - public SlotInaccessible( final IInventory i, final int slotIdx, final int x, final int y ) + public SlotInaccessible( final IItemHandler i, final int slotIdx, final int x, final int y ) { super( i, slotIdx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotInaccessibleHD.java b/src/main/java/appeng/container/slot/SlotInaccessibleHD.java index 10d675d48..b95a62e7c 100644 --- a/src/main/java/appeng/container/slot/SlotInaccessibleHD.java +++ b/src/main/java/appeng/container/slot/SlotInaccessibleHD.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotInaccessibleHD extends SlotInaccessible { - public SlotInaccessibleHD( final IInventory i, final int slotIdx, final int x, final int y ) + public SlotInaccessibleHD( final IItemHandler i, final int slotIdx, final int x, final int y ) { super( i, slotIdx, x, y ); } diff --git a/src/main/java/appeng/container/slot/SlotMACPattern.java b/src/main/java/appeng/container/slot/SlotMACPattern.java index 9ee53b8d2..c7e05542d 100644 --- a/src/main/java/appeng/container/slot/SlotMACPattern.java +++ b/src/main/java/appeng/container/slot/SlotMACPattern.java @@ -19,8 +19,8 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.container.implementations.ContainerMAC; @@ -30,7 +30,7 @@ public class SlotMACPattern extends AppEngSlot private final ContainerMAC mac; - public SlotMACPattern( final ContainerMAC mac, final IInventory i, final int slotIdx, final int x, final int y ) + public SlotMACPattern( final ContainerMAC mac, final IItemHandler i, final int slotIdx, final int x, final int y ) { super( i, slotIdx, x, y ); this.mac = mac; diff --git a/src/main/java/appeng/container/slot/SlotNormal.java b/src/main/java/appeng/container/slot/SlotNormal.java index 96e705b28..3e2a509ea 100644 --- a/src/main/java/appeng/container/slot/SlotNormal.java +++ b/src/main/java/appeng/container/slot/SlotNormal.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotNormal extends AppEngSlot { - public SlotNormal( final IInventory inv, final int slot, final int xPos, final int yPos ) + public SlotNormal( final IItemHandler inv, final int slot, final int xPos, final int yPos ) { super( inv, slot, xPos, yPos ); } diff --git a/src/main/java/appeng/container/slot/SlotOutput.java b/src/main/java/appeng/container/slot/SlotOutput.java index 3c6624337..687483e5b 100644 --- a/src/main/java/appeng/container/slot/SlotOutput.java +++ b/src/main/java/appeng/container/slot/SlotOutput.java @@ -19,14 +19,14 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public class SlotOutput extends AppEngSlot { - public SlotOutput( final IInventory a, final int b, final int c, final int d, final int i ) + public SlotOutput( final IItemHandler a, final int b, final int c, final int d, final int i ) { super( a, b, c, d ); this.setIIcon( i ); diff --git a/src/main/java/appeng/container/slot/SlotPatternOutputs.java b/src/main/java/appeng/container/slot/SlotPatternOutputs.java index 42ef2f87b..70b873d03 100644 --- a/src/main/java/appeng/container/slot/SlotPatternOutputs.java +++ b/src/main/java/appeng/container/slot/SlotPatternOutputs.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotPatternOutputs extends OptionalSlotFake { - public SlotPatternOutputs( final IInventory inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) + public SlotPatternOutputs( final IItemHandler inv, final IOptionalSlotHost containerBus, final int idx, final int x, final int y, final int offX, final int offY, final int groupNum ) { super( inv, containerBus, idx, x, y, offX, offY, groupNum ); } diff --git a/src/main/java/appeng/container/slot/SlotPatternTerm.java b/src/main/java/appeng/container/slot/SlotPatternTerm.java index 98cfa1e74..e6153b771 100644 --- a/src/main/java/appeng/container/slot/SlotPatternTerm.java +++ b/src/main/java/appeng/container/slot/SlotPatternTerm.java @@ -22,8 +22,8 @@ package appeng.container.slot; import java.io.IOException; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.networking.energy.IEnergySource; @@ -40,7 +40,7 @@ public class SlotPatternTerm extends SlotCraftingTerm private final int groupNum; private final IOptionalSlotHost host; - public SlotPatternTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IInventory cMatrix, final IInventory secondMatrix, final IInventory output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c ) + public SlotPatternTerm( final EntityPlayer player, final BaseActionSource mySrc, final IEnergySource energySrc, final IStorageMonitorable storage, final IItemHandler cMatrix, final IItemHandler secondMatrix, final IItemHandler output, final int x, final int y, final IOptionalSlotHost h, final int groupNumber, final IContainerCraftingPacket c ) { super( player, mySrc, energySrc, storage, cMatrix, secondMatrix, output, x, y, c ); diff --git a/src/main/java/appeng/container/slot/SlotPlayerHotBar.java b/src/main/java/appeng/container/slot/SlotPlayerHotBar.java index aba5e52cd..2d81df4ff 100644 --- a/src/main/java/appeng/container/slot/SlotPlayerHotBar.java +++ b/src/main/java/appeng/container/slot/SlotPlayerHotBar.java @@ -19,13 +19,13 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; public class SlotPlayerHotBar extends AppEngSlot { - public SlotPlayerHotBar( final IInventory par1iInventory, final int par2, final int par3, final int par4 ) + public SlotPlayerHotBar( final IItemHandler par1iInventory, final int par2, final int par3, final int par4 ) { super( par1iInventory, par2, par3, par4 ); this.setPlayerSide( true ); diff --git a/src/main/java/appeng/container/slot/SlotPlayerInv.java b/src/main/java/appeng/container/slot/SlotPlayerInv.java index 5c5d3494d..721c78976 100644 --- a/src/main/java/appeng/container/slot/SlotPlayerInv.java +++ b/src/main/java/appeng/container/slot/SlotPlayerInv.java @@ -19,7 +19,7 @@ package appeng.container.slot; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; // there is nothing special about this slot, its simply used to represent the players inventory, vs a container slot. @@ -27,7 +27,7 @@ import net.minecraft.inventory.IInventory; public class SlotPlayerInv extends AppEngSlot { - public SlotPlayerInv( final IInventory par1iInventory, final int par2, final int par3, final int par4 ) + public SlotPlayerInv( final IItemHandler par1iInventory, final int par2, final int par3, final int par4 ) { super( par1iInventory, par2, par3, par4 ); diff --git a/src/main/java/appeng/container/slot/SlotRestrictedInput.java b/src/main/java/appeng/container/slot/SlotRestrictedInput.java index 8539909ee..37908e7e7 100644 --- a/src/main/java/appeng/container/slot/SlotRestrictedInput.java +++ b/src/main/java/appeng/container/slot/SlotRestrictedInput.java @@ -22,11 +22,11 @@ package appeng.container.slot; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.Slot; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntityFurnace; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; @@ -59,7 +59,7 @@ public class SlotRestrictedInput extends AppEngSlot private boolean allowEdit = true; private int stackLimit = -1; - public SlotRestrictedInput( final PlacableItemType valid, final IInventory i, final int slotIndex, final int x, final int y, final InventoryPlayer p ) + public SlotRestrictedInput( final PlacableItemType valid, final IItemHandler i, final int slotIndex, final int x, final int y, final InventoryPlayer p ) { super( i, slotIndex, x, y ); this.which = valid; @@ -106,12 +106,13 @@ public class SlotRestrictedInput extends AppEngSlot { return false; } + if( i.getItem() == Items.AIR ) { return false; } - if( !this.inventory.isItemValidForSlot( this.getSlotIndex(), i ) ) + if( !super.isItemValid( i ) ) { return false; } diff --git a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java index ee2f47eb4..a7107e20a 100644 --- a/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java +++ b/src/main/java/appeng/core/features/registries/P2PTunnelRegistry.java @@ -30,7 +30,6 @@ import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; diff --git a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java index 7ce55bb2c..91bafece9 100644 --- a/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java +++ b/src/main/java/appeng/core/sync/packets/PacketJEIRecipe.java @@ -30,14 +30,13 @@ import io.netty.buffer.Unpooled; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.inventory.Container; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.CompressedStreamTools; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -import net.minecraft.util.EnumFacing; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; import appeng.api.config.Actionable; @@ -58,6 +57,8 @@ import appeng.helpers.IContainerCraftingPacket; import appeng.items.storage.ItemViewCell; import appeng.util.InventoryAdaptor; import appeng.util.Platform; +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.WrapperInvItemHandler; import appeng.util.item.AEItemStack; import appeng.util.prioritylist.IPartitionList; @@ -128,8 +129,8 @@ public class PacketJEIRecipe extends AppEngPacket final IStorageGrid inv = grid.getCache( IStorageGrid.class ); final IEnergyGrid energy = grid.getCache( IEnergyGrid.class ); final ISecurityGrid security = grid.getCache( ISecurityGrid.class ); - final IInventory craftMatrix = cct.getInventoryByName( "crafting" ); - final IInventory playerInventory = cct.getInventoryByName( "player" ); + final IItemHandler craftMatrix = cct.getInventoryByName( "crafting" ); + final IItemHandler playerInventory = cct.getInventoryByName( "player" ); final Actionable realForFake = cct.useRealItems() ? Actionable.MODULATE : Actionable.SIMULATE; @@ -156,7 +157,7 @@ public class PacketJEIRecipe extends AppEngPacket final IItemList all = storage.getStorageList(); final IPartitionList filter = ItemViewCell.createFilter( cct.getViewCells() ); - for( int x = 0; x < craftMatrix.getSizeInventory(); x++ ) + for( int x = 0; x < craftMatrix.getSlots(); x++ ) { final ItemStack patternItem = testInv.getStackInSlot( x ); @@ -176,11 +177,11 @@ public class PacketJEIRecipe extends AppEngPacket cct.getActionSource() ); if( out != null ) { - craftMatrix.setInventorySlotContents( x, out.getItemStack() ); + ItemHandlerUtil.setStackInSlot( craftMatrix, x, out.getItemStack() ); } else { - craftMatrix.setInventorySlotContents( x, ItemStack.EMPTY ); + ItemHandlerUtil.setStackInSlot( craftMatrix, x, ItemStack.EMPTY ); } currentItem = craftMatrix.getStackInSlot( x ); @@ -224,10 +225,10 @@ public class PacketJEIRecipe extends AppEngPacket whichItem = this.extractItemFromPlayerInventory( player, realForFake, patternItem ); } - craftMatrix.setInventorySlotContents( x, whichItem ); + ItemHandlerUtil.setStackInSlot( craftMatrix, x, whichItem ); } } - con.onCraftMatrixChanged( craftMatrix ); + con.onCraftMatrixChanged( new WrapperInvItemHandler( craftMatrix ) ); } } } @@ -245,7 +246,7 @@ public class PacketJEIRecipe extends AppEngPacket */ private ItemStack extractItemFromPlayerInventory( final EntityPlayer player, final Actionable mode, final ItemStack patternItem ) { - final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); + final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player ); final AEItemStack request = AEItemStack.create( patternItem ); final boolean isSimulated = mode == Actionable.SIMULATE; final boolean checkFuzzy = request.isOre() || patternItem.getItemDamage() == OreDictionary.WILDCARD_VALUE || patternItem.hasTagCompound() || patternItem diff --git a/src/main/java/appeng/core/sync/packets/PacketPartPlacement.java b/src/main/java/appeng/core/sync/packets/PacketPartPlacement.java index 7e663ce6f..98c27bd67 100644 --- a/src/main/java/appeng/core/sync/packets/PacketPartPlacement.java +++ b/src/main/java/appeng/core/sync/packets/PacketPartPlacement.java @@ -77,7 +77,8 @@ public class PacketPartPlacement extends AppEngPacket final EntityPlayerMP sender = (EntityPlayerMP) player; AppEng.proxy.updateRenderMode( sender ); PartPlacement.setEyeHeight( this.eyeHeight ); - PartPlacement.place( sender.getHeldItem( this.hand ), new BlockPos( this.x, this.y, this.z ), EnumFacing.VALUES[this.face], sender, this.hand, sender.world, + PartPlacement.place( sender.getHeldItem( this.hand ), new BlockPos( this.x, this.y, this.z ), EnumFacing.VALUES[this.face], sender, this.hand, + sender.world, PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0 ); AppEng.proxy.updateRenderMode( null ); } diff --git a/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java b/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java index 09234fcfe..fc0380ae0 100644 --- a/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java +++ b/src/main/java/appeng/core/sync/packets/PacketPatternSlot.java @@ -26,7 +26,7 @@ import io.netty.buffer.Unpooled; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; -import net.minecraft.inventory.IInventory; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.storage.data.IAEItemStack; @@ -72,7 +72,7 @@ public class PacketPatternSlot extends AppEngPacket } // api - public PacketPatternSlot( final IInventory pat, final IAEItemStack slotItem, final boolean shift ) throws IOException + public PacketPatternSlot( final IItemHandler pat, final IAEItemStack slotItem, final boolean shift ) throws IOException { this.slotItem = slotItem; diff --git a/src/main/java/appeng/helpers/DualityInterface.java b/src/main/java/appeng/helpers/DualityInterface.java index ba75575d6..68ecb9b24 100644 --- a/src/main/java/appeng/helpers/DualityInterface.java +++ b/src/main/java/appeng/helpers/DualityInterface.java @@ -33,8 +33,6 @@ import com.google.common.collect.ImmutableSet; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -49,7 +47,7 @@ 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.RangedWrapper; import appeng.api.AEApi; import appeng.api.config.Actionable; @@ -97,15 +95,14 @@ import appeng.parts.automation.StackUpgradeInventory; import appeng.parts.automation.UpgradeInventory; 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.InventoryAdaptor; import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; +import appeng.util.inv.AdaptorItemHandler; +import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.IInventoryDestination; -import appeng.util.inv.WrapperInvSlot; +import appeng.util.inv.InvOperation; import appeng.util.item.AEItemStack; @@ -117,7 +114,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn public static final int NUMBER_OF_PATTERN_SLOTS = 9; private static final Collection BAD_BLOCKS = new HashSet<>( 100 ); - private final int[] sides = { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; private final IAEItemStack[] requireWork = { null, null, null, null, null, null, null, null, null }; private final MultiCraftingTracker craftingTracker; private final AENetworkProxy gridProxy; @@ -128,7 +124,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn private final AppEngInternalAEInventory config = new AppEngInternalAEInventory( this, NUMBER_OF_CONFIG_SLOTS ); private final AppEngInternalInventory storage = new AppEngInternalInventory( this, NUMBER_OF_STORAGE_SLOTS ); private final AppEngInternalInventory patterns = new AppEngInternalInventory( this, NUMBER_OF_PATTERN_SLOTS ); - private final WrapperInvSlot slotInv = new WrapperInvSlot( this.storage ); private final MEMonitorPassThrough items = new MEMonitorPassThrough<>( new NullInventory(), StorageChannel.ITEMS ); private final MEMonitorPassThrough fluids = new MEMonitorPassThrough<>( new NullInventory(), StorageChannel.FLUIDS ); private final UpgradeInventory upgrades; @@ -138,7 +133,6 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn private List waitingToSend = null; private IMEInventory destination; private boolean isWorking = false; - private IItemHandler itemHandler = null; private final Accessor accessor = new Accessor(); public DualityInterface( final AENetworkProxy networkProxy, final IInterfaceHost ih ) @@ -168,7 +162,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn } @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.isWorking ) { @@ -335,7 +329,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn { final Boolean[] accountedFor = { false, false, false, false, false, false, false, false, false }; // 9... - assert ( accountedFor.length == this.patterns.getSizeInventory() ); + assert ( accountedFor.length == this.patterns.getSlots() ); if( !this.gridProxy.isReady() ) { @@ -409,7 +403,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn IAEItemStack req = this.config.getAEStackInSlot( slot ); if( req != null && req.getStackSize() <= 0 ) { - this.config.setInventorySlotContents( slot, ItemStack.EMPTY ); + this.config.setStackInSlot( slot, ItemStack.EMPTY ); req = null; } @@ -517,12 +511,12 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn // return after.stackSize != stack.stackSize; } - public IInventory getConfig() + public IItemHandler getConfig() { return this.config; } - public IInventory getPatterns() + public IItemHandler getPatterns() { return this.patterns; } @@ -553,24 +547,19 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn return new DimensionalCoord( this.iHost.getTileEntity() ); } - public IInventory getInternalInventory() + public IItemHandler getInternalInventory() { return this.storage; } public void markDirty() { - for( int slot = 0; slot < this.storage.getSizeInventory(); slot++ ) + for( int slot = 0; slot < this.storage.getSlots(); slot++ ) { - this.onChangeInventory( this.storage, slot, InvOperation.markDirty, ItemStack.EMPTY, ItemStack.EMPTY ); + this.storage.markDirty( slot ); } } - public int[] getSlotsForFace( final EnumFacing side ) - { - return this.sides; - } - @Override public TickingRequest getTickingRequest( final IGridNode node ) { @@ -759,7 +748,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn private InventoryAdaptor getAdaptor( final int slot ) { - return new AdaptorIInventory( this.slotInv.getWrapper( slot ) ); + return new AdaptorItemHandler( new RangedWrapper( this.storage, slot, slot + 1 ) ); } private boolean handleCrafting( final int x, final InventoryAdaptor d, final IAEItemStack itemStack ) @@ -813,7 +802,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "storage" ) ) { @@ -838,7 +827,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn return null; } - public IInventory getStorage() + public IItemHandler getStorage() { return this.storage; } @@ -1185,21 +1174,11 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( directedTile, direction.getOpposite() ); if( directedTile instanceof ICraftingMachine || adaptor != null ) { - if( directedTile instanceof IInventory && ( (IInventory) directedTile ).getSizeInventory() == 0 ) + if( adaptor != null && !adaptor.hasSlots() ) { continue; } - if( directedTile instanceof ISidedInventory ) - { - final int[] sides = ( (ISidedInventory) directedTile ).getSlotsForFace( direction.getOpposite() ); - - if( sides == null || sides.length == 0 ) - { - continue; - } - } - final IBlockState directedBlockState = hostWorld.getBlockState( targ ); final Block directedBlock = directedBlockState.getBlock(); ItemStack what = new ItemStack( directedBlock, 1, directedBlock.getMetaFromState( directedBlockState ) ); @@ -1285,11 +1264,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn { if( capabilityClass == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) { - if( this.itemHandler == null ) - { - this.itemHandler = new InvWrapper( this.storage ); - } - return (T) this.itemHandler; + return (T) storage; } else if( capabilityClass == Capabilities.STORAGE_MONITORABLE_ACCESSOR ) { @@ -1312,7 +1287,7 @@ public class DualityInterface implements IGridTickable, IStorageMonitorable, IIn public InterfaceInventory( final DualityInterface tileInterface ) { - super( new AdaptorIInventory( tileInterface.storage ) ); + super( new AdaptorItemHandler( tileInterface.storage ) ); this.setActionSource( new MachineSource( DualityInterface.this.iHost ) ); } diff --git a/src/main/java/appeng/helpers/IContainerCraftingPacket.java b/src/main/java/appeng/helpers/IContainerCraftingPacket.java index 3ae373e24..8bac361a1 100644 --- a/src/main/java/appeng/helpers/IContainerCraftingPacket.java +++ b/src/main/java/appeng/helpers/IContainerCraftingPacket.java @@ -19,8 +19,8 @@ package appeng.helpers; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.networking.IGridNode; import appeng.api.networking.security.BaseActionSource; @@ -39,7 +39,7 @@ public interface IContainerCraftingPacket * * @return the inventory of the part/tile by name. */ - IInventory getInventoryByName( String string ); + IItemHandler getInventoryByName( String string ); /** * @return who are we? diff --git a/src/main/java/appeng/integration/modules/theoneprobe/tile/ChargerInfoProvider.java b/src/main/java/appeng/integration/modules/theoneprobe/tile/ChargerInfoProvider.java index 1adcad548..b6b843b8e 100644 --- a/src/main/java/appeng/integration/modules/theoneprobe/tile/ChargerInfoProvider.java +++ b/src/main/java/appeng/integration/modules/theoneprobe/tile/ChargerInfoProvider.java @@ -21,9 +21,9 @@ package appeng.integration.modules.theoneprobe.tile; 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.world.World; +import net.minecraftforge.items.IItemHandler; import mcjty.theoneprobe.api.ElementAlignment; import mcjty.theoneprobe.api.IProbeHitData; @@ -43,7 +43,7 @@ public class ChargerInfoProvider implements ITileProbInfoProvider if( tile instanceof TileCharger ) { final TileCharger charger = (TileCharger) tile; - final IInventory chargerInventory = charger.getInternalInventory(); + final IItemHandler chargerInventory = charger.getInternalInventory(); final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 ); if( !chargingItem.isEmpty() ) diff --git a/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java index 3dc363153..80ad1da9c 100644 --- a/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java +++ b/src/main/java/appeng/integration/modules/waila/tile/ChargerWailaDataProvider.java @@ -26,9 +26,9 @@ import javax.annotation.Nonnull; import net.minecraft.client.Minecraft; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; +import net.minecraftforge.items.IItemHandler; import mcp.mobius.waila.api.IWailaConfigHandler; import mcp.mobius.waila.api.IWailaDataAccessor; @@ -64,7 +64,7 @@ public final class ChargerWailaDataProvider extends BaseWailaDataProvider if( te instanceof TileCharger ) { final TileCharger charger = (TileCharger) te; - final IInventory chargerInventory = charger.getInternalInventory(); + final IItemHandler chargerInventory = charger.getInternalInventory(); final ItemStack chargingItem = chargerInventory.getStackInSlot( 0 ); if( !chargingItem.isEmpty() ) diff --git a/src/main/java/appeng/items/contents/CellConfig.java b/src/main/java/appeng/items/contents/CellConfig.java index 9ad6e4481..a916fd70b 100644 --- a/src/main/java/appeng/items/contents/CellConfig.java +++ b/src/main/java/appeng/items/contents/CellConfig.java @@ -38,7 +38,7 @@ public class CellConfig extends AppEngInternalInventory } @Override - public void markDirty() + protected void onContentsChanged( int slot ) { this.writeToNBT( Platform.openNbtData( this.is ), "list" ); } diff --git a/src/main/java/appeng/items/contents/CellUpgrades.java b/src/main/java/appeng/items/contents/CellUpgrades.java index 14975d68c..5f6dbc99e 100644 --- a/src/main/java/appeng/items/contents/CellUpgrades.java +++ b/src/main/java/appeng/items/contents/CellUpgrades.java @@ -37,7 +37,7 @@ public final class CellUpgrades extends StackUpgradeInventory } @Override - public void markDirty() + protected void onContentsChanged( int slot ) { this.writeToNBT( Platform.openNbtData( this.is ), "upgrades" ); } diff --git a/src/main/java/appeng/items/contents/NetworkToolViewer.java b/src/main/java/appeng/items/contents/NetworkToolViewer.java index 5befe3326..7ea476730 100644 --- a/src/main/java/appeng/items/contents/NetworkToolViewer.java +++ b/src/main/java/appeng/items/contents/NetworkToolViewer.java @@ -19,18 +19,20 @@ package appeng.items.contents; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; +import net.minecraftforge.items.IItemHandler; import appeng.api.implementations.guiobjects.INetworkTool; import appeng.api.implementations.items.IUpgradeModule; import appeng.api.networking.IGridHost; import appeng.tile.inventory.AppEngInternalInventory; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; +import appeng.util.inv.filter.IAEItemFilter; -public class NetworkToolViewer implements INetworkTool +public class NetworkToolViewer implements INetworkTool, IAEAppEngInventory { private final AppEngInternalInventory inv; @@ -41,7 +43,8 @@ public class NetworkToolViewer implements INetworkTool { this.is = is; this.gh = gHost; - this.inv = new AppEngInternalInventory( null, 9 ); + this.inv = new AppEngInternalInventory( this, 9 ); + this.inv.setFilter( new NetworkToolInventoryFilter() ); if( is.hasTagCompound() ) // prevent crash when opening network status screen. { this.inv.readFromNBT( Platform.openNbtData( is ), "inv" ); @@ -49,85 +52,17 @@ public class NetworkToolViewer implements INetworkTool } @Override - public int getSizeInventory() + public void saveChanges() { - return this.inv.getSizeInventory(); + inv.markDirty( -1 ); } @Override - public ItemStack getStackInSlot( final int i ) + public void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack ) { - return this.inv.getStackInSlot( i ); - } - - @Override - public ItemStack decrStackSize( final int i, final int j ) - { - return this.inv.decrStackSize( i, j ); - } - - @Override - public ItemStack removeStackFromSlot( int i ) - { - return this.inv.removeStackFromSlot( i ); - } - - @Override - public void setInventorySlotContents( final int i, final ItemStack itemstack ) - { - this.inv.setInventorySlotContents( i, itemstack ); - } - - @Override - public String getName() - { - return this.inv.getName(); - } - - @Override - public boolean hasCustomName() - { - return this.inv.hasCustomName(); - } - - @Override - public int getInventoryStackLimit() - { - return this.inv.getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - this.inv.markDirty(); this.inv.writeToNBT( Platform.openNbtData( this.is ), "inv" ); } - @Override - public boolean isUsableByPlayer( final EntityPlayer entityplayer ) - { - return this.inv.isUsableByPlayer( entityplayer ); - } - - @Override - public void openInventory( final EntityPlayer player ) - { - this.inv.openInventory( player ); - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - this.inv.closeInventory( player ); - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - return this.inv.isItemValidForSlot( i, - itemstack ) && itemstack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) itemstack.getItem() ).getType( itemstack ) != null; - } - @Override public ItemStack getItemStack() { @@ -140,39 +75,29 @@ public class NetworkToolViewer implements INetworkTool return this.gh; } - @Override - public int getField( final int id ) + private static class NetworkToolInventoryFilter implements IAEItemFilter { - return this.inv.getField( id ); + @Override + public boolean allowExtract( IItemHandler inv, int slot, int amount ) + { + return true; + } + + @Override + public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack ) + { + return stack.getItem() instanceof IUpgradeModule && ( (IUpgradeModule) stack.getItem() ).getType( stack ) != null; + } + } + + public IItemHandler getInternalInventory() + { + return inv; } @Override - public void setField( final int id, final int value ) + public IItemHandler getInventory() { - this.inv.setField( id, value ); - } - - @Override - public int getFieldCount() - { - return this.inv.getFieldCount(); - } - - @Override - public void clear() - { - this.inv.clear(); - } - - @Override - public ITextComponent getDisplayName() - { - return this.inv.getDisplayName(); - } - - @Override - public boolean isEmpty() - { - return false; + return this.inv; } } diff --git a/src/main/java/appeng/items/materials/ItemMaterial.java b/src/main/java/appeng/items/materials/ItemMaterial.java index 2768feceb..e8f6af3ea 100644 --- a/src/main/java/appeng/items/materials/ItemMaterial.java +++ b/src/main/java/appeng/items/materials/ItemMaterial.java @@ -38,7 +38,6 @@ import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -51,6 +50,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; import appeng.api.config.Upgrades; @@ -68,6 +68,7 @@ import appeng.core.features.MaterialStackSrc; import appeng.items.AEBaseItem; import appeng.util.InventoryAdaptor; import appeng.util.Platform; +import appeng.util.inv.AdaptorItemHandler; public final class ItemMaterial extends AEBaseItem implements IStorageComponent, IUpgradeModule @@ -289,7 +290,7 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent, if( player.isSneaking() ) { final TileEntity te = world.getTileEntity( pos ); - IInventory upgrades = null; + IItemHandler upgrades = null; if( te instanceof IPartHost ) { @@ -311,17 +312,14 @@ public final class ItemMaterial extends AEBaseItem implements IStorageComponent, if( u != null ) { - final InventoryAdaptor ad = InventoryAdaptor.getAdaptor( upgrades, EnumFacing.UP ); - if( ad != null ) + if( player.world.isRemote ) { - if( player.world.isRemote ) - { - return EnumActionResult.PASS; - } - - player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) ); - return EnumActionResult.SUCCESS; + return EnumActionResult.PASS; } + + final InventoryAdaptor ad = new AdaptorItemHandler( upgrades ); + player.inventory.setInventorySlotContents( player.inventory.currentItem, ad.addItems( player.getHeldItem( hand ) ) ); + return EnumActionResult.SUCCESS; } } } diff --git a/src/main/java/appeng/items/storage/ItemBasicStorageCell.java b/src/main/java/appeng/items/storage/ItemBasicStorageCell.java index fd46e0fa9..2bccd7ab0 100644 --- a/src/main/java/appeng/items/storage/ItemBasicStorageCell.java +++ b/src/main/java/appeng/items/storage/ItemBasicStorageCell.java @@ -25,7 +25,6 @@ import java.util.Set; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.InventoryPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; @@ -35,6 +34,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; @@ -188,13 +188,13 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return new CellUpgrades( is, 2 ); } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } @@ -239,7 +239,7 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe final IMEInventoryHandler inv = AEApi.instance().registries().cell().getCellInventory( stack, null, StorageChannel.ITEMS ); if( inv != null && playerInventory.getCurrentItem() == stack ) { - final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); + final InventoryAdaptor ia = InventoryAdaptor.getAdaptor( player ); final IItemList list = inv.getAvailableItems( StorageChannel.ITEMS.createList() ); if( list.isEmpty() && ia != null ) { @@ -253,8 +253,8 @@ public final class ItemBasicStorageCell extends AEBaseItem implements IStorageCe } // drop upgrades - final IInventory upgradesInventory = this.getUpgradesInventory( stack ); - for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSizeInventory(); upgradeIndex++ ) + final IItemHandler upgradesInventory = this.getUpgradesInventory( stack ); + for( int upgradeIndex = 0; upgradeIndex < upgradesInventory.getSlots(); upgradeIndex++ ) { final ItemStack upgradeStack = upgradesInventory.getStackInSlot( upgradeIndex ); final ItemStack leftStack = ia.addItems( upgradeStack ); diff --git a/src/main/java/appeng/items/storage/ItemCreativeStorageCell.java b/src/main/java/appeng/items/storage/ItemCreativeStorageCell.java index 4679d6fc0..94c8f8833 100644 --- a/src/main/java/appeng/items/storage/ItemCreativeStorageCell.java +++ b/src/main/java/appeng/items/storage/ItemCreativeStorageCell.java @@ -22,11 +22,11 @@ package appeng.items.storage; import java.util.List; import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; @@ -53,13 +53,13 @@ public class ItemCreativeStorageCell extends AEBaseItem implements ICellWorkbenc } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return null; } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } diff --git a/src/main/java/appeng/items/storage/ItemViewCell.java b/src/main/java/appeng/items/storage/ItemViewCell.java index a6ac43b96..60d9a1c53 100644 --- a/src/main/java/appeng/items/storage/ItemViewCell.java +++ b/src/main/java/appeng/items/storage/ItemViewCell.java @@ -19,8 +19,8 @@ package appeng.items.storage; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; @@ -65,14 +65,14 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem final IItemList priorityList = AEApi.instance().storage().createItemList(); final ICellWorkbenchItem vc = (ICellWorkbenchItem) currentViewCell.getItem(); - final IInventory upgrades = vc.getUpgradesInventory( currentViewCell ); - final IInventory config = vc.getConfigInventory( currentViewCell ); + final IItemHandler upgrades = vc.getUpgradesInventory( currentViewCell ); + final IItemHandler config = vc.getConfigInventory( currentViewCell ); final FuzzyMode fzMode = vc.getFuzzyMode( currentViewCell ); boolean hasInverter = false; boolean hasFuzzy = false; - for( int x = 0; x < upgrades.getSizeInventory(); x++ ) + for( int x = 0; x < upgrades.getSlots(); x++ ) { final ItemStack is = upgrades.getStackInSlot( x ); if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule ) @@ -94,7 +94,7 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem } } - for( int x = 0; x < config.getSizeInventory(); x++ ) + for( int x = 0; x < config.getSlots(); x++ ) { final ItemStack is = config.getStackInSlot( x ); if( !is.isEmpty() ) @@ -129,13 +129,13 @@ public class ItemViewCell extends AEBaseItem implements ICellWorkbenchItem } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return new CellUpgrades( is, 2 ); } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } diff --git a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java index 2e18418fc..31d9b3cb1 100644 --- a/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java +++ b/src/main/java/appeng/items/tools/powered/ToolColorApplicator.java @@ -37,7 +37,6 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; import net.minecraft.item.EnumDyeColor; import net.minecraft.item.ItemSnowball; import net.minecraft.item.ItemStack; @@ -50,6 +49,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; @@ -516,13 +516,13 @@ public class ToolColorApplicator extends AEBasePoweredItem implements IStorageCe } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return new CellUpgrades( is, 2 ); } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } diff --git a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java index c383de55e..c063bb8d2 100644 --- a/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java +++ b/src/main/java/appeng/items/tools/powered/ToolMatterCannon.java @@ -31,7 +31,6 @@ import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.passive.EntitySheep; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.ActionResult; @@ -46,6 +45,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.Actionable; @@ -445,13 +445,13 @@ public class ToolMatterCannon extends AEBasePoweredItem implements IStorageCell } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return new CellUpgrades( is, 4 ); } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } diff --git a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java index 225a3660f..ed16b27a9 100644 --- a/src/main/java/appeng/items/tools/powered/ToolPortableCell.java +++ b/src/main/java/appeng/items/tools/powered/ToolPortableCell.java @@ -24,7 +24,6 @@ import java.util.Set; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.util.ActionResult; import net.minecraft.util.EnumActionResult; @@ -33,6 +32,7 @@ import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; @@ -152,13 +152,13 @@ public class ToolPortableCell extends AEBasePoweredItem implements IStorageCell, } @Override - public IInventory getUpgradesInventory( final ItemStack is ) + public IItemHandler getUpgradesInventory( final ItemStack is ) { return new CellUpgrades( is, 2 ); } @Override - public IInventory getConfigInventory( final ItemStack is ) + public IItemHandler getConfigInventory( final ItemStack is ) { return new CellConfig( is ); } diff --git a/src/main/java/appeng/items/tools/powered/powersink/PoweredItemCapabilities.java b/src/main/java/appeng/items/tools/powered/powersink/PoweredItemCapabilities.java index 61226cc3b..656b60f51 100644 --- a/src/main/java/appeng/items/tools/powered/powersink/PoweredItemCapabilities.java +++ b/src/main/java/appeng/items/tools/powered/powersink/PoweredItemCapabilities.java @@ -27,7 +27,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilityProvider; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import appeng.api.config.PowerUnits; diff --git a/src/main/java/appeng/me/storage/CellInventory.java b/src/main/java/appeng/me/storage/CellInventory.java index cbcedd19f..b9bedeea6 100644 --- a/src/main/java/appeng/me/storage/CellInventory.java +++ b/src/main/java/appeng/me/storage/CellInventory.java @@ -21,11 +21,11 @@ package appeng.me.storage; import java.util.HashSet; -import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTBase; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.items.IItemHandler; import net.minecraftforge.oredict.OreDictionary; import appeng.api.AEApi; @@ -534,13 +534,13 @@ public class CellInventory implements ICellInventory } @Override - public IInventory getConfigInventory() + public IItemHandler getConfigInventory() { return this.cellType.getConfigInventory( this.i ); } @Override - public IInventory getUpgradesInventory() + public IItemHandler getUpgradesInventory() { return this.cellType.getUpgradesInventory( this.i ); } diff --git a/src/main/java/appeng/me/storage/CellInventoryHandler.java b/src/main/java/appeng/me/storage/CellInventoryHandler.java index 40a0b563a..5d83e415c 100644 --- a/src/main/java/appeng/me/storage/CellInventoryHandler.java +++ b/src/main/java/appeng/me/storage/CellInventoryHandler.java @@ -19,9 +19,9 @@ package appeng.me.storage; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.FuzzyMode; @@ -52,14 +52,14 @@ public class CellInventoryHandler extends MEInventoryHandler imple { final IItemList priorityList = AEApi.instance().storage().createItemList(); - final IInventory upgrades = ci.getUpgradesInventory(); - final IInventory config = ci.getConfigInventory(); + final IItemHandler upgrades = ci.getUpgradesInventory(); + final IItemHandler config = ci.getConfigInventory(); final FuzzyMode fzMode = ci.getFuzzyMode(); boolean hasInverter = false; boolean hasFuzzy = false; - for( int x = 0; x < upgrades.getSizeInventory(); x++ ) + for( int x = 0; x < upgrades.getSlots(); x++ ) { final ItemStack is = upgrades.getStackInSlot( x ); if( !is.isEmpty() && is.getItem() instanceof IUpgradeModule ) @@ -81,7 +81,7 @@ public class CellInventoryHandler extends MEInventoryHandler imple } } - for( int x = 0; x < config.getSizeInventory(); x++ ) + for( int x = 0; x < config.getSlots(); x++ ) { final ItemStack is = config.getStackInSlot( x ); if( !is.isEmpty() ) diff --git a/src/main/java/appeng/parts/AEBasePart.java b/src/main/java/appeng/parts/AEBasePart.java index a6601a22b..fd78a3f75 100644 --- a/src/main/java/appeng/parts/AEBasePart.java +++ b/src/main/java/appeng/parts/AEBasePart.java @@ -34,7 +34,6 @@ import net.minecraft.crash.CrashReportCategory; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -45,6 +44,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.Upgrades; @@ -344,7 +344,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { return null; } @@ -372,15 +372,15 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, pHost.setPriority( compound.getInteger( "priority" ) ); } - final IInventory inv = this.getInventoryByName( "config" ); + final IItemHandler inv = 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 ) ); } } } @@ -408,7 +408,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost, output.setInteger( "priority", pHost.getPriority() ); } - final IInventory inv = this.getInventoryByName( "config" ); + final IItemHandler inv = this.getInventoryByName( "config" ); if( inv instanceof AppEngInternalAEInventory ) { ( (AppEngInternalAEInventory) inv ).writeToNBT( output, "config" ); diff --git a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java index 339e4c51b..fbdd32227 100644 --- a/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/BlockUpgradeInventory.java @@ -25,7 +25,7 @@ import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import appeng.api.config.Upgrades; -import appeng.tile.inventory.IAEAppEngInventory; +import appeng.util.inv.IAEAppEngInventory; public class BlockUpgradeInventory extends UpgradeInventory diff --git a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java index 8f1b81f31..1f065e4d6 100644 --- a/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/DefinitionUpgradeInventory.java @@ -23,7 +23,7 @@ import net.minecraft.item.ItemStack; import appeng.api.config.Upgrades; import appeng.api.definitions.IItemDefinition; -import appeng.tile.inventory.IAEAppEngInventory; +import appeng.util.inv.IAEAppEngInventory; public final class DefinitionUpgradeInventory extends UpgradeInventory diff --git a/src/main/java/appeng/parts/automation/PartFormationPlane.java b/src/main/java/appeng/parts/automation/PartFormationPlane.java index 6e1b00f9f..7611e90c3 100644 --- a/src/main/java/appeng/parts/automation/PartFormationPlane.java +++ b/src/main/java/appeng/parts/automation/PartFormationPlane.java @@ -26,7 +26,6 @@ import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemFirework; @@ -43,6 +42,7 @@ import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; import net.minecraftforge.common.IPlantable; +import net.minecraftforge.items.IItemHandler; import appeng.api.AEApi; import appeng.api.config.AccessRestriction; @@ -78,8 +78,8 @@ import appeng.items.parts.PartModels; import appeng.me.GridAccessException; import appeng.me.storage.MEInventoryHandler; import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; +import appeng.util.inv.InvOperation; import appeng.util.prioritylist.FuzzyPriorityList; import appeng.util.prioritylist.PrecisePriorityList; @@ -119,7 +119,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine final IItemList priorityList = AEApi.instance().storage().createItemList(); final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9; - for( int x = 0; x < this.Config.getSizeInventory() && x < slotsToUse; x++ ) + for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ ) { final IAEItemStack is = this.Config.getAEStackInSlot( x ); if( is != null ) @@ -161,7 +161,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine } @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 ) { super.onChangeInventory( inv, slot, mc, removedStack, newStack ); @@ -195,7 +195,7 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "config" ) ) { @@ -456,7 +456,6 @@ public class PartFormationPlane extends PartUpgradeable implements ICellContaine EnumHand hand = player.getActiveHand(); player.setHeldItem( hand, is ); - // TODO: LIMIT FIREWORKS /* * if( i instanceof ItemFirework ) diff --git a/src/main/java/appeng/parts/automation/PartLevelEmitter.java b/src/main/java/appeng/parts/automation/PartLevelEmitter.java index 8df0be712..729c0bece 100644 --- a/src/main/java/appeng/parts/automation/PartLevelEmitter.java +++ b/src/main/java/appeng/parts/automation/PartLevelEmitter.java @@ -23,7 +23,6 @@ import java.util.Collection; import java.util.Random; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -34,6 +33,7 @@ import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.FuzzyMode; import appeng.api.config.LevelType; @@ -76,8 +76,8 @@ import appeng.items.parts.PartModels; import appeng.me.GridAccessException; import appeng.parts.PartModel; import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; +import appeng.util.inv.InvOperation; public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherHost, IStackWatcherHost, ICraftingWatcherHost, IMEMonitorHandlerReceiver, ICraftingProvider @@ -479,7 +479,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH } @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.config ) { @@ -522,7 +522,7 @@ public class PartLevelEmitter extends PartUpgradeable implements IEnergyWatcherH } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "config" ) ) { diff --git a/src/main/java/appeng/parts/automation/PartSharedItemBus.java b/src/main/java/appeng/parts/automation/PartSharedItemBus.java index 425fb3ed4..b75d02534 100644 --- a/src/main/java/appeng/parts/automation/PartSharedItemBus.java +++ b/src/main/java/appeng/parts/automation/PartSharedItemBus.java @@ -19,11 +19,11 @@ package appeng.parts.automation; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.RedstoneMode; import appeng.api.config.Upgrades; @@ -69,7 +69,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "config" ) ) { @@ -125,7 +125,7 @@ public abstract class PartSharedItemBus extends PartUpgradeable implements IGrid protected int availableSlots() { - return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSizeInventory() ); + return Math.min( 1 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 4, this.getConfig().getSlots() ); } protected int calculateItemsToSend() diff --git a/src/main/java/appeng/parts/automation/PartUpgradeable.java b/src/main/java/appeng/parts/automation/PartUpgradeable.java index cca94b81b..aead02121 100644 --- a/src/main/java/appeng/parts/automation/PartUpgradeable.java +++ b/src/main/java/appeng/parts/automation/PartUpgradeable.java @@ -21,17 +21,17 @@ package appeng.parts.automation; import java.util.List; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.RedstoneMode; import appeng.api.config.Upgrades; import appeng.api.util.IConfigManager; import appeng.parts.PartBasicState; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.ConfigManager; import appeng.util.IConfigManagerHost; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; public abstract class PartUpgradeable extends PartBasicState implements IAEAppEngInventory, IConfigManagerHost @@ -59,7 +59,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn } @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.upgrades ) { @@ -155,7 +155,7 @@ public abstract class PartUpgradeable extends PartBasicState implements IAEAppEn } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "upgrades" ) ) { diff --git a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java index 0ef879ba9..8ea57e6d9 100644 --- a/src/main/java/appeng/parts/automation/StackUpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/StackUpgradeInventory.java @@ -22,8 +22,8 @@ package appeng.parts.automation; import net.minecraft.item.ItemStack; import appeng.api.config.Upgrades; -import appeng.tile.inventory.IAEAppEngInventory; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; public class StackUpgradeInventory extends UpgradeInventory diff --git a/src/main/java/appeng/parts/automation/UpgradeInventory.java b/src/main/java/appeng/parts/automation/UpgradeInventory.java index d93570fa8..e9ad59c1c 100644 --- a/src/main/java/appeng/parts/automation/UpgradeInventory.java +++ b/src/main/java/appeng/parts/automation/UpgradeInventory.java @@ -20,17 +20,18 @@ package appeng.parts.automation; import net.minecraft.init.Items; -import net.minecraft.inventory.IInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.Upgrades; import appeng.api.implementations.items.IUpgradeModule; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; +import appeng.util.inv.filter.IAEItemFilter; public abstract class UpgradeInventory extends AppEngInternalInventory implements IAEAppEngInventory @@ -47,9 +48,10 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement public UpgradeInventory( final IAEAppEngInventory parent, final int s ) { - super( null, s ); + super( null, s, 1 ); this.setTileEntity( this ); this.parent = parent; + this.setFilter( new UpgradeInvFilter() ); } @Override @@ -58,31 +60,6 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement return true; } - @Override - public int getInventoryStackLimit() - { - return 1; - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - if( itemstack.isEmpty() ) - { - return false; - } - final Item it = itemstack.getItem(); - if( it instanceof IUpgradeModule ) - { - final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack ); - if( u != null ) - { - return this.getInstalledUpgrades( u ) < this.getMaxInstalled( u ); - } - } - return false; - } - public int getInstalledUpgrades( final Upgrades u ) { if( !this.cached ) @@ -171,7 +148,7 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement } @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 ) { this.cached = false; if( this.parent != null && Platform.isServer() ) @@ -179,4 +156,33 @@ public abstract class UpgradeInventory extends AppEngInternalInventory implement this.parent.onChangeInventory( inv, slot, mc, removedStack, newStack ); } } + + private class UpgradeInvFilter implements IAEItemFilter + { + + @Override + public boolean allowExtract( IItemHandler inv, int slot, int amount ) + { + return true; + } + + @Override + public boolean allowInsert( IItemHandler inv, int slot, ItemStack itemstack ) + { + if( itemstack.isEmpty() ) + { + return false; + } + final Item it = itemstack.getItem(); + if( it instanceof IUpgradeModule ) + { + final Upgrades u = ( (IUpgradeModule) it ).getType( itemstack ); + if( u != null ) + { + return getInstalledUpgrades( u ) < getMaxInstalled( u ); + } + } + return false; + } + } } diff --git a/src/main/java/appeng/parts/misc/PartInterface.java b/src/main/java/appeng/parts/misc/PartInterface.java index 4c61ff1be..0743ab2be 100644 --- a/src/main/java/appeng/parts/misc/PartInterface.java +++ b/src/main/java/appeng/parts/misc/PartInterface.java @@ -25,8 +25,6 @@ import java.util.List; import com.google.common.collect.ImmutableSet; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; @@ -35,8 +33,8 @@ import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; -import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.Actionable; import appeng.api.config.Upgrades; @@ -67,13 +65,13 @@ import appeng.helpers.Reflected; import appeng.items.parts.PartModels; import appeng.parts.PartBasicState; import appeng.parts.PartModel; -import appeng.tile.inventory.IAEAppEngInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; +import appeng.util.inv.IAEAppEngInventory; import appeng.util.inv.IInventoryDestination; +import appeng.util.inv.InvOperation; -public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, ISidedInventory, IAEAppEngInventory, IPriorityHost +public class PartInterface extends PartBasicState implements IGridTickable, IStorageMonitorable, IInventoryDestination, IInterfaceHost, IAEAppEngInventory, IPriorityHost { public static final ResourceLocation MODEL_BASE = new ResourceLocation( AppEng.MOD_ID, "part/interface_base" ); @@ -166,7 +164,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { return this.duality.getInventoryByName( name ); } @@ -218,103 +216,7 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto } @Override - public int getSizeInventory() - { - return this.duality.getStorage().getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot( final int i ) - { - return this.duality.getStorage().getStackInSlot( i ); - } - - @Override - public ItemStack decrStackSize( final int i, final int j ) - { - return this.duality.getStorage().decrStackSize( i, j ); - } - - @Override - public ItemStack removeStackFromSlot( final int i ) - { - return this.duality.getStorage().removeStackFromSlot( i ); - } - - @Override - public void setInventorySlotContents( final int i, final ItemStack itemstack ) - { - this.duality.getStorage().setInventorySlotContents( i, itemstack ); - } - - @Override - public String getName() - { - return this.duality.getStorage().getName(); - } - - @Override - public boolean hasCustomName() - { - return this.duality.getStorage().hasCustomName(); - } - - @Override - public int getInventoryStackLimit() - { - return this.duality.getStorage().getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - this.duality.getStorage().markDirty(); - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer entityplayer ) - { - return this.duality.getStorage().isUsableByPlayer( entityplayer ); - } - - @Override - public void openInventory( final EntityPlayer player ) - { - this.duality.getStorage().openInventory( player ); - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - this.duality.getStorage().closeInventory( player ); - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - return this.duality.getStorage().isItemValidForSlot( i, itemstack ); - } - - @Override - public int[] getSlotsForFace( final EnumFacing side ) - { - return this.duality.getSlotsForFace( side ); - } - - @Override - public boolean canInsertItem( final int i, final ItemStack itemstack, final EnumFacing j ) - { - return true; - } - - @Override - public boolean canExtractItem( final int i, final ItemStack itemstack, final EnumFacing j ) - { - return true; - } - - @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 ) { this.duality.onChangeInventory( inv, slot, mc, removedStack, newStack ); } @@ -385,36 +287,6 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto this.duality.setPriority( newValue ); } - @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 ITextComponent getDisplayName() - { - return null; - } - @Override public IPartModel getStaticModels() { @@ -443,12 +315,4 @@ public class PartInterface extends PartBasicState implements IGridTickable, ISto { return this.duality.getCapability( capabilityClass, this.getSide().getFacing() ); } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } - } diff --git a/src/main/java/appeng/parts/misc/PartStorageBus.java b/src/main/java/appeng/parts/misc/PartStorageBus.java index 59797a4c1..3f8e58237 100644 --- a/src/main/java/appeng/parts/misc/PartStorageBus.java +++ b/src/main/java/appeng/parts/misc/PartStorageBus.java @@ -24,7 +24,6 @@ import java.util.Collections; import java.util.List; import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -85,8 +84,8 @@ import appeng.me.storage.MEMonitorIInventory; import appeng.parts.PartModel; import appeng.parts.automation.PartUpgradeable; import appeng.tile.inventory.AppEngInternalAEInventory; -import appeng.tile.inventory.InvOperation; import appeng.util.Platform; +import appeng.util.inv.InvOperation; import appeng.util.prioritylist.FuzzyPriorityList; import appeng.util.prioritylist.PrecisePriorityList; @@ -170,7 +169,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC } @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 ) { super.onChangeInventory( inv, slot, mc, removedStack, newStack ); @@ -204,7 +203,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "config" ) ) { @@ -449,7 +448,7 @@ public class PartStorageBus extends PartUpgradeable implements IGridTickable, IC final IItemList priorityList = AEApi.instance().storage().createItemList(); final int slotsToUse = 18 + this.getInstalledUpgrades( Upgrades.CAPACITY ) * 9; - for( int x = 0; x < this.Config.getSizeInventory() && x < slotsToUse; x++ ) + for( int x = 0; x < this.Config.getSlots() && x < slotsToUse; x++ ) { final IAEItemStack is = this.Config.getAEStackInSlot( x ); if( is != null ) diff --git a/src/main/java/appeng/parts/p2p/PartP2PFEPower.java b/src/main/java/appeng/parts/p2p/PartP2PFEPower.java index b7201a310..af6ac9e6a 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PFEPower.java +++ b/src/main/java/appeng/parts/p2p/PartP2PFEPower.java @@ -1,21 +1,19 @@ /* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, AlgorithmX2, All rights reserved. * - * * This file is part of Applied Energistics 2. - * * Copyright (c) 2013 - 2017, 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 . + * 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 . */ package appeng.parts.p2p; @@ -30,7 +28,6 @@ import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.math.BlockPos; import net.minecraftforge.common.capabilities.Capability; -import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import appeng.api.config.PowerUnits; diff --git a/src/main/java/appeng/parts/p2p/PartP2PItems.java b/src/main/java/appeng/parts/p2p/PartP2PItems.java index 294246962..fc78981ca 100644 --- a/src/main/java/appeng/parts/p2p/PartP2PItems.java +++ b/src/main/java/appeng/parts/p2p/PartP2PItems.java @@ -19,22 +19,16 @@ package appeng.parts.p2p; -import java.util.LinkedList; +import java.util.ArrayList; import java.util.List; -import javax.annotation.Nonnull; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityChest; import net.minecraft.util.EnumFacing; -import net.minecraft.util.text.ITextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.EmptyHandler; import appeng.api.networking.IGridNode; import appeng.api.networking.events.MENetworkBootingStatusChange; @@ -49,19 +43,15 @@ import appeng.core.settings.TickRates; import appeng.items.parts.PartModels; import appeng.me.GridAccessException; import appeng.me.cache.helpers.TunnelCollection; -import appeng.tile.inventory.AppEngNullInventory; import appeng.util.Platform; -import appeng.util.inv.AdaptorIInventory; -import appeng.util.inv.WrapperChainedInventory; -import appeng.util.inv.WrapperMCISidedInventory; +import appeng.util.inv.WrapperChainedItemHandler; -// TODO: BC Integration -//@Interface( iface = "buildcraft.api.transport.IPipeConnection", iname = IntegrationType.BuildCraftTransport ) -public class PartP2PItems extends PartP2PTunnel implements /* IPipeConnection, */ISidedInventory, IGridTickable, IItemHandler +public class PartP2PItems extends PartP2PTunnel implements IItemHandler, IGridTickable { - + private static final float POWER_DRAIN = 2.0f; private static final P2PModels MODELS = new P2PModels( "part/p2p/p2p_tunnel_items" ); + private boolean partVisited = false; @PartModels public static List getModels() @@ -69,10 +59,9 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip return MODELS.getModels(); } - private final LinkedList which = new LinkedList<>(); private int oldSize = 0; private boolean requested; - private IInventory cachedInv; + private IItemHandler cachedInv; public PartP2PItems( final ItemStack is ) { @@ -90,7 +79,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip } } - private IInventory getDestination() + private IItemHandler getDestination() { this.requested = true; @@ -99,7 +88,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip return this.cachedInv; } - final List outs = new LinkedList<>(); + final List outs = new ArrayList(); final TunnelCollection itemTunnels; try @@ -108,13 +97,13 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip } catch( final GridAccessException e ) { - return new AppEngNullInventory(); + return EmptyHandler.INSTANCE; } for( final PartP2PItems t : itemTunnels ) { - final IInventory inv = t.getOutputInv(); - if( inv != null ) + final IItemHandler inv = t.getOutputInv(); + if( inv != null && inv != this ) { if( Platform.getRandomInt() % 2 == 0 ) { @@ -127,44 +116,28 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip } } - return this.cachedInv = new WrapperChainedInventory( outs ); + return this.cachedInv = new WrapperChainedItemHandler( outs.toArray( new IItemHandler[outs.size()] ) ); } - private IInventory getOutputInv() + private IItemHandler getOutputInv() { - IInventory output = null; - - if( this.getProxy().isActive() ) + IItemHandler ret = null; + if( !partVisited ) { - final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( this.getSide().getFacing() ) ); - - if( this.which.contains( this ) ) + partVisited = true; + if( this.getProxy().isActive() ) { - return null; - } + final EnumFacing facing = this.getSide().getFacing(); + final TileEntity te = this.getTile().getWorld().getTileEntity( this.getTile().getPos().offset( facing ) ); - this.which.add( this ); - - if( output == null ) - { - if( te instanceof TileEntityChest ) + if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ) ) { - output = Platform.GetChestInv( te ); - } - else if( te instanceof ISidedInventory ) - { - output = new WrapperMCISidedInventory( (ISidedInventory) te, this.getSide().getFacing().getOpposite() ); - } - else if( te instanceof IInventory ) - { - output = (IInventory) te; + ret = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, facing.getOpposite() ); } } - - this.which.pop(); + partVisited = false; } - - return output; + return ret; } @Override @@ -180,7 +153,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip if( this.requested && this.cachedInv != null ) { - ( (WrapperChainedInventory) this.cachedInv ).cycleOrder(); + ( (WrapperChainedItemHandler) this.cachedInv ).cycleOrder(); } this.requested = false; @@ -194,7 +167,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip { this.cachedInv = null; final int olderSize = this.oldSize; - this.oldSize = this.getDestination().getSizeInventory(); + this.oldSize = this.getDestination().getSlots(); if( olderSize != this.oldSize ) { this.getHost().notifyNeighbors(); @@ -209,7 +182,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip { this.cachedInv = null; final int olderSize = this.oldSize; - this.oldSize = this.getDestination().getSizeInventory(); + this.oldSize = this.getDestination().getSlots(); if( olderSize != this.oldSize ) { this.getHost().notifyNeighbors(); @@ -224,7 +197,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip { this.cachedInv = null; final int olderSize = this.oldSize; - this.oldSize = this.getDestination().getSizeInventory(); + this.oldSize = this.getDestination().getSlots(); if( olderSize != this.oldSize ) { this.getHost().notifyNeighbors(); @@ -239,7 +212,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip { this.cachedInv = null; final int olderSize = this.oldSize; - this.oldSize = this.getDestination().getSizeInventory(); + this.oldSize = this.getDestination().getSlots(); if( olderSize != this.oldSize ) { this.getHost().notifyNeighbors(); @@ -255,164 +228,6 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip } } - @Override - public int[] getSlotsForFace( final EnumFacing side ) - { - final int[] slots = new int[this.getSizeInventory()]; - for( int x = 0; x < this.getSizeInventory(); x++ ) - { - slots[x] = x; - } - return slots; - } - - @Override - public int getSizeInventory() - { - return this.getDestination().getSizeInventory(); - } - - /** - * Returns the number of slots available - * - * @return The number of slots available - **/ - @Override - public int getSlots() - { - return this.getSizeInventory(); - } - - @Override - public ItemStack getStackInSlot( final int i ) - { - return this.getDestination().getStackInSlot( i ); - } - - /** - * Inserts an ItemStack into the given slot and return the remainder. - * The ItemStack should not be modified in this function! - * Note: This behaviour is subtly different from IFluidHandlers.fill() - * - * @param slot Slot to insert into. - * @param stack ItemStack to insert. - * @param simulate If true, the insertion is only simulated - * @return The remaining ItemStack that was not inserted (if the entire stack is accepted, then return - * ItemStack.EMPTY). - * May be the same as the input ItemStack if unchanged, otherwise a new ItemStack. - **/ - @Nonnull - @Override - public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate ) - { - - if( this.isItemValidForSlot( slot, stack ) ) - { - AdaptorIInventory adaptor = new AdaptorIInventory( this.getDestination() ); - - if( simulate ) - { - return adaptor.simulateAdd( stack ); - } - else - { - return adaptor.addItems( stack ); - } - } - return stack; - } - - /** - * Extracts an ItemStack from the given slot. The returned value must be null - * if nothing is extracted, otherwise it's stack size must not be greater than amount or the - * itemstacks getMaxStackSize(). - * - * @param slot Slot to extract from. - * @param amount Amount to extract (may be greater than the current stacks max limit) - * @param simulate If true, the extraction is only simulated - * @return ItemStack extracted from the slot, must be ItemStack.EMPTY, if nothing can be extracted - **/ - @Nonnull - @Override - public ItemStack extractItem( int slot, int amount, boolean simulate ) - { - return ItemStack.EMPTY; - } - - /** - * Retrieves the maximum stack size allowed to exist in the given slot. - * - * @param slot Slot to query. - * @return The maximum stack size allowed in the slot. - */ - @Override - public int getSlotLimit( int slot ) - { - if( slot >= 0 && slot < this.getDestination().getSizeInventory() ) - { - return this.getDestination().getInventoryStackLimit(); - } - return 0; - } - - @Override - public ItemStack decrStackSize( final int i, final int j ) - { - return this.getDestination().decrStackSize( i, j ); - } - - @Override - public ItemStack removeStackFromSlot( final int i ) - { - return ItemStack.EMPTY; - } - - @Override - public void setInventorySlotContents( final int i, final ItemStack itemstack ) - { - this.getDestination().setInventorySlotContents( i, itemstack ); - } - - @Override - public String getName() - { - return null; - } - - @Override - public boolean hasCustomName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return this.getDestination().getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - // eh? - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer entityplayer ) - { - return false; - } - - @Override - public void openInventory( final EntityPlayer p ) - { - } - - @Override - public void closeInventory( final EntityPlayer p ) - { - } - @Override public boolean hasCapability( Capability capabilityClass ) { @@ -424,6 +239,7 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip return super.hasCapability( capabilityClass ); } + @SuppressWarnings( "unchecked" ) @Override public T getCapability( Capability capabilityClass ) { @@ -436,76 +252,43 @@ public class PartP2PItems extends PartP2PTunnel implements /* IPip } @Override - public boolean isItemValidForSlot( final int i, final net.minecraft.item.ItemStack itemstack ) + public int getSlots() { - return this.getDestination().isItemValidForSlot( i, itemstack ); + return this.getDestination().getSlots(); } @Override - public boolean canInsertItem( final int i, final ItemStack itemstack, final EnumFacing j ) + public ItemStack getStackInSlot( final int i ) { - return this.getDestination().isItemValidForSlot( i, itemstack ); + return this.getDestination().getStackInSlot( i ); } @Override - public boolean canExtractItem( final int i, final ItemStack itemstack, final EnumFacing j ) + public ItemStack insertItem( final int slot, final ItemStack stack, boolean simulate ) { - return false; + return this.getDestination().insertItem( slot, stack, simulate ); + } + + @Override + public ItemStack extractItem( final int slot, final int amount, boolean simulate ) + { + return this.getDestination().extractItem( slot, amount, simulate ); + } + + @Override + public int getSlotLimit( int slot ) + { + return this.getDestination().getSlotLimit( slot ); } public float getPowerDrainPerTick() { - return 2.0f; - } - - @Override - public int getField( final int id ) - { - return 0; - } - - // @Override - // @Method( iname = IntegrationType.BuildCraftTransport ) - // public ConnectOverride overridePipeConnection( PipeType type, ForgeDirection with ) - // { - // return 0; - // } - - @Override - public void setField( final int id, final int value ) - { - - } - - @Override - public int getFieldCount() - { - return 0; - } - - @Override - public void clear() - { - // probably not... - } - - @Override - public ITextComponent getDisplayName() - { - return null; + return POWER_DRAIN; } @Override public IPartModel getStaticModels() { - return MODELS.getModel( this.isPowered(), this.isActive() ); + return MODELS.getModel( isPowered(), isActive() ); } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } - } diff --git a/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java b/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java index 6900f6ec3..71651a1d9 100644 --- a/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java +++ b/src/main/java/appeng/parts/reporting/AbstractPartTerminal.java @@ -22,11 +22,11 @@ package appeng.parts.reporting; import java.util.List; 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.EnumHand; import net.minecraft.util.math.Vec3d; +import net.minecraftforge.items.IItemHandler; import appeng.api.config.Settings; import appeng.api.config.SortDir; @@ -41,11 +41,11 @@ import appeng.api.util.IConfigManager; import appeng.core.sync.GuiBridge; import appeng.me.GridAccessException; 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.inv.IAEAppEngInventory; +import appeng.util.inv.InvOperation; /** @@ -170,13 +170,13 @@ public abstract class AbstractPartTerminal extends AbstractPartDisplay implement } @Override - public IInventory getViewCellStorage() + public IItemHandler getViewCellStorage() { return this.viewCell; } @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 ) { this.getHost().markForSave(); } diff --git a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java index ac0e28bbf..088711648 100644 --- a/src/main/java/appeng/parts/reporting/PartConversionMonitor.java +++ b/src/main/java/appeng/parts/reporting/PartConversionMonitor.java @@ -25,7 +25,6 @@ import java.util.List; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.Vec3d; @@ -162,7 +161,7 @@ public class PartConversionMonitor extends AbstractPartMonitor if( retrieved != null ) { ItemStack newItems = retrieved.getItemStack(); - final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player, EnumFacing.UP ); + final InventoryAdaptor adaptor = InventoryAdaptor.getAdaptor( player ); newItems = adaptor.addItems( newItems ); if( !newItems.isEmpty() ) { diff --git a/src/main/java/appeng/parts/reporting/PartCraftingTerminal.java b/src/main/java/appeng/parts/reporting/PartCraftingTerminal.java index 2fa7aaeb7..d4fd1413a 100644 --- a/src/main/java/appeng/parts/reporting/PartCraftingTerminal.java +++ b/src/main/java/appeng/parts/reporting/PartCraftingTerminal.java @@ -22,10 +22,10 @@ package appeng.parts.reporting; import java.util.List; 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.ResourceLocation; +import net.minecraftforge.items.IItemHandler; import appeng.api.parts.IPartModel; import appeng.core.AppEng; @@ -105,7 +105,7 @@ public class PartCraftingTerminal extends AbstractPartTerminal } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "crafting" ) ) { diff --git a/src/main/java/appeng/parts/reporting/PartPatternTerminal.java b/src/main/java/appeng/parts/reporting/PartPatternTerminal.java index d03e83100..a1af924c1 100644 --- a/src/main/java/appeng/parts/reporting/PartPatternTerminal.java +++ b/src/main/java/appeng/parts/reporting/PartPatternTerminal.java @@ -22,10 +22,10 @@ package appeng.parts.reporting; import java.util.List; 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.ResourceLocation; +import net.minecraftforge.items.IItemHandler; import appeng.api.implementations.ICraftingPatternItem; import appeng.api.networking.crafting.ICraftingPatternDetails; @@ -37,7 +37,7 @@ import appeng.helpers.Reflected; import appeng.items.parts.PartModels; import appeng.parts.PartModel; import appeng.tile.inventory.AppEngInternalInventory; -import appeng.tile.inventory.InvOperation; +import appeng.util.inv.InvOperation; public class PartPatternTerminal extends AbstractPartTerminal @@ -120,7 +120,7 @@ public class PartPatternTerminal extends AbstractPartTerminal } @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.pattern && slot == 1 ) { @@ -134,16 +134,16 @@ public class PartPatternTerminal extends AbstractPartTerminal this.setCraftingRecipe( details.isCraftable() ); this.setSubstitution( details.canSubstitute() ); - for( int x = 0; x < this.crafting.getSizeInventory() && x < details.getInputs().length; x++ ) + for( int x = 0; x < this.crafting.getSlots() && x < details.getInputs().length; x++ ) { final IAEItemStack item = details.getInputs()[x]; - this.crafting.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); + this.crafting.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); } - for( int x = 0; x < this.output.getSizeInventory() && x < details.getOutputs().length; x++ ) + for( int x = 0; x < this.output.getSlots() && x < details.getOutputs().length; x++ ) { final IAEItemStack item = details.getOutputs()[x]; - this.output.setInventorySlotContents( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); + this.output.setStackInSlot( x, item == null ? ItemStack.EMPTY : item.getItemStack() ); } } } @@ -160,7 +160,7 @@ public class PartPatternTerminal extends AbstractPartTerminal { if( this.craftingMode ) { - for( int x = 0; x < this.crafting.getSizeInventory(); x++ ) + for( int x = 0; x < this.crafting.getSlots(); x++ ) { final ItemStack is = this.crafting.getStackInSlot( x ); if( !is.isEmpty() ) @@ -193,7 +193,7 @@ public class PartPatternTerminal extends AbstractPartTerminal } @Override - public IInventory getInventoryByName( final String name ) + public IItemHandler getInventoryByName( final String name ) { if( name.equals( "crafting" ) ) { diff --git a/src/main/java/appeng/recipes/loader/RecipeResourceCopier.java b/src/main/java/appeng/recipes/loader/RecipeResourceCopier.java index ef64acdde..99ae1a7b8 100644 --- a/src/main/java/appeng/recipes/loader/RecipeResourceCopier.java +++ b/src/main/java/appeng/recipes/loader/RecipeResourceCopier.java @@ -232,7 +232,7 @@ public class RecipeResourceCopier { final Enumeration entries = jar.entries(); // gives ALL entries in jar final Collection result = new HashSet<>( INITIAL_RESOURCE_CAPACITY ); // avoid - // duplicates + // duplicates // in case it is a // subdirectory diff --git a/src/main/java/appeng/tile/AEBaseInvTile.java b/src/main/java/appeng/tile/AEBaseInvTile.java index 265cf565b..37b3ec8f1 100644 --- a/src/main/java/appeng/tile/AEBaseInvTile.java +++ b/src/main/java/appeng/tile/AEBaseInvTile.java @@ -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 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 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 ); diff --git a/src/main/java/appeng/tile/AEBaseTile.java b/src/main/java/appeng/tile/AEBaseTile.java index c0cb24272..193773b95 100644 --- a/src/main/java/appeng/tile/AEBaseTile.java +++ b/src/main/java/appeng/tile/AEBaseTile.java @@ -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 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 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" ); diff --git a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java index 609a6bc1e..06c14c496 100644 --- a/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java +++ b/src/main/java/appeng/tile/crafting/TileMolecularAssembler.java @@ -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; + } + } } diff --git a/src/main/java/appeng/tile/grid/AENetworkInvTile.java b/src/main/java/appeng/tile/grid/AENetworkInvTile.java index 6dc0c7c2c..e9618f819 100644 --- a/src/main/java/appeng/tile/grid/AENetworkInvTile.java +++ b/src/main/java/appeng/tile/grid/AENetworkInvTile.java @@ -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; - } - } diff --git a/src/main/java/appeng/tile/grindstone/TileGrinder.java b/src/main/java/appeng/tile/grindstone/TileGrinder.java index bc3171c5c..1e87f310b 100644 --- a/src/main/java/appeng/tile/grindstone/TileGrinder.java +++ b/src/main/java/appeng/tile/grindstone/TileGrinder.java @@ -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; + } } + } diff --git a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java index 5869b4406..379a5448c 100644 --- a/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java +++ b/src/main/java/appeng/tile/inventory/AppEngInternalAEInventory.java @@ -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 +public class AppEngInternalAEInventory implements IInternalItemHandler, Iterable { - private final IAEAppEngInventory te; private final IAEItemStack[] inv; private final int size; @@ -52,19 +54,6 @@ public class AppEngInternalAEInventory implements IInventory, Iterable 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 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 +public class AppEngInternalInventory extends ItemStackHandler implements IInternalItemHandler, Iterable { - 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 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 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 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() diff --git a/src/main/java/appeng/tile/misc/TileCellWorkbench.java b/src/main/java/appeng/tile/misc/TileCellWorkbench.java index 4cd9f04e9..91f418a0c 100644 --- a/src/main/java/appeng/tile/misc/TileCellWorkbench.java +++ b/src/main/java/appeng/tile/misc/TileCellWorkbench.java @@ -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; diff --git a/src/main/java/appeng/tile/misc/TileCharger.java b/src/main/java/appeng/tile/misc/TileCharger.java index 0e66d082b..9fcd9bfad 100644 --- a/src/main/java/appeng/tile/misc/TileCharger.java +++ b/src/main/java/appeng/tile/misc/TileCharger.java @@ -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 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 ); + } } } diff --git a/src/main/java/appeng/tile/misc/TileCondenser.java b/src/main/java/appeng/tile/misc/TileCondenser.java index ecdb70d40..9d3206e5d 100644 --- a/src/main/java/appeng/tile/misc/TileCondenser.java +++ b/src/main/java/appeng/tile/misc/TileCondenser.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/misc/TileInscriber.java b/src/main/java/appeng/tile/misc/TileInscriber.java index 71b41c6e4..25ddb2538 100644 --- a/src/main/java/appeng/tile/misc/TileInscriber.java +++ b/src/main/java/appeng/tile/misc/TileInscriber.java @@ -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 getCapability( Capability 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; - } - } diff --git a/src/main/java/appeng/tile/misc/TileInterface.java b/src/main/java/appeng/tile/misc/TileInterface.java index 2632f458b..eef0e0066 100644 --- a/src/main/java/appeng/tile/misc/TileInterface.java +++ b/src/main/java/appeng/tile/misc/TileInterface.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/misc/TileSecurityStation.java b/src/main/java/appeng/tile/misc/TileSecurityStation.java index 84e008dc0..8bd2139f3 100644 --- a/src/main/java/appeng/tile/misc/TileSecurityStation.java +++ b/src/main/java/appeng/tile/misc/TileSecurityStation.java @@ -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 drops ) { - if( !this.getConfigSlot().isEmpty() ) + if( !ItemHandlerUtil.isEmpty( this.getConfigSlot() ) ) { drops.add( this.getConfigSlot().getStackInSlot( 0 ) ); } diff --git a/src/main/java/appeng/tile/misc/TileVibrationChamber.java b/src/main/java/appeng/tile/misc/TileVibrationChamber.java index 0b7558c94..6f4d80bad 100644 --- a/src/main/java/appeng/tile/misc/TileVibrationChamber.java +++ b/src/main/java/appeng/tile/misc/TileVibrationChamber.java @@ -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; + } } } diff --git a/src/main/java/appeng/tile/networking/TileController.java b/src/main/java/appeng/tile/networking/TileController.java index d7f0a9db8..e11f8bed5 100644 --- a/src/main/java/appeng/tile/networking/TileController.java +++ b/src/main/java/appeng/tile/networking/TileController.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java b/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java index 77196906d..c9ecb7bd9 100644 --- a/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java +++ b/src/main/java/appeng/tile/networking/TileEnergyAcceptor.java @@ -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; - } - } diff --git a/src/main/java/appeng/tile/networking/TileWireless.java b/src/main/java/appeng/tile/networking/TileWireless.java index ccac20976..28e970fd9 100644 --- a/src/main/java/appeng/tile/networking/TileWireless.java +++ b/src/main/java/appeng/tile/networking/TileWireless.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/powersink/AERootPoweredTile.java b/src/main/java/appeng/tile/powersink/AERootPoweredTile.java index fee98fac0..00cab4992 100644 --- a/src/main/java/appeng/tile/powersink/AERootPoweredTile.java +++ b/src/main/java/appeng/tile/powersink/AERootPoweredTile.java @@ -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; diff --git a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java index 746f8998b..8b51a0152 100644 --- a/src/main/java/appeng/tile/qnb/TileQuantumBridge.java +++ b/src/main/java/appeng/tile/qnb/TileQuantumBridge.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/spatial/TileSpatialIOPort.java b/src/main/java/appeng/tile/spatial/TileSpatialIOPort.java index b40266fb4..9217e83b1 100644 --- a/src/main/java/appeng/tile/spatial/TileSpatialIOPort.java +++ b/src/main/java/appeng/tile/spatial/TileSpatialIOPort.java @@ -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 { - 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; } } diff --git a/src/main/java/appeng/tile/storage/TileChest.java b/src/main/java/appeng/tile/storage/TileChest.java index 3585b8136..c623f1bd6 100644 --- a/src/main/java/appeng/tile/storage/TileChest.java +++ b/src/main/java/appeng/tile/storage/TileChest.java @@ -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 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 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 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; + } + + } + } diff --git a/src/main/java/appeng/tile/storage/TileDrive.java b/src/main/java/appeng/tile/storage/TileDrive.java index 5f54d903b..fc8a89561 100644 --- a/src/main/java/appeng/tile/storage/TileDrive.java +++ b/src/main/java/appeng/tile/storage/TileDrive.java @@ -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[] 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 ); + } + } } diff --git a/src/main/java/appeng/tile/storage/TileIOPort.java b/src/main/java/appeng/tile/storage/TileIOPort.java index 46554db90..985c4daa5 100644 --- a/src/main/java/appeng/tile/storage/TileIOPort.java +++ b/src/main/java/appeng/tile/storage/TileIOPort.java @@ -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; - } } diff --git a/src/main/java/appeng/tile/storage/TileSkyChest.java b/src/main/java/appeng/tile/storage/TileSkyChest.java index 916311dd0..6251745d6 100644 --- a/src/main/java/appeng/tile/storage/TileSkyChest.java +++ b/src/main/java/appeng/tile/storage/TileSkyChest.java @@ -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; - } } diff --git a/src/main/java/appeng/util/InventoryAdaptor.java b/src/main/java/appeng/util/InventoryAdaptor.java index 8f779e3c7..f0b2e04ae 100644 --- a/src/main/java/appeng/util/InventoryAdaptor.java +++ b/src/main/java/appeng/util/InventoryAdaptor.java @@ -19,26 +19,18 @@ package appeng.util; -import java.util.ArrayList; - import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.ISidedInventory; import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntityChest; +import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; -import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.PlayerInvWrapper; import appeng.api.config.FuzzyMode; -import appeng.util.inv.AdaptorIInventory; import appeng.util.inv.AdaptorItemHandler; -import appeng.util.inv.AdaptorList; -import appeng.util.inv.AdaptorPlayerInventory; import appeng.util.inv.IInventoryDestination; import appeng.util.inv.ItemSlot; -import appeng.util.inv.WrapperMCISidedInventory; /** @@ -49,60 +41,26 @@ import appeng.util.inv.WrapperMCISidedInventory; */ public abstract class InventoryAdaptor implements Iterable { - - // returns an appropriate adaptor, or null - public static InventoryAdaptor getAdaptor( final Object te, final EnumFacing d ) + public static InventoryAdaptor getAdaptor( final TileEntity te, final EnumFacing d ) { - if( te == null ) + if( te != null && te.hasCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ) ) { - return null; - } - - if( te instanceof ICapabilityProvider ) - { - ICapabilityProvider capProvider = (ICapabilityProvider) te; - // Attempt getting an IItemHandler for the given side via caps - IItemHandler itemHandler = capProvider.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ); - if( itemHandler != null && itemHandler.getSlots() > 0 ) + IItemHandler itemHandler = te.getCapability( CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, d ); + if( itemHandler != null ) { return new AdaptorItemHandler( itemHandler ); } } + return null; + } - if( te instanceof EntityPlayer ) + public static InventoryAdaptor getAdaptor( final EntityPlayer te ) + { + if( te != null ) { - return new AdaptorIInventory( new AdaptorPlayerInventory( ( (EntityPlayer) te ).inventory, false ) ); + return new AdaptorItemHandler( new PlayerInvWrapper( te.inventory ) ); } - else if( te instanceof ArrayList ) - { - @SuppressWarnings( "unchecked" ) - final ArrayList list = (ArrayList) te; - - return new AdaptorList( list ); - } - else if( te instanceof TileEntityChest ) - { - return new AdaptorIInventory( Platform.GetChestInv( te ) ); - } - else if( te instanceof ISidedInventory ) - { - final ISidedInventory si = (ISidedInventory) te; - final int[] slots = si.getSlotsForFace( d ); - if( si.getSizeInventory() > 0 && slots != null && slots.length > 0 ) - { - return new AdaptorIInventory( new WrapperMCISidedInventory( si, d ) ); - } - } - else if( te instanceof IInventory ) - { - final IInventory i = (IInventory) te; - if( i.getSizeInventory() > 0 ) - { - return new AdaptorIInventory( i ); - } - } - return null; } @@ -122,4 +80,6 @@ public abstract class InventoryAdaptor implements Iterable public abstract ItemStack simulateAdd( ItemStack toBeSimulated ); public abstract boolean containsItems(); + + public abstract boolean hasSlots(); } diff --git a/src/main/java/appeng/util/Lazy.java b/src/main/java/appeng/util/Lazy.java new file mode 100644 index 000000000..fe04d4a74 --- /dev/null +++ b/src/main/java/appeng/util/Lazy.java @@ -0,0 +1,44 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util; + + +import java.util.function.Supplier; + + +public class Lazy implements Supplier +{ + private final Supplier supplier; + private T instance = null; + + public Lazy( final Supplier supplier ) + { + this.supplier = supplier; + } + + @Override + public T get() + { + if( instance == null ) + { + instance = supplier.get(); + } + return instance; + } +} diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index efa38b84f..40f2f9b35 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -49,7 +49,6 @@ import net.minecraft.init.Items; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.ISidedInventory; import net.minecraft.inventory.InventoryCrafting; -import net.minecraft.inventory.InventoryLargeChest; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; @@ -68,7 +67,6 @@ import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.Vec3d; import net.minecraft.util.registry.RegistryNamespaced; import net.minecraft.util.text.translation.I18n; -import net.minecraft.world.ILockableContainer; import net.minecraft.world.World; import net.minecraft.world.WorldServer; import net.minecraft.world.chunk.Chunk; @@ -566,86 +564,6 @@ public class Platform return Math.abs( RANDOM_GENERATOR.nextInt() ); } - /* - * Utility function to get the full inventory for a Double Chest in the World. - */ - public static IInventory GetChestInv( final Object te ) - { - TileEntityChest teA = (TileEntityChest) te; - TileEntity teB = null; - final IBlockState myBlockID = teA.getWorld().getBlockState( teA.getPos() ); - - final BlockPos posX = teA.getPos().offset( EnumFacing.EAST ); - final BlockPos negX = teA.getPos().offset( EnumFacing.WEST ); - - if( teA.getWorld().getBlockState( posX ) == myBlockID ) - { - teB = teA.getWorld().getTileEntity( posX ); - if( !( teB instanceof TileEntityChest ) ) - { - teB = null; - } - } - - if( teB == null ) - { - if( teA.getWorld().getBlockState( negX ) == myBlockID ) - { - teB = teA.getWorld().getTileEntity( negX ); - if( !( teB instanceof TileEntityChest ) ) - { - teB = null; - } - else - { - final TileEntityChest x = teA; - teA = (TileEntityChest) teB; - teB = x; - } - } - } - - final BlockPos posY = teA.getPos().offset( EnumFacing.SOUTH ); - final BlockPos negY = teA.getPos().offset( EnumFacing.NORTH ); - - if( teB == null ) - { - if( teA.getWorld().getBlockState( posY ) == myBlockID ) - { - teB = teA.getWorld().getTileEntity( posY ); - if( !( teB instanceof TileEntityChest ) ) - { - teB = null; - } - } - } - - if( teB == null ) - { - if( teA.getWorld().getBlockState( negY ) == myBlockID ) - { - teB = teA.getWorld().getTileEntity( negY ); - if( !( teB instanceof TileEntityChest ) ) - { - teB = null; - } - else - { - final TileEntityChest x = teA; - teA = (TileEntityChest) teB; - teB = x; - } - } - } - - if( teB == null ) - { - return teA; - } - - return new InventoryLargeChest( "", teA, (ILockableContainer) teB ); - } - public static boolean isModLoaded( final String modid ) { try diff --git a/src/main/java/appeng/util/helpers/ItemHandlerUtil.java b/src/main/java/appeng/util/helpers/ItemHandlerUtil.java new file mode 100644 index 000000000..d53f30f7b --- /dev/null +++ b/src/main/java/appeng/util/helpers/ItemHandlerUtil.java @@ -0,0 +1,115 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.helpers; + + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.IItemHandlerModifiable; + +import appeng.util.inv.IInternalItemHandler; + + +public class ItemHandlerUtil +{ + private ItemHandlerUtil() + { + } + + public static void setStackInSlot( final IItemHandler inv, final int slot, final ItemStack stack ) + { + if( inv instanceof IItemHandlerModifiable ) + { + ( (IItemHandlerModifiable) inv ).setStackInSlot( slot, stack ); + } + else + { + inv.extractItem( slot, Integer.MAX_VALUE, false ); + inv.insertItem( slot, stack, false ); + } + } + + public static void clear( final IItemHandler inv ) + { + for( int x = 0; x < inv.getSlots(); x++ ) + { + setStackInSlot( inv, x, ItemStack.EMPTY ); + } + } + + public static boolean isEmpty( final IItemHandler inv ) + { + for( int x = 0; x < inv.getSlots(); x++ ) + { + if( !inv.getStackInSlot( x ).isEmpty() ) + { + return false; + } + } + return true; + } + + public static void markDirty( final IItemHandler inv, final int slot ) + { + if( inv instanceof IInternalItemHandler ) + { + ( (IInternalItemHandler) inv ).markDirty( slot ); + } + } + + public static boolean isItemValidForSlot( final IItemHandler inv, int slot, ItemStack stack ) + { + if( stack.isEmpty() ) + { + return false; + } + + if( inv instanceof IInternalItemHandler ) + { + return ( (IInternalItemHandler) inv ).isItemValidForSlot( slot, stack ); + } + + // empty slot + ItemStack currentStack = inv.getStackInSlot( slot ); + setStackInSlot( inv, slot, ItemStack.EMPTY ); + // test insert + ItemStack remainder = inv.insertItem( slot, stack, true ); + // restore slot + setStackInSlot( inv, slot, currentStack ); + + return remainder.isEmpty() || remainder.getCount() < stack.getCount(); + } + + public static void copy( final IItemHandler from, final IItemHandler to, boolean deepCopy ) + { + for( int i = 0; i < Math.min( from.getSlots(), to.getSlots() ); ++i ) + { + setStackInSlot( to, i, deepCopy ? from.getStackInSlot( i ).copy() : from.getStackInSlot( i ) ); + } + } + + public static void copy( final InventoryCrafting from, final IItemHandler to, boolean deepCopy ) + { + for( int i = 0; i < Math.min( from.getSizeInventory(), to.getSlots() ); ++i ) + { + setStackInSlot( to, i, deepCopy ? from.getStackInSlot( i ).copy() : from.getStackInSlot( i ) ); + } + } +} diff --git a/src/main/java/appeng/util/inv/AdaptorIInventory.java b/src/main/java/appeng/util/inv/AdaptorIInventory.java deleted file mode 100644 index eac460a70..000000000 --- a/src/main/java/appeng/util/inv/AdaptorIInventory.java +++ /dev/null @@ -1,368 +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 . - */ - -package appeng.util.inv; - - -import java.util.Iterator; - -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; - -import appeng.api.config.FuzzyMode; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; - - -public class AdaptorIInventory extends InventoryAdaptor -{ - - private final IInventory i; - private final boolean wrapperEnabled; - - public AdaptorIInventory( final IInventory s ) - { - this.i = s; - this.wrapperEnabled = s instanceof IInventoryWrapper; - } - - @Override - public ItemStack removeItems( int amount, ItemStack filter, final IInventoryDestination destination ) - { - final int s = this.i.getSizeInventory(); - ItemStack rv = ItemStack.EMPTY; - - for( int x = 0; x < s && amount > 0; x++ ) - { - final ItemStack is = this.i.getStackInSlot( x ); - if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) ) - { - int boundAmounts = amount; - if( boundAmounts > is.getCount() ) - { - boundAmounts = is.getCount(); - } - if( destination != null && !destination.canInsert( is ) ) - { - boundAmounts = 0; - } - - if( boundAmounts > 0 ) - { - if( rv.isEmpty() ) - { - rv = is.copy(); - filter = rv; - rv.setCount( boundAmounts ); - amount -= boundAmounts; - } - else - { - rv.grow( boundAmounts ); - amount -= boundAmounts; - } - - if( is.getCount() == boundAmounts ) - { - this.i.setInventorySlotContents( x, ItemStack.EMPTY ); - this.i.markDirty(); - } - else - { - final ItemStack po = is.copy(); - po.grow( -boundAmounts ); - this.i.setInventorySlotContents( x, po ); - this.i.markDirty(); - } - } - } - } - - // if ( rv != null ) - // i.markDirty(); - - return rv; - } - - @Override - public ItemStack simulateRemove( int amount, final ItemStack filter, final IInventoryDestination destination ) - { - final int s = this.i.getSizeInventory(); - ItemStack rv = ItemStack.EMPTY; - - for( int x = 0; x < s && amount > 0; x++ ) - { - final ItemStack is = this.i.getStackInSlot( x ); - if( !is.isEmpty() && this.canRemoveStackFromSlot( x, is ) && ( filter.isEmpty() || Platform.itemComparisons().isSameItem( is, filter ) ) ) - { - int boundAmount = amount; - if( boundAmount > is.getCount() ) - { - boundAmount = is.getCount(); - } - if( destination != null && !destination.canInsert( is ) ) - { - boundAmount = 0; - } - - if( boundAmount > 0 ) - { - if( rv.isEmpty() ) - { - rv = is.copy(); - rv.setCount( boundAmount ); - amount -= boundAmount; - } - else - { - rv.grow( boundAmount ); - amount -= boundAmount; - } - } - } - } - - return rv; - } - - @Override - public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination ) - { - final int s = this.i.getSizeInventory(); - for( int x = 0; x < s; x++ ) - { - final ItemStack is = this.i.getStackInSlot( x ); - if( !is.isEmpty() && this.canRemoveStackFromSlot( x, - is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) - { - int newAmount = amount; - if( newAmount > is.getCount() ) - { - newAmount = is.getCount(); - } - if( destination != null && !destination.canInsert( is ) ) - { - newAmount = 0; - } - - ItemStack rv = ItemStack.EMPTY; - if( newAmount > 0 ) - { - rv = is.copy(); - rv.setCount( newAmount ); - - if( is.getCount() == rv.getCount() ) - { - this.i.setInventorySlotContents( x, ItemStack.EMPTY ); - this.i.markDirty(); - } - else - { - final ItemStack po = is.copy(); - po.grow( -rv.getCount() ); - this.i.setInventorySlotContents( x, po ); - this.i.markDirty(); - } - } - - if( !rv.isEmpty() ) - { - // i.markDirty(); - return rv; - } - } - } - return ItemStack.EMPTY; - } - - @Override - public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination ) - { - final int s = this.i.getSizeInventory(); - for( int x = 0; x < s; x++ ) - { - final ItemStack is = this.i.getStackInSlot( x ); - - if( !is.isEmpty() && this.canRemoveStackFromSlot( x, - is ) && ( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( is, filter, fuzzyMode ) ) ) - { - int boundAmount = amount; - if( boundAmount > is.getCount() ) - { - boundAmount = is.getCount(); - } - if( destination != null && !destination.canInsert( is ) ) - { - boundAmount = 0; - } - - if( boundAmount > 0 ) - { - final ItemStack rv = is.copy(); - rv.setCount( boundAmount ); - return rv; - } - } - } - return ItemStack.EMPTY; - } - - @Override - public ItemStack addItems( final ItemStack toBeAdded ) - { - return this.addItems( toBeAdded, true ); - } - - @Override - public ItemStack simulateAdd( final ItemStack toBeSimulated ) - { - return this.addItems( toBeSimulated, false ); - } - - @Override - public boolean containsItems() - { - final int s = this.i.getSizeInventory(); - for( int x = 0; x < s; x++ ) - { - if( !this.i.getStackInSlot( x ).isEmpty() ) - { - return true; - } - } - return false; - } - - /** - * Adds an {@link ItemStack} to the adapted {@link IInventory}. - * - * It respects the inventories stack limit, which can result in not all items added and some left ones are returned. - * The ItemStack next is required for inventories, which will fail on isItemValidForSlot() for stacksizes larger - * than the limit. - * - * @param itemsToAdd itemStack to add to the inventory - * @param modulate true to modulate, false for simulate - * - * @return the left itemstack, which could not be added - */ - private ItemStack addItems( final ItemStack itemsToAdd, final boolean modulate ) - { - if( itemsToAdd.isEmpty() || itemsToAdd.getCount() == 0 ) - { - return ItemStack.EMPTY; - } - - final ItemStack left = itemsToAdd.copy(); - final int stackLimit = itemsToAdd.getMaxStackSize(); - final int perOperationLimit = Math.min( this.i.getInventoryStackLimit(), stackLimit ); - final int inventorySize = this.i.getSizeInventory(); - - for( int slot = 0; slot < inventorySize; slot++ ) - { - final ItemStack next = left.copy(); - next.setCount( Math.min( perOperationLimit, next.getCount() ) ); - - if( this.i.isItemValidForSlot( slot, next ) ) - { - final ItemStack is = this.i.getStackInSlot( slot ); - if( is.isEmpty() ) - { - left.grow( -next.getCount() ); - - if( modulate ) - { - this.i.setInventorySlotContents( slot, next ); - this.i.markDirty(); - } - - if( left.getCount() <= 0 ) - { - return ItemStack.EMPTY; - } - } - else if( Platform.itemComparisons().isSameItem( is, left ) && is.getCount() < perOperationLimit ) - { - final int room = perOperationLimit - is.getCount(); - final int used = Math.min( left.getCount(), room ); - - if( modulate ) - { - is.grow( used ); - this.i.setInventorySlotContents( slot, is ); - this.i.markDirty(); - } - - left.grow( -used ); - if( left.getCount() <= 0 ) - { - return ItemStack.EMPTY; - } - } - } - } - - return left; - } - - private boolean canRemoveStackFromSlot( final int x, final ItemStack is ) - { - if( this.wrapperEnabled ) - { - return ( (IInventoryWrapper) this.i ).canRemoveItemFromSlot( x, is ); - } - return true; - } - - @Override - public Iterator iterator() - { - return new InvIterator(); - } - - private class InvIterator implements Iterator - { - - private final ItemSlot is = new ItemSlot(); - private int x = 0; - - @Override - public boolean hasNext() - { - return this.x < AdaptorIInventory.this.i.getSizeInventory(); - } - - @Override - public ItemSlot next() - { - final ItemStack iss = AdaptorIInventory.this.i.getStackInSlot( this.x ); - - this.is.setExtractable( AdaptorIInventory.this.canRemoveStackFromSlot( this.x, iss ) ); - this.is.setItemStack( iss ); - - this.is.setSlot( this.x ); - this.x++; - return this.is; - } - - @Override - public void remove() - { - // nothing! - } - } -} diff --git a/src/main/java/appeng/util/inv/AdaptorItemHandler.java b/src/main/java/appeng/util/inv/AdaptorItemHandler.java index afd7bb31c..78b03055f 100644 --- a/src/main/java/appeng/util/inv/AdaptorItemHandler.java +++ b/src/main/java/appeng/util/inv/AdaptorItemHandler.java @@ -38,6 +38,12 @@ public class AdaptorItemHandler extends InventoryAdaptor this.itemHandler = itemHandler; } + @Override + public boolean hasSlots() + { + return itemHandler.getSlots() > 0; + } + @Override public ItemStack removeItems( int amount, ItemStack filter, IInventoryDestination destination ) { diff --git a/src/main/java/appeng/util/inv/AdaptorList.java b/src/main/java/appeng/util/inv/AdaptorList.java index eb2589409..e13f00a94 100644 --- a/src/main/java/appeng/util/inv/AdaptorList.java +++ b/src/main/java/appeng/util/inv/AdaptorList.java @@ -40,6 +40,12 @@ public class AdaptorList extends InventoryAdaptor this.i = s; } + @Override + public boolean hasSlots() + { + return !i.isEmpty(); + } + @Override public ItemStack removeItems( int amount, final ItemStack filter, final IInventoryDestination destination ) { diff --git a/src/main/java/appeng/util/inv/AdaptorPlayerHand.java b/src/main/java/appeng/util/inv/AdaptorPlayerHand.java deleted file mode 100644 index ad73113e7..000000000 --- a/src/main/java/appeng/util/inv/AdaptorPlayerHand.java +++ /dev/null @@ -1,237 +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 . - */ - -package appeng.util.inv; - - -import java.util.Iterator; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.item.ItemStack; - -import appeng.api.config.FuzzyMode; -import appeng.util.InventoryAdaptor; -import appeng.util.Platform; -import appeng.util.iterators.NullIterator; - - -/* - * Lets you do simply tests with the players cursor, without messing with the specifics. - */ -public class AdaptorPlayerHand extends InventoryAdaptor -{ - - private final EntityPlayer player; - - public AdaptorPlayerHand( final EntityPlayer player ) - { - this.player = player; - } - - @Override - public ItemStack removeItems( final int amount, final ItemStack filter, final IInventoryDestination destination ) - { - final ItemStack hand = this.player.inventory.getItemStack(); - if( hand.isEmpty() ) - { - return ItemStack.EMPTY; - } - - if( filter.isEmpty() || Platform.itemComparisons().isSameItem( filter, hand ) ) - { - final ItemStack result = hand.copy(); - result.setCount( hand.getCount() > amount ? amount : hand.getCount() ); - hand.grow( -amount ); - if( hand.getCount() <= 0 ) - { - this.player.inventory.setItemStack( ItemStack.EMPTY ); - } - return result; - } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack simulateRemove( final int amount, final ItemStack filter, final IInventoryDestination destination ) - { - - final ItemStack hand = this.player.inventory.getItemStack(); - if( hand.isEmpty() ) - { - return ItemStack.EMPTY; - } - - if( filter == null || Platform.itemComparisons().isSameItem( filter, hand ) ) - { - final ItemStack result = hand.copy(); - result.setCount( hand.getCount() > amount ? amount : hand.getCount() ); - return result; - } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack removeSimilarItems( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination ) - { - final ItemStack hand = this.player.inventory.getItemStack(); - if( hand.isEmpty() ) - { - return ItemStack.EMPTY; - } - - if( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) ) - { - final ItemStack result = hand.copy(); - result.setCount( hand.getCount() > amount ? amount : hand.getCount() ); - hand.grow( -amount ); - if( hand.getCount() <= 0 ) - { - this.player.inventory.setItemStack( ItemStack.EMPTY ); - } - return result; - } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack simulateSimilarRemove( final int amount, final ItemStack filter, final FuzzyMode fuzzyMode, final IInventoryDestination destination ) - { - - final ItemStack hand = this.player.inventory.getItemStack(); - if( hand.isEmpty() ) - { - return ItemStack.EMPTY; - } - - if( filter.isEmpty() || Platform.itemComparisons().isFuzzyEqualItem( filter, hand, fuzzyMode ) ) - { - final ItemStack result = hand.copy(); - result.setCount( hand.getCount() > amount ? amount : hand.getCount() ); - return result; - } - - return ItemStack.EMPTY; - } - - @Override - public ItemStack addItems( final ItemStack toBeAdded ) - { - - if( toBeAdded.isEmpty() ) - { - return ItemStack.EMPTY; - } - if( toBeAdded.getCount() == 0 ) - { - return ItemStack.EMPTY; - } - if( this.player == null ) - { - return toBeAdded; - } - if( this.player.inventory == null ) - { - return toBeAdded; - } - - final ItemStack hand = this.player.inventory.getItemStack(); - - if( !hand.isEmpty() && !Platform.itemComparisons().isSameItem( toBeAdded, hand ) ) - { - return toBeAdded; - } - - int original = 0; - ItemStack newHand = ItemStack.EMPTY; - if( hand.isEmpty() ) - { - newHand = toBeAdded.copy(); - } - else - { - newHand = hand; - original = hand.getCount(); - newHand.grow( toBeAdded.getCount() ); - } - - if( newHand.getCount() > newHand.getMaxStackSize() ) - { - newHand.setCount( newHand.getMaxStackSize() ); - final ItemStack B = toBeAdded.copy(); - B.grow( -( newHand.getCount() - original ) ); - this.player.inventory.setItemStack( newHand ); - return B; - } - - this.player.inventory.setItemStack( newHand ); - return ItemStack.EMPTY; - } - - @Override - public ItemStack simulateAdd( final ItemStack toBeSimulated ) - { - final ItemStack hand = this.player.inventory.getItemStack(); - if( toBeSimulated.isEmpty() ) - { - return ItemStack.EMPTY; - } - - if( !hand.isEmpty() && !Platform.itemComparisons().isEqualItem( toBeSimulated, hand ) ) - { - return toBeSimulated; - } - - int original = 0; - ItemStack newHand = ItemStack.EMPTY; - if( hand.isEmpty() ) - { - newHand = toBeSimulated.copy(); - } - else - { - newHand = hand.copy(); - original = hand.getCount(); - newHand.grow( toBeSimulated.getCount() ); - } - - if( newHand.getCount() > newHand.getMaxStackSize() ) - { - newHand.setCount( newHand.getMaxStackSize() ); - final ItemStack B = toBeSimulated.copy(); - B.grow( -( newHand.getCount() - original ) ); - return B; - } - - return ItemStack.EMPTY; - } - - @Override - public boolean containsItems() - { - return !this.player.inventory.getItemStack().isEmpty(); - } - - @Override - public Iterator iterator() - { - return new NullIterator<>(); - } -} diff --git a/src/main/java/appeng/util/inv/AdaptorPlayerInventory.java b/src/main/java/appeng/util/inv/AdaptorPlayerInventory.java deleted file mode 100644 index bd15f7263..000000000 --- a/src/main/java/appeng/util/inv/AdaptorPlayerInventory.java +++ /dev/null @@ -1,162 +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 . - */ - -package appeng.util.inv; - - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; - - -public class AdaptorPlayerInventory implements IInventory -{ - - private final IInventory src; - private final int min = 0; - private final int size = 36; - - public AdaptorPlayerInventory( final IInventory playerInv, final boolean swap ) - { - - if( swap ) - { - this.src = new WrapperChainedInventory( new WrapperInventoryRange( playerInv, 9, this.size - 9, false ), new WrapperInventoryRange( playerInv, 0, 9, false ) ); - } - else - { - this.src = playerInv; - } - } - - @Override - public int getSizeInventory() - { - return this.size; - } - - @Override - public ItemStack getStackInSlot( final int var1 ) - { - return this.src.getStackInSlot( var1 + this.min ); - } - - @Override - public ItemStack decrStackSize( final int var1, final int var2 ) - { - return this.src.decrStackSize( this.min + var1, var2 ); - } - - @Override - public ItemStack removeStackFromSlot( final int var1 ) - { - return this.src.removeStackFromSlot( this.min + var1 ); - } - - @Override - public void setInventorySlotContents( final int var1, final ItemStack var2 ) - { - this.src.setInventorySlotContents( var1 + this.min, var2 ); - } - - @Override - public ITextComponent getDisplayName() - { - return this.src.getDisplayName(); - } - - @Override - public boolean hasCustomName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - return this.src.getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - this.src.markDirty(); - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer var1 ) - { - return this.src.isUsableByPlayer( var1 ); - } - - @Override - public void openInventory( final EntityPlayer player ) - { - this.src.openInventory( player ); - - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - this.src.closeInventory( player ); - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - return this.src.isItemValidForSlot( i, itemstack ); - } - - @Override - public String getName() - { - return this.src.getName(); - } - - @Override - public int getField( final int id ) - { - return this.src.getField( id ); - } - - @Override - public void setField( final int id, final int value ) - { - this.src.setField( id, value ); - } - - @Override - public int getFieldCount() - { - return this.src.getFieldCount(); - } - - @Override - public void clear() - { - this.src.clear(); - } - - @Override - public boolean isEmpty() - { - return this.src.isEmpty(); - } -} diff --git a/src/main/java/appeng/tile/inventory/IAEAppEngInventory.java b/src/main/java/appeng/util/inv/IAEAppEngInventory.java similarity index 83% rename from src/main/java/appeng/tile/inventory/IAEAppEngInventory.java rename to src/main/java/appeng/util/inv/IAEAppEngInventory.java index 2ca28a386..a811a980e 100644 --- a/src/main/java/appeng/tile/inventory/IAEAppEngInventory.java +++ b/src/main/java/appeng/util/inv/IAEAppEngInventory.java @@ -16,17 +16,16 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.tile.inventory; +package appeng.util.inv; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public interface IAEAppEngInventory { - void saveChanges(); - void onChangeInventory( IInventory inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack ); + void onChangeInventory( IItemHandler inv, int slot, InvOperation mc, ItemStack removedStack, ItemStack newStack ); } diff --git a/src/main/java/appeng/util/inv/IInventoryWrapper.java b/src/main/java/appeng/util/inv/IInternalItemHandler.java similarity index 74% rename from src/main/java/appeng/util/inv/IInventoryWrapper.java rename to src/main/java/appeng/util/inv/IInternalItemHandler.java index eedab2a70..5951f6eb4 100644 --- a/src/main/java/appeng/util/inv/IInventoryWrapper.java +++ b/src/main/java/appeng/util/inv/IInternalItemHandler.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2017, 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 @@ -20,10 +20,12 @@ package appeng.util.inv; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandlerModifiable; -public interface IInventoryWrapper +public interface IInternalItemHandler extends IItemHandlerModifiable { + boolean isItemValidForSlot( int slot, ItemStack stack ); - boolean canRemoveItemFromSlot( int x, ItemStack is ); + void markDirty( int slot ); } diff --git a/src/main/java/appeng/util/inv/IMEAdaptor.java b/src/main/java/appeng/util/inv/IMEAdaptor.java index 87423970c..30c28d6a5 100644 --- a/src/main/java/appeng/util/inv/IMEAdaptor.java +++ b/src/main/java/appeng/util/inv/IMEAdaptor.java @@ -49,6 +49,12 @@ public class IMEAdaptor extends InventoryAdaptor this.src = src; } + @Override + public boolean hasSlots() + { + return true; + } + @Override public Iterator iterator() { diff --git a/src/main/java/appeng/tile/inventory/InvOperation.java b/src/main/java/appeng/util/inv/InvOperation.java similarity index 90% rename from src/main/java/appeng/tile/inventory/InvOperation.java rename to src/main/java/appeng/util/inv/InvOperation.java index aaa9a0165..72d4dfb13 100644 --- a/src/main/java/appeng/tile/inventory/InvOperation.java +++ b/src/main/java/appeng/util/inv/InvOperation.java @@ -16,11 +16,10 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.tile.inventory; +package appeng.util.inv; public enum InvOperation { - decreaseStackSize, setInventorySlotContents, markDirty - + EXTRACT, INSERT, SET, DIRTY } diff --git a/src/main/java/appeng/util/inv/WrapperChainedInventory.java b/src/main/java/appeng/util/inv/WrapperChainedInventory.java deleted file mode 100644 index c7522ee44..000000000 --- a/src/main/java/appeng/util/inv/WrapperChainedInventory.java +++ /dev/null @@ -1,275 +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 . - */ - -package appeng.util.inv; - - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.google.common.collect.ImmutableList; - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; - - -public class WrapperChainedInventory implements IInventory -{ - - private int fullSize = 0; - private List l; - private Map offsets; - - public WrapperChainedInventory( final IInventory... inventories ) - { - this.setInventory( inventories ); - } - - private void setInventory( final IInventory... a ) - { - this.l = ImmutableList.copyOf( a ); - this.calculateSizes(); - } - - private void calculateSizes() - { - this.offsets = new HashMap<>(); - - int offset = 0; - for( final IInventory in : this.l ) - { - final InvOffset io = new InvOffset(); - io.offset = offset; - io.size = in.getSizeInventory(); - io.i = in; - - for( int y = 0; y < io.size; y++ ) - { - this.offsets.put( y + io.offset, io ); - } - - offset += io.size; - } - - this.fullSize = offset; - } - - public WrapperChainedInventory( final List inventories ) - { - this.setInventory( inventories ); - } - - private void setInventory( final List a ) - { - this.l = a; - this.calculateSizes(); - } - - public void cycleOrder() - { - if( this.l.size() > 1 ) - { - final List newOrder = new ArrayList<>( this.l.size() ); - newOrder.add( this.l.get( this.l.size() - 1 ) ); - for( int x = 0; x < this.l.size() - 1; x++ ) - { - newOrder.add( this.l.get( x ) ); - } - this.setInventory( newOrder ); - } - } - - public IInventory getInv( final int idx ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return io.i; - } - return null; - } - - public int getInvSlot( final int idx ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return idx - io.offset; - } - return 0; - } - - @Override - public int getSizeInventory() - { - return this.fullSize; - } - - @Override - public ItemStack getStackInSlot( final int idx ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return io.i.getStackInSlot( idx - io.offset ); - } - return ItemStack.EMPTY; - } - - @Override - public ItemStack decrStackSize( final int idx, final int var2 ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return io.i.decrStackSize( idx - io.offset, var2 ); - } - return ItemStack.EMPTY; - } - - @Override - public ItemStack removeStackFromSlot( final int idx ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return io.i.removeStackFromSlot( idx - io.offset ); - } - return ItemStack.EMPTY; - } - - @Override - public void setInventorySlotContents( final int idx, final ItemStack var2 ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - io.i.setInventorySlotContents( idx - io.offset, var2 ); - } - } - - @Override - public String getName() - { - return "ChainedInv"; - } - - @Override - public boolean hasCustomName() - { - return false; - } - - @Override - public int getInventoryStackLimit() - { - int smallest = 64; - - for( final IInventory i : this.l ) - { - smallest = Math.min( smallest, i.getInventoryStackLimit() ); - } - - return smallest; - } - - @Override - public void markDirty() - { - for( final IInventory i : this.l ) - { - i.markDirty(); - } - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer var1 ) - { - return false; - } - - @Override - public void openInventory( final EntityPlayer player ) - { - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - } - - @Override - public boolean isItemValidForSlot( final int idx, final ItemStack itemstack ) - { - final InvOffset io = this.offsets.get( idx ); - if( io != null ) - { - return io.i.isItemValidForSlot( idx - io.offset, itemstack ); - } - return false; - } - - private static class InvOffset - { - - private int offset; - private int size; - private IInventory i; - } - - @Override - public ITextComponent getDisplayName() - { - return null; - } - - @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() - { - // TODO Auto-generated method stub - return false; - } -} diff --git a/src/main/java/appeng/util/inv/WrapperChainedItemHandler.java b/src/main/java/appeng/util/inv/WrapperChainedItemHandler.java new file mode 100644 index 000000000..89ba6c747 --- /dev/null +++ b/src/main/java/appeng/util/inv/WrapperChainedItemHandler.java @@ -0,0 +1,178 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv; + + +import java.util.ArrayList; + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.EmptyHandler; + +import appeng.util.helpers.ItemHandlerUtil; + + +public class WrapperChainedItemHandler implements IInternalItemHandler +{ + private IItemHandler[] itemHandler; // the handlers + private int[] baseIndex; // index-offsets of the different handlers + private int slotCount; // number of total slots + + public WrapperChainedItemHandler( IItemHandler... itemHandler ) + { + setItemHandlers( itemHandler ); + } + + private void setItemHandlers( IItemHandler[] handlers ) + { + this.itemHandler = handlers; + this.baseIndex = new int[itemHandler.length]; + int index = 0; + for( int i = 0; i < itemHandler.length; i++ ) + { + index += itemHandler[i].getSlots(); + baseIndex[i] = index; + } + this.slotCount = index; + } + + // returns the handler index for the slot + private int getIndexForSlot( int slot ) + { + if( slot < 0 ) + { + return -1; + } + + for( int i = 0; i < baseIndex.length; i++ ) + { + if( slot - baseIndex[i] < 0 ) + { + return i; + } + } + return -1; + } + + private IItemHandler getHandlerFromIndex( int index ) + { + if( index < 0 || index >= itemHandler.length ) + { + return EmptyHandler.INSTANCE; + } + return itemHandler[index]; + } + + private int getSlotFromIndex( int slot, int index ) + { + if( index <= 0 || index >= baseIndex.length ) + { + return slot; + } + return slot - baseIndex[index - 1]; + } + + public void cycleOrder() + { + if( this.itemHandler.length > 1 ) + { + ArrayList newOrder = new ArrayList<>(); + newOrder.add( this.itemHandler[this.itemHandler.length - 1] ); + for( int i = 0; i < this.itemHandler.length - 1; ++i ) + { + newOrder.add( this.itemHandler[i] ); + } + this.setItemHandlers( newOrder.toArray( new IItemHandler[this.itemHandler.length] ) ); + } + } + + @Override + public int getSlots() + { + return slotCount; + } + + @Override + @Nonnull + public ItemStack getStackInSlot( final int slot ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + return handler.getStackInSlot( targetSlot ); + } + + @Override + @Nonnull + public ItemStack insertItem( final int slot, @Nonnull ItemStack stack, boolean simulate ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + return handler.insertItem( targetSlot, stack, simulate ); + } + + @Override + @Nonnull + public ItemStack extractItem( int slot, int amount, boolean simulate ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + return handler.extractItem( targetSlot, amount, simulate ); + } + + @Override + public int getSlotLimit( int slot ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int localSlot = getSlotFromIndex( slot, index ); + return handler.getSlotLimit( localSlot ); + } + + @Override + public void setStackInSlot( int slot, ItemStack stack ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + ItemHandlerUtil.setStackInSlot( handler, targetSlot, stack ); + } + + @Override + public boolean isItemValidForSlot( int slot, ItemStack stack ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + return ItemHandlerUtil.isItemValidForSlot( handler, targetSlot, stack ); + } + + @Override + public void markDirty( int slot ) + { + int index = getIndexForSlot( slot ); + IItemHandler handler = getHandlerFromIndex( index ); + int targetSlot = getSlotFromIndex( slot, index ); + ItemHandlerUtil.markDirty( handler, targetSlot ); + } +} diff --git a/src/main/java/appeng/util/inv/WrapperCursorItemHandler.java b/src/main/java/appeng/util/inv/WrapperCursorItemHandler.java new file mode 100644 index 000000000..f7b414e9e --- /dev/null +++ b/src/main/java/appeng/util/inv/WrapperCursorItemHandler.java @@ -0,0 +1,43 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv; + + +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraftforge.items.ItemStackHandler; + + +public class WrapperCursorItemHandler extends ItemStackHandler +{ + private final InventoryPlayer inv; + + public WrapperCursorItemHandler( InventoryPlayer inventoryPlayer ) + { + super( 1 ); + + this.inv = inventoryPlayer; + setStackInSlot( 0, inventoryPlayer.getItemStack() ); + } + + @Override + protected void onContentsChanged( int slot ) + { + this.inv.setItemStack( getStackInSlot( slot ) ); + } +} diff --git a/src/main/java/appeng/util/inv/WrapperFilteredItemHandler.java b/src/main/java/appeng/util/inv/WrapperFilteredItemHandler.java new file mode 100644 index 000000000..b380a666a --- /dev/null +++ b/src/main/java/appeng/util/inv/WrapperFilteredItemHandler.java @@ -0,0 +1,103 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv; + + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import appeng.util.helpers.ItemHandlerUtil; +import appeng.util.inv.filter.IAEItemFilter; + + +public class WrapperFilteredItemHandler implements IInternalItemHandler +{ + private final IItemHandler handler; + private final IAEItemFilter filter; + + public WrapperFilteredItemHandler( @Nonnull IItemHandler handler, @Nonnull IAEItemFilter filter ) + { + this.handler = handler; + this.filter = filter; + } + + @Override + public void setStackInSlot( int slot, ItemStack stack ) + { + ItemHandlerUtil.setStackInSlot( handler, slot, stack ); + } + + @Override + public int getSlots() + { + return handler.getSlots(); + } + + @Override + public ItemStack getStackInSlot( int slot ) + { + return handler.getStackInSlot( slot ); + } + + @Override + public ItemStack insertItem( int slot, ItemStack stack, boolean simulate ) + { + if( !filter.allowInsert( handler, slot, stack ) ) + { + return stack; + } + + return handler.insertItem( slot, stack, simulate ); + } + + @Override + public ItemStack extractItem( int slot, int amount, boolean simulate ) + { + if( !filter.allowExtract( handler, slot, amount ) ) + { + return ItemStack.EMPTY; + } + + return handler.extractItem( slot, amount, simulate ); + } + + @Override + public int getSlotLimit( int slot ) + { + return handler.getSlotLimit( slot ); + } + + @Override + public boolean isItemValidForSlot( int slot, ItemStack stack ) + { + if( !filter.allowInsert( handler, slot, stack ) ) + { + return false; + } + return ItemHandlerUtil.isItemValidForSlot( handler, slot, stack ); + } + + @Override + public void markDirty( int slot ) + { + ItemHandlerUtil.markDirty( handler, slot ); + } +} diff --git a/src/main/java/appeng/tile/inventory/AppEngNullInventory.java b/src/main/java/appeng/util/inv/WrapperInvItemHandler.java similarity index 52% rename from src/main/java/appeng/tile/inventory/AppEngNullInventory.java rename to src/main/java/appeng/util/inv/WrapperInvItemHandler.java index cc5f49e81..f71469302 100644 --- a/src/main/java/appeng/tile/inventory/AppEngNullInventory.java +++ b/src/main/java/appeng/util/inv/WrapperInvItemHandler.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2017, 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 @@ -16,61 +16,31 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.tile.inventory; +package appeng.util.inv; 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; +import net.minecraftforge.items.IItemHandler; + +import appeng.util.helpers.ItemHandlerUtil; -public class AppEngNullInventory implements IInventory +public class WrapperInvItemHandler implements IInventory { + private final IItemHandler inv; - public AppEngNullInventory() + public WrapperInvItemHandler( final IItemHandler inv ) { - } - - 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 ) - { - + this.inv = inv; } @Override public String getName() { - return "appeng-internal"; + return null; } @Override @@ -79,30 +49,6 @@ public class AppEngNullInventory implements IInventory 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() { @@ -110,27 +56,92 @@ public class AppEngNullInventory implements IInventory } @Override - public void openInventory( final EntityPlayer player ) + public int getSizeInventory() { - + return inv.getSlots(); } @Override - public void closeInventory( final EntityPlayer player ) + public boolean isEmpty() { - + return ItemHandlerUtil.isEmpty( inv ); } @Override - public int getField( final int id ) + public ItemStack getStackInSlot( int index ) + { + return inv.getStackInSlot( index ); + } + + @Override + public ItemStack decrStackSize( int index, int count ) + { + return inv.extractItem( index, count, false ); + } + + @Override + public ItemStack removeStackFromSlot( int index ) + { + return inv.extractItem( index, inv.getSlotLimit( index ), false ); + } + + @Override + public void setInventorySlotContents( int index, ItemStack stack ) + { + ItemHandlerUtil.setStackInSlot( inv, index, stack ); + } + + @Override + public int getInventoryStackLimit() + { + int max = 0; + for( int i = 0; i < inv.getSlots(); ++i ) + { + max = Math.max( max, inv.getSlotLimit( i ) ); + } + return max; + } + + @Override + public void markDirty() + { + ItemHandlerUtil.markDirty( inv, -1 ); + } + + @Override + public boolean isUsableByPlayer( EntityPlayer player ) + { + return false; + } + + @Override + public void openInventory( EntityPlayer player ) + { + // NOP + } + + @Override + public void closeInventory( EntityPlayer player ) + { + // NOP + } + + @Override + public boolean isItemValidForSlot( int index, ItemStack stack ) + { + return ItemHandlerUtil.isItemValidForSlot( inv, index, stack ); + } + + @Override + public int getField( int id ) { return 0; } @Override - public void setField( final int id, final int value ) + public void setField( int id, int value ) { - + // NOP } @Override @@ -142,12 +153,7 @@ public class AppEngNullInventory implements IInventory @Override public void clear() { - + ItemHandlerUtil.clear( inv ); } - @Override - public boolean isEmpty() - { - return true; - } } diff --git a/src/main/java/appeng/util/inv/WrapperInvSlot.java b/src/main/java/appeng/util/inv/WrapperInvSlot.java deleted file mode 100644 index 7e0910847..000000000 --- a/src/main/java/appeng/util/inv/WrapperInvSlot.java +++ /dev/null @@ -1,175 +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 . - */ - -package appeng.util.inv; - - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; - - -public class WrapperInvSlot -{ - - private final IInventory inv; - - public WrapperInvSlot( final IInventory inv ) - { - this.inv = inv; - } - - public IInventory getWrapper( final int slot ) - { - return new InternalInterfaceWrapper( this.inv, slot ); - } - - protected boolean isItemValid( final ItemStack itemstack ) - { - return true; - } - - private class InternalInterfaceWrapper implements IInventory - { - - private final IInventory inv; - private final int slot; - - public InternalInterfaceWrapper( final IInventory target, final int slot ) - { - this.inv = target; - this.slot = slot; - } - - @Override - public int getSizeInventory() - { - return 1; - } - - @Override - public ItemStack getStackInSlot( final int i ) - { - return this.inv.getStackInSlot( this.slot ); - } - - @Override - public ItemStack decrStackSize( final int i, final int num ) - { - return this.inv.decrStackSize( this.slot, num ); - } - - @Override - public ItemStack removeStackFromSlot( final int i ) - { - return this.inv.removeStackFromSlot( this.slot ); - } - - @Override - public void setInventorySlotContents( final int i, final ItemStack itemstack ) - { - this.inv.setInventorySlotContents( this.slot, itemstack ); - } - - @Override - public int getInventoryStackLimit() - { - return this.inv.getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - this.inv.markDirty(); - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer entityplayer ) - { - return this.inv.isUsableByPlayer( entityplayer ); - } - - @Override - public String getName() - { - return this.inv.getName(); - } - - @Override - public boolean hasCustomName() - { - return this.inv.hasCustomName(); - } - - @Override - public void openInventory( final EntityPlayer player ) - { - this.inv.openInventory( player ); - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - this.inv.closeInventory( player ); - } - - @Override - public void clear() - { - this.inv.clear(); - } - - @Override - public int getField( final int id ) - { - return this.inv.getField( id ); - } - - @Override - public int getFieldCount() - { - return this.inv.getFieldCount(); - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - return WrapperInvSlot.this.isItemValid( itemstack ) && this.inv.isItemValidForSlot( this.slot, itemstack ); - } - - @Override - public ITextComponent getDisplayName() - { - return this.inv.getDisplayName(); - } - - @Override - public void setField( final int id, final int value ) - { - this.inv.setField( id, value ); - } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } - } -} diff --git a/src/main/java/appeng/util/inv/WrapperInventoryRange.java b/src/main/java/appeng/util/inv/WrapperInventoryRange.java deleted file mode 100644 index 71a5050ed..000000000 --- a/src/main/java/appeng/util/inv/WrapperInventoryRange.java +++ /dev/null @@ -1,216 +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 . - */ - -package appeng.util.inv; - - -import net.minecraft.entity.player.EntityPlayer; -import net.minecraft.inventory.IInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.text.ITextComponent; - - -public class WrapperInventoryRange implements IInventory -{ - - private final IInventory src; - private boolean ignoreValidItems = false; - private int[] slots; - - public WrapperInventoryRange( final IInventory a, final int[] s, final boolean ignoreValid ) - { - this.src = a; - this.setSlots( s ); - - if( this.getSlots() == null ) - { - this.setSlots( new int[0] ); - } - - this.setIgnoreValidItems( ignoreValid ); - } - - public WrapperInventoryRange( final IInventory a, final int min, final int size, final boolean ignoreValid ) - { - this.src = a; - this.setSlots( new int[size] ); - for( int x = 0; x < size; x++ ) - { - this.getSlots()[x] = min + x; - } - this.setIgnoreValidItems( ignoreValid ); - } - - public static String concatLines( final int[] s, final String separator ) - { - if( s.length > 0 ) - { - final StringBuilder sb = new StringBuilder(); - for( final int value : s ) - { - if( sb.length() > 0 ) - { - sb.append( separator ); - } - sb.append( value ); - } - return sb.toString(); - } - return ""; - } - - @Override - public int getSizeInventory() - { - return this.getSlots().length; - } - - @Override - public ItemStack getStackInSlot( final int var1 ) - { - return this.src.getStackInSlot( this.getSlots()[var1] ); - } - - @Override - public ItemStack decrStackSize( final int var1, final int var2 ) - { - return this.src.decrStackSize( this.getSlots()[var1], var2 ); - } - - @Override - public ItemStack removeStackFromSlot( final int var1 ) - { - return this.src.removeStackFromSlot( this.getSlots()[var1] ); - } - - @Override - public void setInventorySlotContents( final int var1, final ItemStack var2 ) - { - this.src.setInventorySlotContents( this.getSlots()[var1], var2 ); - } - - @Override - public int getInventoryStackLimit() - { - return this.src.getInventoryStackLimit(); - } - - @Override - public void markDirty() - { - this.src.markDirty(); - } - - @Override - public boolean isUsableByPlayer( final EntityPlayer var1 ) - { - return this.src.isUsableByPlayer( var1 ); - } - - @Override - public String getName() - { - return this.src.getName(); - } - - @Override - public boolean hasCustomName() - { - return this.src.hasCustomName(); - } - - @Override - public void openInventory( final EntityPlayer player ) - { - this.src.openInventory( player ); - } - - @Override - public void closeInventory( final EntityPlayer player ) - { - this.src.closeInventory( player ); - } - - @Override - public void clear() - { - this.src.clear(); - } - - @Override - public int getField( final int id ) - { - return this.src.getField( id ); - } - - @Override - public int getFieldCount() - { - return this.src.getFieldCount(); - } - - @Override - public ITextComponent getDisplayName() - { - return this.src.getDisplayName(); - } - - @Override - public void setField( final int id, final int value ) - { - this.src.setField( id, value ); - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - if( this.isIgnoreValidItems() ) - { - return true; - } - - return this.src.isItemValidForSlot( this.getSlots()[i], itemstack ); - } - - boolean isIgnoreValidItems() - { - return this.ignoreValidItems; - } - - private void setIgnoreValidItems( final boolean ignoreValidItems ) - { - this.ignoreValidItems = ignoreValidItems; - } - - int[] getSlots() - { - return this.slots; - } - - private void setSlots( final int[] slots ) - { - this.slots = slots; - } - - @Override - public boolean isEmpty() - { - // TODO Auto-generated method stub - return false; - } -} diff --git a/src/main/java/appeng/util/inv/WrapperLazyItemHandler.java b/src/main/java/appeng/util/inv/WrapperLazyItemHandler.java new file mode 100644 index 000000000..235de1032 --- /dev/null +++ b/src/main/java/appeng/util/inv/WrapperLazyItemHandler.java @@ -0,0 +1,87 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv; + + +import java.util.function.Supplier; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import appeng.util.Lazy; +import appeng.util.helpers.ItemHandlerUtil; + + +public class WrapperLazyItemHandler implements IInternalItemHandler +{ + private final Lazy sourceHandler; + + public WrapperLazyItemHandler( Supplier source ) + { + this.sourceHandler = new Lazy<>( source ); + } + + @Override + public int getSlots() + { + return sourceHandler.get().getSlots(); + } + + @Override + public ItemStack getStackInSlot( int slot ) + { + return sourceHandler.get().getStackInSlot( slot ); + } + + @Override + public ItemStack insertItem( int slot, ItemStack stack, boolean simulate ) + { + return sourceHandler.get().insertItem( slot, stack, simulate ); + } + + @Override + public ItemStack extractItem( int slot, int amount, boolean simulate ) + { + return sourceHandler.get().extractItem( slot, amount, simulate ); + } + + @Override + public int getSlotLimit( int slot ) + { + return sourceHandler.get().getSlotLimit( slot ); + } + + @Override + public void setStackInSlot( int slot, ItemStack stack ) + { + ItemHandlerUtil.setStackInSlot( sourceHandler.get(), slot, stack ); + } + + @Override + public boolean isItemValidForSlot( int slot, ItemStack stack ) + { + return ItemHandlerUtil.isItemValidForSlot( sourceHandler.get(), slot, stack ); + } + + @Override + public void markDirty( int slot ) + { + ItemHandlerUtil.markDirty( sourceHandler.get(), slot ); + } +} diff --git a/src/main/java/appeng/util/inv/WrapperMCISidedInventory.java b/src/main/java/appeng/util/inv/WrapperMCISidedInventory.java deleted file mode 100644 index e635fbf91..000000000 --- a/src/main/java/appeng/util/inv/WrapperMCISidedInventory.java +++ /dev/null @@ -1,77 +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 . - */ - -package appeng.util.inv; - - -import net.minecraft.inventory.ISidedInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.util.EnumFacing; - - -public class WrapperMCISidedInventory extends WrapperInventoryRange implements IInventoryWrapper -{ - - private final ISidedInventory side; - private final EnumFacing dir; - - public WrapperMCISidedInventory( final ISidedInventory a, final EnumFacing d ) - { - super( a, a.getSlotsForFace( d ), false ); - this.side = a; - this.dir = d; - } - - @Override - public ItemStack decrStackSize( final int var1, final int var2 ) - { - if( this.canRemoveItemFromSlot( var1, this.getStackInSlot( var1 ) ) ) - { - return super.decrStackSize( var1, var2 ); - } - return null; - } - - @Override - public boolean isItemValidForSlot( final int i, final ItemStack itemstack ) - { - - if( this.isIgnoreValidItems() ) - { - return true; - } - - if( this.side.isItemValidForSlot( this.getSlots()[i], itemstack ) ) - { - return this.side.canInsertItem( this.getSlots()[i], itemstack, this.dir ); - } - - return false; - } - - @Override - public boolean canRemoveItemFromSlot( final int i, final ItemStack is ) - { - if( is.isEmpty() ) - { - return false; - } - - return this.side.canExtractItem( this.getSlots()[i], is, this.dir ); - } -} diff --git a/src/main/java/appeng/util/inv/WrapperRangeItemHandler.java b/src/main/java/appeng/util/inv/WrapperRangeItemHandler.java new file mode 100644 index 000000000..ca325a1aa --- /dev/null +++ b/src/main/java/appeng/util/inv/WrapperRangeItemHandler.java @@ -0,0 +1,129 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv; + + +import javax.annotation.Nonnull; + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import appeng.util.helpers.ItemHandlerUtil; + + +public class WrapperRangeItemHandler implements IInternalItemHandler +{ + private final IItemHandler compose; + private final int minSlot; + private final int maxSlot; + + public WrapperRangeItemHandler( IItemHandler compose, int minSlot, int maxSlotExclusive ) + { + this.compose = compose; + this.minSlot = minSlot; + this.maxSlot = maxSlotExclusive; + } + + @Override + public int getSlots() + { + return maxSlot - minSlot; + } + + @Override + @Nonnull + public ItemStack getStackInSlot( int slot ) + { + if( checkSlot( slot ) ) + { + return compose.getStackInSlot( slot + minSlot ); + } + + return ItemStack.EMPTY; + } + + @Override + @Nonnull + public ItemStack insertItem( int slot, @Nonnull ItemStack stack, boolean simulate ) + { + if( checkSlot( slot ) ) + { + return compose.insertItem( slot + minSlot, stack, simulate ); + } + + return stack; + } + + @Override + @Nonnull + public ItemStack extractItem( int slot, int amount, boolean simulate ) + { + if( checkSlot( slot ) ) + { + return compose.extractItem( slot + minSlot, amount, simulate ); + } + + return ItemStack.EMPTY; + } + + @Override + public void setStackInSlot( int slot, @Nonnull ItemStack stack ) + { + if( checkSlot( slot ) ) + { + ItemHandlerUtil.setStackInSlot( compose, slot + minSlot, stack ); + } + } + + @Override + public int getSlotLimit( int slot ) + { + if( checkSlot( slot ) ) + { + return compose.getSlotLimit( slot + minSlot ); + } + + return 0; + } + + private boolean checkSlot( int localSlot ) + { + return localSlot + minSlot < maxSlot; + } + + @Override + public boolean isItemValidForSlot( int slot, ItemStack stack ) + { + if( checkSlot( slot ) ) + { + return ItemHandlerUtil.isItemValidForSlot( compose, slot + minSlot, stack ); + } + return false; + } + + @Override + public void markDirty( int slot ) + { + if( checkSlot( slot ) ) + { + ItemHandlerUtil.markDirty( compose, slot + minSlot ); + } + } + +} diff --git a/src/main/java/appeng/util/inv/filter/AEItemDefinitionFilter.java b/src/main/java/appeng/util/inv/filter/AEItemDefinitionFilter.java new file mode 100644 index 000000000..a022d5579 --- /dev/null +++ b/src/main/java/appeng/util/inv/filter/AEItemDefinitionFilter.java @@ -0,0 +1,49 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv.filter; + + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + +import appeng.api.definitions.IItemDefinition; + + +public class AEItemDefinitionFilter implements IAEItemFilter +{ + private final IItemDefinition definition; + + public AEItemDefinitionFilter( IItemDefinition definition ) + { + this.definition = definition; + } + + @Override + public boolean allowExtract( IItemHandler inv, int slot, int amount ) + { + return true; + } + + @Override + public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack ) + { + return definition.isSameAs( stack ); + } + +} diff --git a/src/main/java/appeng/util/inv/filter/AEItemFilters.java b/src/main/java/appeng/util/inv/filter/AEItemFilters.java new file mode 100644 index 000000000..9a713d140 --- /dev/null +++ b/src/main/java/appeng/util/inv/filter/AEItemFilters.java @@ -0,0 +1,64 @@ +/* + * This file is part of Applied Energistics 2. + * Copyright (c) 2013 - 2017, 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 . + */ + +package appeng.util.inv.filter; + + +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; + + +public class AEItemFilters +{ + public static final IAEItemFilter INSERT_ONLY = new InsertOnlyFilter(); + public static final IAEItemFilter EXTRACT_ONLY = new ExtractOnlyFilter(); + + private AEItemFilters() + { + } + + private static class InsertOnlyFilter implements IAEItemFilter + { + @Override + public boolean allowExtract( IItemHandler inv, int slot, int amount ) + { + return false; + } + + @Override + public boolean allowInsert( IItemHandler inv, int slot, ItemStack stack ) + { + return true; + } + } + + private static class ExtractOnlyFilter 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 false; + } + } +} diff --git a/src/main/java/appeng/container/slot/QuartzKnifeOutput.java b/src/main/java/appeng/util/inv/filter/IAEItemFilter.java similarity index 68% rename from src/main/java/appeng/container/slot/QuartzKnifeOutput.java rename to src/main/java/appeng/util/inv/filter/IAEItemFilter.java index 319d479a4..6e9b671c2 100644 --- a/src/main/java/appeng/container/slot/QuartzKnifeOutput.java +++ b/src/main/java/appeng/util/inv/filter/IAEItemFilter.java @@ -1,6 +1,6 @@ /* * This file is part of Applied Energistics 2. - * Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved. + * Copyright (c) 2013 - 2017, 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 @@ -16,17 +16,16 @@ * along with Applied Energistics 2. If not, see . */ -package appeng.container.slot; +package appeng.util.inv.filter; -import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; -public class QuartzKnifeOutput extends SlotOutput +public interface IAEItemFilter { + boolean allowExtract( IItemHandler inv, int slot, int amount ); - public QuartzKnifeOutput( final IInventory a, final int b, final int c, final int d, final int i ) - { - super( a, b, c, d, i ); - } + boolean allowInsert( IItemHandler inv, int slot, ItemStack stack ); } diff --git a/src/main/java/appeng/util/iterators/AEInvIterator.java b/src/main/java/appeng/util/iterators/AEInvIterator.java index 796d43e3a..988b27873 100644 --- a/src/main/java/appeng/util/iterators/AEInvIterator.java +++ b/src/main/java/appeng/util/iterators/AEInvIterator.java @@ -35,7 +35,7 @@ public final class AEInvIterator implements Iterator public AEInvIterator( final AppEngInternalAEInventory inventory ) { this.inventory = inventory; - this.size = this.inventory.getSizeInventory(); + this.size = this.inventory.getSlots(); } @Override diff --git a/src/main/java/appeng/util/iterators/InvIterator.java b/src/main/java/appeng/util/iterators/InvIterator.java index 7ee8b63f3..942c1c4d5 100644 --- a/src/main/java/appeng/util/iterators/InvIterator.java +++ b/src/main/java/appeng/util/iterators/InvIterator.java @@ -21,21 +21,21 @@ package appeng.util.iterators; import java.util.Iterator; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; +import net.minecraftforge.items.IItemHandler; public final class InvIterator implements Iterator { - private final IInventory inventory; + private final IItemHandler inventory; private final int size; private int counter = 0; - public InvIterator( final IInventory inventory ) + public InvIterator( final IItemHandler inventory ) { this.inventory = inventory; - this.size = this.inventory.getSizeInventory(); + this.size = this.inventory.getSlots(); } @Override diff --git a/src/main/java/appeng/worldgen/MeteoritePlacer.java b/src/main/java/appeng/worldgen/MeteoritePlacer.java index f5c19c35e..d1a75c8db 100644 --- a/src/main/java/appeng/worldgen/MeteoritePlacer.java +++ b/src/main/java/appeng/worldgen/MeteoritePlacer.java @@ -29,7 +29,6 @@ import net.minecraft.block.state.IBlockState; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; -import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -223,10 +222,9 @@ public final class MeteoritePlacer this.skyChestDefinition.maybeBlock().ifPresent( block -> this.putter.put( w, x, y, z, block ) ); final TileEntity te = w.getTileEntity( x, y, z ); - if( te instanceof IInventory ) + final InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, EnumFacing.UP ); + if( ap != null ) { - final InventoryAdaptor ap = InventoryAdaptor.getAdaptor( te, EnumFacing.UP ); - int primary = Math.max( 1, (int) ( Math.random() * 4 ) ); if( primary > 3 ) // in case math breaks...