package minestrapteam.mods.minestrappolation.block.machines; import minestrapteam.mods.minestrappolation.Minestrappolation; import minestrapteam.mods.minestrappolation.handlers.MGuiHandler; import minestrapteam.mods.minestrappolation.tileentity.TileEntityBarrel; import net.minecraft.block.BlockFalling; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.material.Material; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.inventory.Container; import net.minecraft.inventory.IInventory; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.BlockPos; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumWorldBlockLayer; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class BlockBarrel extends BlockFalling implements ITileEntityProvider { public BlockBarrel() { super(Material.wood); } @Override public void breakBlock(World world, BlockPos pos, IBlockState state) { TileEntity te = world.getTileEntity(pos); if (te instanceof IInventory) { IInventory inventory = (IInventory) te; for (int i1 = 0; i1 < inventory.getSizeInventory(); ++i1) { ItemStack itemstack = inventory.getStackInSlot(i1); if (itemstack != null) { float f = world.rand.nextFloat() * 0.8F + 0.1F; float f1 = world.rand.nextFloat() * 0.8F + 0.1F; EntityItem entityitem; for (float f2 = world.rand.nextFloat() * 0.8F + 0.1F; itemstack.stackSize > 0; world.spawnEntityInWorld(entityitem)) { int j1 = world.rand.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; entityitem = new EntityItem(world, pos.getX() + f, pos.getY() + f1, pos.getZ() + f2, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); entityitem.motionX = world.rand.nextGaussian() * 0.05F; entityitem.motionY = world.rand.nextGaussian() * 0.05F + 0.2F; entityitem.motionZ = world.rand.nextGaussian() * 0.05F; if (itemstack.hasTagCompound()) { entityitem.getEntityItem() .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); } } } } } super.breakBlock(world, pos, state); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumFacing side, float hitX, float hitY, float hitZ) { if (worldIn.isRemote) return true; playerIn .openGui(Minestrappolation.instance, MGuiHandler.GUIID_BARREL, worldIn, pos.getX(), pos.getY(), pos.getZ()); return true; } @Override public boolean onBlockEventReceived(World world, BlockPos pos, IBlockState state, int eventID, int eventParam) { super.onBlockEventReceived(world, pos, state, eventID, eventParam); TileEntity te = world.getTileEntity(pos); return te != null && te.receiveClientEvent(eventID, eventParam); } @Override public TileEntity createNewTileEntity(World world, int metadata) { return new TileEntityBarrel(); } @Override public boolean isOpaqueCube() { return false; } @Override public boolean isFullCube() { return false; } @Override @SideOnly(Side.CLIENT) public EnumWorldBlockLayer getBlockLayer() { return EnumWorldBlockLayer.CUTOUT; } @Override public boolean hasComparatorInputOverride() { return true; } @Override public int getComparatorInputOverride(World worldIn, BlockPos pos) { return Container.calcRedstone(worldIn.getTileEntity(pos)); } }