old-tool-damage doesn't handle invulnerability overdamage
Shevchik opened this issue ยท 5 comments
The vanilla damage handling of invulnerability uses this code
if ((float)this.hurtResistantTime > (float)this.maxHurtResistantTime / 2.0F)
{
if (amount <= this.lastDamage)
{
return false;
}
this.damageEntity(source, amount - this.lastDamage);
this.lastDamage = amount;
flag = false;
}
else
{
this.lastDamage = amount;
this.hurtResistantTime = this.maxHurtResistantTime;
this.damageEntity(source, amount);
this.hurtTime = this.maxHurtTime = 10;
}
As you can see, if the player should be invulnerable (noDamageTicks > 10), it will still allow damage, but only if the new damage is bigger than the old one, and it deal a damage difference between new and old damage.
Old tools damage module however doesn't handle this case, and always sets base damage to the tools base damage, ignoring any possible downscale caused by invulnerability overdamage.
To easily reproduce the issue you can try attacking, jump attacking the player really fast, which will cause normal hit and then a crit (while player is still invulnerable).
This is most likely the reason for the following issues:
#455
#450
The solution might be to change the tools damage by directly changing the damage value for NMS Item instances, or scaling down the old tools damage based on EntityDamageEvent new tools original base relative to full damage.
Ok can you please summarise what should happen in 1.8 terms, and what the plugin is instead doing? So that I can figure out where along the chain of calculations this should be inserted.
Also, is the snippet of code from the 1.8 source?
The snippet is from 1.8 code source, but it doesn't matter, even current versions have almost the same code. The point is that even if player is "invulnerable" he is actually not.
So for example if player A hits player B with some tool for 2 damage, and then in next 3 ticks hits player B for 3 damage, he will inflict 1 damage instead (because hurt resistant timer is active, so it subtracts last damage). However OCM old tool damage does not take that into account, so it will change the base damage back to 3 (or whatever the damage of that specific tool was), without scaling down based on base damage relative to tool full base damage.