forked from TAIGA/TAIGA
Resolved a possible arithmetic exception. Divided by zero.
This commit is contained in:
@@ -16,7 +16,12 @@ public class TraitHeroic extends AbstractTrait {
|
||||
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
|
||||
int durability = ToolHelper.getCurrentDurability(tool);
|
||||
int durabilitymax = ToolHelper.getMaxDurability(tool);
|
||||
float calc = newDamage + (newDamage / 2) / (durability * durabilitymax / (durabilitymax - durability - 1));
|
||||
float calc;
|
||||
if ((durability * durabilitymax / (durabilitymax - durability - 1)) != 0) {
|
||||
calc = newDamage + (newDamage / 2) / (durability * durabilitymax / (durabilitymax - durability - 1));
|
||||
} else {
|
||||
calc = newDamage + (newDamage / 2) / ((durability * durabilitymax / (durabilitymax - durability - 1)) + 1);
|
||||
}
|
||||
if ((float) durability < (float) (0.10 * durabilitymax) || player.getHealth() < player.getMaxHealth() / 8 || (target.getHealth() == target.getMaxHealth() && random.nextFloat() > 0.8)) {
|
||||
return super.damage(tool, player, target, damage, calc, isCritical);
|
||||
} else return super.damage(tool, player, target, damage, newDamage * 0.9f, isCritical);
|
||||
|
Reference in New Issue
Block a user