mojira.dev
MC-86840

Armor durability affecting protection is not working right

The code for the new "damaged armor doesn't protect as well" feature seems broken. In particular, the code looks something like this:

int protection = ((ItemArmor)itemStack.getItem()).protectionAmount;
int durability = itemStack.getDurability();
int damage = itemStack.getDamage();
if ( damage > durability / 2 ) {
    protection = Math.ceiling( (float)(durability - damage) / (float)(durability / 2) );
}

The code seems pretty clear that it's trying to gradually decrease the protection, full protection until half-damaged then decreasing linearly to no protection when fully-damaged. But as it is it instead sets the protection to 1 as soon as the armor hits half-damaged. To calculate that correctly, it should be

protection = Math.ceiling( (float)protection * (float)(durability - damage) / (float)(durability / 2) );

(Mods: If "set to 1 at half-damaged" were the intended behavior, it would just do that as "protection = 1" instead of the formula shown).

Comments 7

MC-86832 was just confusion with the new mechanics, this ticket is about incorrect calculation of protection values.

Oh god. This bug is probably going to remain hidden among the vast amount of people neglecting to do full testing and just noticing that their full prot 5 diamond armour has gone down to 4 points, and others saying 'shut up, Mojang knows best'. While it is game breaking and just a one line fix, I doubt it will be noticed by the community for a while.

Of course, it doesn't help that it has no labels and is still for some unfathomable reason unconfirmed when I see constant posts about the broken mechanic everywhere!

Fixed for Future Version 1.9+. See reddit post above.

Anomie X

(Unassigned)

Community Consensus

Minecraft 15w34b, Minecraft 15w34c, Minecraft 15w34d

Minecraft 15w36a

Retrieved