Workbench - Hopper support

This commit is contained in:
Emmanuel BENOîT 2016-07-21 11:08:51 +02:00
parent a6567c90da
commit a95ca66528

View file

@ -8,10 +8,15 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.NetworkManager; import net.minecraft.network.NetworkManager;
import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.network.play.server.SPacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IWorldNameable; import net.minecraft.world.IWorldNameable;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants.NBT; 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 customName = "";
private String defaultRecipe = ""; private String defaultRecipe = "";
private IItemHandler itemHandler;
@Override @Override
public String getName( ) 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 @Override
public boolean shouldRefresh( final World world , final BlockPos pos , final IBlockState oldState , public boolean shouldRefresh( final World world , final BlockPos pos , final IBlockState oldState ,
final IBlockState newSate ) final IBlockState newSate )