Getting slot in block inventory that contains item

Started by Jaklyn on

Topic category: Help with Minecraft modding (Java Edition)

Joined Jun 2024
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Getting slot in block inventory that contains item

Hello,

I am trying to make a procedure that checks which slot an item is within a block inventory. For example, lets say im trying to make it so if any inventory holds a dirt block, its swapped with a diamond. 

Can anyone help?

Joined Aug 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
You could use a local…
Mon, 12/01/2025 - 00:26

You could use a local variable to check each slot, and use repeat # times to check every slot.
Code example:

[ Image link if it doesn't show: https://imgur.com/a/mcreator-help-1-utArYqf ]

What it does by each block:

  1. Sets the local variable (in the example checknum) to 0 (for slot #0)
  2. Repeat # times, set # to amount of slots in inventory +1
  3. IF statement: if (Get copy of item from slot # [checknum variable]) of block = item (dirt, in this case)
  4. Set (get number of items from slot [checknum variable] of block) (diamond) in slot (checknum variable(
  5. Sets the local variable (checknum) to (checknum + 1)

I hope this helps!