![Mythic Upgrades](https://media.forgecdn.net/avatars/thumbnails/989/840/256/256/638502667247706173_animated.gif)
Infinite Recursive damage() Call
andrew0030 opened this issue ยท 1 comments
So while playing on a Server with a friend we came across an edge case issue.
Basically if two players are wearing full sapphire armor, and they have the damage deflection effect active (given by full set), if player A attacks player B it causes the damage to be deflected, which then triggers player B's deflection, and you can see where this is going.
I'm pretty sure this method right here. Is what causes the problem. There seems to be some logic in place to prevent this, but I think it could be tweaked to be more robust, for instance the variable should always be reset regardless of whether another Mod catches any potential issues that may arise during the damage()
method. The recursion check should probably also be the first thing inside the if statement.
Here is an example of what it could look like:
@Inject(method = "damage", at = @At(value = "TAIL"))
private void deflectDamage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
if (has_damage_been_deflected) return;
if (cir.getReturnValue()) {
StatusEffectInstance deflection = this.getActiveStatusEffects().get(MUEffects.DAMAGE_DEFLECTION);
if (deflection != null) {
Entity attacker = source.getAttacker();
if (attacker != null && attacker.distanceTo(this) <= 3.0f) {
has_damage_been_deflected = true;
try {
attacker.damage(MythicUpgradesDamageTypes.create(attacker.getWorld(),
MythicUpgradesDamageTypes.DEFLECTING_DAMAGE_TYPE, (LivingEntity)(Object)this), deflecting_damage);
} catch (Throwable err) {
has_damage_been_deflected = false;
throw new RuntimeException(err);
}
has_damage_been_deflected = false;
}
}
}
}
We haven't tested this code snippet so take it with a grain of salt and test it first.
Hey I'm back, so I decided to pull and check if this fixes the issue, but to my surprise everything was working, so I went looking and low and behold Prominence 2 is using a very outdated version of the Mod, so I downloaded latest installed it both locally and on the server and BOOM it works,
So sorry about the false report, I should have made sure the Mod Pack was using latest, but I guess my ignorance blinded me.
That said I would argue the try/catch
is still a good idea to add!