Incorrect damage applied to armor durability
elstur opened this issue · 11 comments
I can't seem to get the damage done to durability on armor to function right. It seems to randomly take 1-3 durability on a helm for example, per hit, regardless of using strength II potions or not. This is also unaffected by changing the armor modes or tool damage modes on/off.
Normally, with strength II, the average durability damage done to a helm is 5.
Is there something in this that is stopping the durability damage?
Perhaps this is caused due to the recalculation of damage. I was unaware that durability done to armor was dependent on damage caused / potion effects used. Do you have a source anywhere that explains the calculations for durability caused?
I don't, but I do know in my own testing any time I have cancelled the attack packets and re-issued my own entitydamagebyentity event, it has caused issues with durability. Not sure the source of this issue here, only really just noticed it when I launched my practice server.
I'll try and dig in and get back to you.
public void damageArmor(float damage) {
damage = damage / 4.0F;
if (damage < 1.0F) {
damage = 1.0F;
}
for(int i = 0; i < this.armorInventory.size(); ++i) {
ItemStack itemstack = this.armorInventory.get(i);
if (itemstack.getItem() instanceof ItemArmor) {
itemstack.damageItem((int)damage, this.player);
}
}
}
called in
protected float applyArmorCalculations(DamageSource source, float damage) {
if (!source.isUnblockable()) {
this.damageArmor(damage);
damage = CombatRules.getDamageAfterAbsorb(damage, (float)this.getTotalArmorValue(), (float)this.getEntityAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).getAttributeValue());
}
return damage;
}
called in
protected void damageEntity(DamageSource damageSrc, float damageAmount) {
if (!this.isEntityInvulnerable(damageSrc)) {
damageAmount = this.applyArmorCalculations(damageSrc, damageAmount);
And this for thorns:
public void onUserHurt(EntityLivingBase user, Entity attacker, int level) {
Random random = user.getRNG();
ItemStack itemstack = EnchantmentHelper.getEnchantedItem(Enchantments.THORNS, user);
if (shouldHit(level, random) /* enchantment activated, damage reflected */) {
if (attacker != null) {
attacker.attackEntityFrom(DamageSource.causeThornsDamage(user), (float)getDamage(level, random));
}
if (!itemstack.func_190926_b() /* itemstack is not null, still has durability and is not air */) {
itemstack.damageItem(3, user);
}
} else if (!itemstack.func_190926_b() /* itemstack is not null, still has durability and is not air */) {
itemstack.damageItem(1, user);
}
}
This thorns damage should be additional to the one above (so it takes 1 to 3 extra damage)
All code for 1.12.
@I-Al-Istannen is there any way you could PR this math into the old armor module? You seem to have quite a handle on the formulas for this.
OCM doesn't seem to cancel and re-issue the event, so the armor should work as it always did?
The relevant part for strength is this:
/**
* Damages armor in each slot by the specified amount.
*/
public void damageArmor(float damage)
{
damage = damage / 4.0F;
if (damage < 1.0F)
{
damage = 1.0F;
}
for (int i = 0; i < this.armorInventory.size(); ++i)
{
ItemStack itemstack = this.armorInventory.get(i);
if (itemstack.getItem() instanceof ItemArmor)
{
itemstack.damageItem((int)damage, this.player);
}
}
}
i.e. the armor damage depends on the amount of damage received. I don't see any code disabling that mechanism in OCM and I can not reproduce it:
And after hitting with Strength II and a sharpness 5 diamond sword:
The attack did 16 damage (6 for strength 2, 7 for the sword and 3 for sharpness), so the armor loses floor(16 / 4)
durability, which is `4´. So this is correct.
I have old-armor-strength disabled, not sure if that makes much of a difference, but durability is always only doing 1-2 damage no matter what. I will try and do more testing and get back with you
@elstur What version of the plugin are you using?
Well, it says version 1.6.5 but it was a development build and I'm not sure which pull. It was the most recent version prior to me making this post.
I just haven't had the ability to actually test this on my dev server yet.
Well, you should be using at least 1.6.6 from here or even the newest development build from the Jenkins server.