/** 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) { if (!world.isRemote) { if (player.isSneaking()) { player.openGui(FullPower.instance, GuiHandler.GuiIDs.CAMO_MINE.ordinal(), world, x, y, z); } TileEntityCamoMine te = (TileEntityCamoMine) world.getTileEntity(x, y, z); if (te.getCamouflage(side) != null) { ItemStack camoStack = te.getCamouflage(side); te.setCamouflage(null, side); EntityItem itemEntity = new EntityItem(world, x, y, z, camoStack); LogHelper.info("StackSize=" + camoStack.stackSize); // Tell world this item needs to be spawned world.spawnEntityInWorld(itemEntity); } else { ItemStack playerItem = player.getCurrentEquippedItem(); if (playerItem != null) { ItemStack camoStack = playerItem.splitStack(1); // Remove 1 from stack ChatHelper.send(camoStack.toString()); te.setCamouflage(camoStack, side); } } } return true; }
@SideOnly(Side.CLIENT) public IIcon getIcon(IBlockAccess world, int x, int y, int z, int side) { TileEntityCamoMine te = (TileEntityCamoMine) world.getTileEntity(x, y, z); ItemStack stack = te.getCamouflage(side); if (stack != null && stack.getItem() instanceof ItemBlock) { Block block = ((ItemBlock) stack.getItem()).field_150939_a; return block.getIcon(side, stack.getItemDamage()); } else { return super.getIcon(world, x, y, z, side); } }
@SideOnly(Side.CLIENT) public void updateProgressBar(int id, int value) { super.updateProgressBar(id, value); if (id == 0) { te.setTimer(value); } }
public void detectAndSendChanges() { super.detectAndSendChanges(); if (lastTimer != te.getTimer()) { for (ICrafting crafter : (List<ICrafting>) this.crafters) { crafter.sendProgressBarUpdate(this, 0, te.getTimer()); } lastTimer = te.getTimer(); } if (!lastTarget.equals(te.getTarget())) { for (Object crafter : (List<ICrafting>) this.crafters) { if (crafter instanceof EntityPlayerMP) { NetworkHandler.sendTo( new MessageHandleTextUpdate(te, 0, te.getTarget()), (EntityPlayerMP) crafter); } } lastTarget = te.getTarget(); } }
@Override public boolean canInteractWith(EntityPlayer player) { return te.isUseableByPlayer(player); }