forked from TAIGA/TAIGA
fix divide by zero error (#121)
This commit is contained in:

committed by
Giovanni Harting

parent
719d326f7e
commit
b874a41abb
@@ -16,11 +16,15 @@ public class TraitHeroic extends AbstractTrait {
|
|||||||
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
|
public float damage(ItemStack tool, EntityLivingBase player, EntityLivingBase target, float damage, float newDamage, boolean isCritical) {
|
||||||
int durability = ToolHelper.getCurrentDurability(tool);
|
int durability = ToolHelper.getCurrentDurability(tool);
|
||||||
int durabilitymax = ToolHelper.getMaxDurability(tool);
|
int durabilitymax = ToolHelper.getMaxDurability(tool);
|
||||||
|
int safeDenominator = durabilitymax - durability - 1;
|
||||||
|
if (safeDenominator <= 0) {
|
||||||
|
safeDenominator = 1;
|
||||||
|
}
|
||||||
float calc;
|
float calc;
|
||||||
if ((durability * durabilitymax / (durabilitymax - durability - 1)) != 0) {
|
if ((durability * durabilitymax / (durabilitymax - durability - 1)) != 0) {
|
||||||
calc = newDamage + (newDamage / 2) / (durability * durabilitymax / (durabilitymax - durability - 1));
|
calc = newDamage + (newDamage / 2) / (durability * durabilitymax / safeDenominator);
|
||||||
} else {
|
} else {
|
||||||
calc = newDamage + (newDamage / 2) / ((durability * durabilitymax / (durabilitymax - durability - 1)) + 1);
|
calc = newDamage + (newDamage / 2) / ((durability * durabilitymax / safeDenominator) + 1);
|
||||||
}
|
}
|
||||||
if ((float) durability < (float) (0.10 * durabilitymax) || player.getHealth() < player.getMaxHealth() / 8 || (target.getHealth() == target.getMaxHealth() && random.nextFloat() > 0.8)) {
|
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);
|
return super.damage(tool, player, target, damage, calc, isCritical);
|
||||||
|
Reference in New Issue
Block a user