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 )