How to get amount of a certain item in player's inventory

Started by DESTROYER on

Topic category: Help with MCreator software

Joined Sep 2020
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How to get amount of a certain item in player's inventory

I am making a mod that needs to know how many iron ingots the player has in their inventory at all times. The only way I have found of figuring this out is:

 

set (local: counter) to (0)

while (entity has (iron ingot) in inventory) {

     remove (1) (iron ingot) from entity's inventory

     set (local: counter) to ((get local: counter) + 1)

}

set (global: overlayText) to (get local: counter)

add (get local: counter) (iron ingot) to entity's inventory

 

The problem with this is its probably inefficient because it has to do this every player tick, but mainly because it plays the dropping and picking up minecraft inventory sound constantly super fast and it sounds like a machine gun. Also the little ingot icon gets streatched out because its being dropped and added.

Does anyone know how to get the number of iron ingots in a player's inventory?

Thanks