How do you detect item count in inventory

Started by IndigoTail on

Topic category: Help with modding (Java Edition)

Last seen on 11:40, 8. Dec 2021
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do you detect item count in inventory

I have made a firearm magazine system in my mod, but I want the system to, for example, automatically reset ammo count to 30 (for rifle mags) if the ammo item exceeds 30.

Is there a way to detect the amount of a certain item in a player's inventory?

Last seen on 19:55, 7. Jan 2021
Joined Aug 2019
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
No, but you could make an if…
Tue, 12/03/2019 - 19:39

No, but you could make an if statement to test if the player has the item, remove one, test again, and remove another, and repeat this as many times as is necessary. If it is false at any point in it, you just need an else giving the player the appropriate amount of the item. Hopefully this will be added as an actual feature in the future.

Last seen on 11:40, 8. Dec 2021
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Thanks, I'll definitely try…
Wed, 12/04/2019 - 14:30

Thanks, I'll definitely try that out

Screw me sideways I have an ammo type called "LMG Box ammo" which has over 50 rounds

Last seen on 11:40, 8. Dec 2021
Joined Nov 2017
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Still need some…
Wed, 12/04/2019 - 14:33

Still need some brainstorming to make it work, but it sounds viable