Need help with item give/remove with level function

Started by michaljef.xyz on

Topic category: Help with Minecraft modding (Java Edition)

Joined Mar 2025
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
Need help with item give/remove with level function

I need help with this system. This is a prototype unique mechanic.

Code 1

What should it do?

If the player clicks with the sword (right click trigger), it removes itself from the inventory, and gets another tool corresponding to the level (for easy debug), if the level is 0 (corresponding to the sword), the state is set to false and gets the other sword back as well.
If the level is more than 0, the state remains, change tools and reset item_level to 0

Problem: Often the player gets another item corresponding to another lower level.

 

Code 2

Second code

After useing a item that's food (the simplest debug trigger so far), on a 20% chance, it will do a level-up for item_level.
If the player still eats despite max level (4), it will alert them.

Problem: sometimes, for some reason, the level doesn't go up, but goes down.