Skip to content

Commit

Permalink
Take offhand into account with TNT auto-ignite.
Browse files Browse the repository at this point in the history
It turns out that the Inventory#removeItem(ItemStack) method doesn't actually work for items held in the offhand. This commit changes the behavior so it simply decrements the ItemStack amount for the item held during the block place. Note that going from 1 to 0 will result in an air stack, which will just disappear from the inventory.

Fixes #429
  • Loading branch information
garbagemule committed Apr 26, 2018
1 parent 4b0b40f commit 8d9764d
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/main/java/com/garbagemule/MobArena/ArenaListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,12 @@ public void onBlockPlace(BlockPlaceEvent event) {
// If auto-igniting, set the planter of the primed TNT instead
if (autoIgniteTNT) {
event.setCancelled(true);
event.getPlayer().getInventory().removeItem(new ItemStack(Material.TNT, 1));
ItemStack stack = event.getItemInHand();
if (stack == null || stack.getType() != Material.TNT) {
plugin.getLogger().warning("Player " + event.getPlayer().getDisplayName() + " just placed TNT without holding a TNT block");
return;
}
stack.setAmount(stack.getAmount() - 1);
TNTPrimed tnt = b.getWorld().spawn(b.getRelative(BlockFace.UP).getLocation(), TNTPrimed.class);
setPlanter(tnt, event.getPlayer());
return;
Expand Down

0 comments on commit 8d9764d

Please sign in to comment.