Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void checkTorch() {
- 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.
- 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.
- ItemStack stack = player.inventory.getStackInSlot(i);
- if (stack.isItemEqual(new ItemStack(Blocks.torch))) { //Checks if the item is a torch.
- stack.stackSize--;
- world.setBlock((int) player.posX, (int) player.posY, (int) player.posZ, Blocks.torch);
- return; //Breaks if it has already placed a torch - no sense to keep looking for a torch.
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement