How do you detect item count in inventory

Started by IndigoTail on Tue, 12/03/2019 - 14:55

Topic category: Help with modding (Java Edition)

Last seen on 15:56, 13. Jul 2020
Joined Nov 2017
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • MCreator plugins:
  • Comments:
How do you detect item count in inventory
Tue, 12/03/2019 - 14:55

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 09:17, 20. Feb 2020
Joined Aug 2019
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 15:56, 13. Jul 2020
Joined Nov 2017
User points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • Tracker tickets:
  • 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 15:56, 13. Jul 2020
Joined Nov 2017
User points:

User statistics:

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

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