How to get Slot Id of Item in Main Hand?

Started by SparkleArts on

Topic category: Help with Minecraft modding (Java Edition)

Joined Feb 2018
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to get Slot Id of Item in Main Hand?

I want to create a Command that adds Lore to Items, but I can't find it to work because I have problems to detect the slot number/id of the Item that in Main Hand.

Can someone help with this?

Joined Feb 2023
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Here is how I detected theā€¦
Mon, 04/03/2023 - 18:17

Here is how I detected the slot ID of the item in your main Hand.

https://imgur.com/5ufv8C2

I created a temporary item to replace with the the item in your main hand. Then I searched the inventory (slots 0 - 9) for said temporary item. When it finds that item, it exits the loop at give you the slot ID number of the item in your main Hand (variable: num).

You can return the item to your main Hand if needed, as the item info was stored in the inHand variable.