Mojira Archive
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).

Fixed

Anomie X

2015-08-20, 11:46 PM

2015-09-02, 06:25 PM

2015-09-02, 06:25 PM

19

6

Community Consensus

Minecraft 15w34b, Minecraft 15w34c, Minecraft 15w34d

Minecraft 15w36a