#Check for item with 0 durability

1 messages · Page 1 of 1 (latest)

bleak torrent
#

I have a set of commands which modify the durability of a held item by -1. But unfortunately minecraft does not automatically break items when they try to go below 0.

Is there anyway to check if the item a player is holding is at 0 durability, and subsequently delete it? My initial thought would be a predicate and clear command but predicates can only track damage on an item, and I'm hoping to make it more universal so I can use this for a personal library.

fluid orbit
#

Unfortunately that is the way durability actually gets tracked in item data: the damage they have taken. You therefore can't quickly check if it is at 0 durability, and instead need to check if its damage equals it max_damage.

It sounds like the item is a custom one you're adding the damage and max_damage components to, so this max_damage value should therefore be known. You can just check if the damage is that value via a hardcoded predicate, and indeed, even do it all in the item modifier and have it delete the item if it is

graceful totem
#

You can in fact check durability AND damage using:
https://minecraft.wiki/w/Data_component_predicate#damage

Minecraft Wiki

Data component predicates (historically known as item sub-predicates) are used to check conditions about data components. They are used in minecraft:item_predicate argument type, item modifiers, loot predicates, advancement criteria, and entity and block predicates. They return a pass or fail result to the invoker, who acts differently based on ...

#

execute if items entity @s weapon *[minecraft:damage~{durability:{max:0}}]

#

I am actually surprised you can get the durability to negative, what is the minecraft version?

#

I assume this is some older version, as I can't even reproduce negative durability in 1.21.11 (and probably any 1.20.5+ version)

graceful totem
#

If you do use item modifiers:

your modifier you can also do a conditional discard with the condition being that durability is 0. Make sure this runs before you deduct durability or it will break 1 damage early.

bleak torrent
graceful totem
#

an item typically breaks when durability is 0 and it is used again (and any durability is being subtracted)

#

if the item damages 3 per use, it breaks when you have 2 durability left

#

but if it has 3 durability left, it goes to 0 before breaking after the next use.

bleak torrent