From a95ca6652897846a23a1082f9cb58f352ab109d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emmanuel=20Beno=C3=AEt?= Date: Thu, 21 Jul 2016 11:08:51 +0200 Subject: [PATCH] Workbench - Hopper support --- .../tech/base/workbench/TBWBTileEntity.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/java/mmm/tech/base/workbench/TBWBTileEntity.java b/src/java/mmm/tech/base/workbench/TBWBTileEntity.java index 3455680..d0771f0 100644 --- a/src/java/mmm/tech/base/workbench/TBWBTileEntity.java +++ b/src/java/mmm/tech/base/workbench/TBWBTileEntity.java @@ -8,10 +8,15 @@ import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.EnumFacing; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IWorldNameable; import net.minecraft.world.World; +import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.Constants.NBT; +import net.minecraftforge.items.CapabilityItemHandler; +import net.minecraftforge.items.IItemHandler; +import net.minecraftforge.items.wrapper.InvWrapper; @@ -41,6 +46,8 @@ public class TBWBTileEntity private String customName = ""; private String defaultRecipe = ""; + private IItemHandler itemHandler; + @Override public String getName( ) @@ -62,6 +69,28 @@ public class TBWBTileEntity } + @Override + public boolean hasCapability( final Capability< ? > capability , final EnumFacing facing ) + { + return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY && facing != null + || super.hasCapability( capability , facing ); + } + + + @Override + @SuppressWarnings( "unchecked" ) + public < T > T getCapability( final net.minecraftforge.common.capabilities.Capability< T > capability , + final net.minecraft.util.EnumFacing facing ) + { + if ( capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY ) { + return (T) ( this.itemHandler == null + ? ( this.itemHandler = new InvWrapper( this.storage ) ) + : this.itemHandler ); + } + return super.getCapability( capability , facing ); + } + + @Override public boolean shouldRefresh( final World world , final BlockPos pos , final IBlockState oldState , final IBlockState newSate )