Advertisement
yarinch

Untitled

Oct 1st, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. public void checkTorch() {
  2.         if (world.isAirBlock((int) player.posX, (int) player.posY, (int) player.posZ)) { //Checks if the block your'e trying to place a torch in isn't air. You can change it to the block you want.
  3.             for (int i = 0; i < player.inventory.getSizeInventory(); i++) { //Checks in the entire player's inventory. If you want to just check the hotbar, use 8 instead of the inventory size, since the hotbar is slots 0-8.
  4.                 ItemStack stack = player.inventory.getStackInSlot(i);
  5.                 if (stack.isItemEqual(new ItemStack(Blocks.torch))) { //Checks if the item is a torch.
  6.                     stack.stackSize--;
  7.                     world.setBlock((int) player.posX, (int) player.posY, (int) player.posZ, Blocks.torch);
  8.                     return; //Breaks if it has already placed a torch - no sense to keep looking for a torch.
  9.                 }
  10.             }
  11.         }
  12.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement