private void handleArea( World world, int i, int j, int k, EntityPlayer entityplayer, TileEntityToolRack te, int slot, int dir) { boolean hasToolInHand = entityplayer.getCurrentEquippedItem() != null && (entityplayer.getCurrentEquippedItem().getItem() instanceof ItemTool || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemWeapon || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemHoe || entityplayer.getCurrentEquippedItem().getItem() instanceof ItemProPick); if (te.storage[slot] == null && hasToolInHand) { te.storage[slot] = entityplayer.getCurrentEquippedItem().copy(); entityplayer.inventory.mainInventory[entityplayer.inventory.currentItem] = null; } else if (te.storage[slot] != null) { te.ejectItem(slot, dir); te.storage[slot] = null; } }
public boolean onBlockActivated( World world, int i, int j, int k, EntityPlayer entityplayer, int side, float hitX, float hitY, float hitZ) { if (!world.isRemote) { TileEntityToolRack te = (TileEntityToolRack) world.getBlockTileEntity(i, j, k); int dir = world.getBlockMetadata(i, j, k); if (te != null) { if (dir == 0) { if (hitX < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 0); } else if (hitX > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 0); } else if (hitX < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 0); } else if (hitX > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 0); } } else if (dir == 1) { if (hitZ < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 1); } else if (hitZ > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 1); } else if (hitZ < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 1); } else if (hitZ > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 1); } } else if (dir == 2) { if (hitX < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 2); } else if (hitX > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 2); } else if (hitX < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 2); } else if (hitX > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 2); } } else if (dir == 3) { if (hitZ < 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 0, 3); } else if (hitZ > 0.5 && hitY > 0.5) { handleArea(world, i, j, k, entityplayer, te, 1, 3); } else if (hitZ < 0.5) { handleArea(world, i, j, k, entityplayer, te, 2, 3); } else if (hitZ > 0.5) { handleArea(world, i, j, k, entityplayer, te, 3, 3); } } te.broadcastPacketInRange(te.createUpdatePacket()); return true; } } return false; }