fixed #174: added missing safety factor to division

Signed-off-by: Giovanni Harting <539@idlegandalf.com>
This commit is contained in:
2018-08-26 00:26:10 +02:00
parent 809c10ef51
commit 7e4c4baf05

View File

@@ -13,22 +13,22 @@ public class TraitHeroic extends AbstractTrait {
}
@Override
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 durabilitymax = ToolHelper.getMaxDurability(tool);
int safeDenominator = durabilitymax - durability - 1;
if (safeDenominator <= 0) {
safeDenominator = 1;
}
float calc;
if ((durability * durabilitymax / (durabilitymax - durability - 1)) != 0) {
if ((durability * durabilitymax / (durabilitymax - durability - 1 / safeDenominator)) != 0) {
calc = newDamage + (newDamage / 2) / (durability * durabilitymax / safeDenominator);
} else {
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);
} else return super.damage(tool, player, target, damage, newDamage * 0.9f, isCritical);
}