package com.miningmark48.pearcelmod.block; import com.miningmark48.pearcelmod.reference.GUIs; import com.miningmark48.pearcelmod.reference.Reference; import com.miningmark48.pearcelmod.tileentity.TileEntityPearcelStorageCrate; import net.minecraft.block.BlockContainer; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.IInventory; import net.minecraft.inventory.InventoryHelper; import net.minecraft.item.ItemStack; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockPearcelStorageCrate extends BlockContainer{ public BlockPearcelStorageCrate() { super(Material.WOOD); setHardness(1.5F); setResistance(3.0F); } public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityPearcelStorageCrate(); } @Override public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof IInventory) { InventoryHelper.dropInventoryItems(worldIn, pos, (IInventory)tileentity); worldIn.updateComparatorOutputLevel(pos, this); } super.breakBlock(worldIn, pos, state); } @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase placer, ItemStack stack){ // Disabled because of bug // if (stack.hasDisplayName()){ // ((TileEntityPearcelStorageCrate) world.getBlockState(pos)).setCustomName(stack.getDisplayName()); // } } @Override public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ){ if (!player.isSneaking()){ player.openGui(Reference.MOD_ID, GUIs.gui_id_pearcel_storage_crate, world, pos.getX(), pos.getY(), pos.getZ()); return true; }else{ return false; } } }