diff --git a/src/main/java/org/ultramine/economy/BasicHoldings.java b/src/main/java/org/ultramine/economy/BasicHoldings.java index c91e9e9..e6eada9 100644 --- a/src/main/java/org/ultramine/economy/BasicHoldings.java +++ b/src/main/java/org/ultramine/economy/BasicHoldings.java @@ -2,7 +2,6 @@ import net.minecraft.command.CommandException; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.util.MathHelper; public class BasicHoldings implements IHoldings { @@ -70,7 +69,7 @@ { if(amount <= 0.0d) throw new CommandException("economy.fail.negativeamount"); - this.balance += MathHelper.floor_double(amount*100); + this.balance = Math.addExact(this.balance, floor(amount*100)); acc.onHoldingsChange(this); } @@ -79,14 +78,14 @@ { if(amount <= 0.0d) throw new CommandException("economy.fail.negativeamount"); - this.balance -= MathHelper.ceiling_double_int(amount*100); + this.balance = Math.subtractExact(this.balance, ceiling(amount*100)); acc.onHoldingsChange(this); } @Override public void subtractChecked(double amount) { - if((balance - MathHelper.ceiling_double_int(amount*100)) < 0L) + if(Math.subtractExact(balance, ceiling(amount*100)) < 0L) throw new CommandException("economy.fail.notenough"); subtract(amount); } @@ -114,13 +113,13 @@ @Override public boolean hasEnough(double amount) { - return MathHelper.ceiling_double_int(amount*100) <= this.balance; + return ceiling(amount*100) <= this.balance; } @Override public boolean hasOver(double amount) { - return MathHelper.ceiling_double_int(amount*100) < this.balance; + return ceiling(amount*100) < this.balance; } @Override @@ -148,4 +147,16 @@ { this.balance = nbt.getLong("b"); } + + private static long ceiling(double arg) + { + long i = (long)arg; + return arg > (double)i ? Math.addExact(i, 1) : i; + } + + private static long floor(double arg) + { + long i = (long)arg; + return arg < (double)i ? Math.subtractExact(i, 1) : i; + } }