mojira.dev
MC-265207

Durability bar can appear empty even if the item still has remaining uses

The bug

The durability bar used by damageable items can appear completely empty even in cases where it has remaining uses.

I consider this to be an issue for much the same reason as MC-120664 was fixed: empty durability should imply the tool is no longer usable at all, rather than having a tiny pool of residual uses.

How to reproduce

Have an item, preferably one with high base durability, that is a small matter of uses (greater than one) from breaking.

Expected results

As the item can still be used, the durability bar should appear at its lowest level, but not empty (i.e. one red pixel). Empty durability bars should only be used if the durability is 0 or a negative number.

Actual results

The tool can still be used even when the durability bar looks empty, even though this logically doesn't make much sense.

Code analysis

Code analysis by @unknown can be found in this comment.

Linked issues

Attachments

Comments 4

Apollo

I believe I've identified the source of the issue in the code.

MCP-Reborn 1.20, net.minecraft.world.item:

{{public int getBarWidth(ItemStack p_150900_) {}}
{{  return Math.round(13.0F - (float)p_150900_.getDamageValue() * 13.0F / (float)this.maxDamage);}}
{{}}}
The bar width can be rounded down to 0, even if the item's damage value is lower than the maximum damage it can take. Using Math.ceil instead of Math.round should fix the issue.
 

bigCRAFT

Mojang needs to hire apollo

Jon1337

I think the durability bar should stay empty at 1 because it can be used as a last warning before your tool breaks

muzikbike

It is worth noting that bundles are not affected:

[media]

muzikbike

(Unassigned)

Confirmed

Platform

Normal

UI

1.20.1, 23w35a, 1.20.2 Pre-release 1, 1.20.2 Pre-release 2, 1.20.2

Retrieved