/** Called upon block activation (right click on the block.) */ @Override public boolean onBlockActivated( World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) { TEHopper te = getHopperTE(world, x, y, z); if (world.isRemote) { if (te != null && te.pressBlock != null && player.isSneaking()) { te.pressBlock = null; te.pressCooldown = 0; } return true; } else { if (te != null && te.pressCooldown == 0) { player.openGui(TerraFirmaCraft.instance, 49, world, x, y, z); } else if (te != null && te.pressBlock != null && player.isSneaking()) { TFC_Core.giveItemToPlayer(te.pressBlock, player); te.pressBlock = null; te.pressCooldown = 0; } return true; } }
/** Called when the block is placed in the world. */ @Override public void onBlockPlacedBy( World world, int x, int y, int z, EntityLivingBase entity, ItemStack is) { super.onBlockPlacedBy(world, x, y, z, entity, is); if (is.hasDisplayName()) { TEHopper tileentityhopper = getHopperTE(world, x, y, z); tileentityhopper.setCustomName(is.getDisplayName()); } }
@Override public void breakBlock(World world, int x, int y, int z, Block block, int meta) { if (world.getTileEntity(x, y, z) instanceof TEHopper) { TEHopper te = (TEHopper) world.getTileEntity(x, y, z); for (int i1 = 0; i1 < te.getSizeInventory(); ++i1) { ItemStack itemstack = te.getStackInSlot(i1); if (itemstack != null) { while (itemstack.stackSize > 0) { int j1 = this.random.nextInt(21) + 10; if (j1 > itemstack.stackSize) { j1 = itemstack.stackSize; } itemstack.stackSize -= j1; EntityItem entityitem = new EntityItem( world, x + 0.5f, y + 0.5f, z + 0.5f, new ItemStack(itemstack.getItem(), j1, itemstack.getItemDamage())); if (itemstack.hasTagCompound()) { entityitem .getEntityItem() .setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy()); } // float f3 = 0.05F; world.spawnEntityInWorld(entityitem); } } } if (te.pressBlock != null) { EntityItem entityitem = new EntityItem(world, x + 0.5, y + 0.5, z + 0.5, te.pressBlock); world.spawnEntityInWorld(entityitem); } world.func_147453_f(x, y, z, block); } super.breakBlock(world, x, y, z, block, meta); }