Getting the ItemStack in the left hand

Sponge Build: spongevanilla-1.10.2-5.0.0-BETA-91
I am trying to get the ItemStack in the left hand from a player object to save and delete it. I tried using player.getInventory().poll() in a loop until the inventory is empty, but the Item in the left hand stays.

The inventory API implementation hasn’t yet been updated for the new offhand slot in 1.9/1.10.

In the main time, you can use Player#getItemInHand

If you want to remove from the hand, you can use myPlayer.setItemInHand(null), or in 1.9 and up, myPlayer.setItemInHand(HandTypes.LEFT, null)

Worked for me, thanks a lot! I actually used Sponge 4.1.0 by accident, so the implementation was old.

HandTypes.OFF_HAND**

1 Like