How do i detect when the item the player is holding lost durability?

Started by MamaLuigi on

Topic category: Help with modding (Java Edition)

Last seen on 00:58, 14. Oct 2024
Joined Sep 2021
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
How do i detect when the item the player is holding lost durability?

The title explains itself, how do i detect when the item the player is holding lost durability?

 

For example, if the player is holding an Iron Pickaxe, and the pickaxe lost 1 point of durability, how would i be able to detect that?

Last seen on 16:12, 15. Oct 2024
Joined May 2022
Points:

User statistics:

  • Modifications:
  • Forum topics:
  • Wiki pages:
  • MCreator plugins:
  • Comments:
I don't know if there's a…
Fri, 10/20/2023 - 20:18

I don't know if there's a way to detect this directly, but you could keep in mind that there's a limited number of ways items can lose durability. Pickaxes, for example, only ever lose durability when they break blocks or hit things. (This is slightly random though, and gets more complicated with enchantments and things.) 

...It's possible you could try creating a custom number NBT tag that applies to an item, keeping track of the item's last durability. Then, if the item's current durability no longer matches the NBT tag, you know that durability has changed, and can update the NBT tag. I'm not how sure if this would work well, but it's worth a try.