I was googling this and couldn't figure out, what the the slot id for the offhand? Thanks in advance.
Could you possibly use instead? I'm just getting into development so i'm not sure if that's what you're looking for. Code (Text): player.getInventory().getItemInOffHand(); Edit: Just tried it. Doesn't seem to work Edit2: Just kidding. I was a dummy and tested the wrong thing Code (Text): player.getInventory().getItemInOffHand(); or player.getEquipment().getItemInOffHand() Work to get the off hand 'Slot'. Even though it's treated not like a slot
A good tip when trying to find something is to just nose around. Especially given the main IDEs IntelliJ and Eclipse they give suggestions on what methods you can use so usually that can give you a trail to fixing/finding a solution. That's how I found that method btw.
well done in spigot there's a method wherein you can edit the thread and change the prefix as solved if the problem is no longer existed.
I'm pretty sure he's trying to find the ID number of the off hand slot, so he can call Inventory#setItem. You can find this pretty easily by making an event listener that prints the clicked slot to console when a player clicks in an inventory.
Edit: This should help. Code (Text): public ItemStack getItemInOffHand() { return CraftItemStack.asCraftMirror(getInventory().extraSlots[0]); } public void setItemInOffHand(ItemStack item) { ItemStack[] extra = getExtraContents(); extra[0] = item; setExtraContents(extra); }
What's the difference between that and just setting the offhand using the command I suggested? Because it seems you can set item for off hand like what I said previously
There isn't a difference, and you didn't suggest that, you suggested using PlayerInventory#getItemInOffHand, when it should be set. Also, it's not a command, it's a method (or function).