Fix overflow when charging ultimate battery

This commit is contained in:
Antifluxfield 2017-10-21 00:02:40 +08:00
parent 2d8df8d145
commit b3e0abed70

View file

@ -256,7 +256,8 @@ public abstract class GT_MetaBase_Item extends GT_Generic_Item implements ISpeci
Long[] tStats = getElectricStats(aStack);
if (tStats == null || tStats[2] > aTier || !(tStats[3] == -1 || tStats[3] == -3 || (tStats[3] < 0 && aCharge == Integer.MAX_VALUE)) || aStack.stackSize != 1)
return 0;
long tChargeBefore = getRealCharge(aStack), tNewCharge = aCharge == Integer.MAX_VALUE ? Long.MAX_VALUE : Math.min(Math.abs(tStats[0]), tChargeBefore + (aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge)));
long tTransfer = aIgnoreTransferLimit ? (long) aCharge : Math.min(tStats[1], (long) aCharge);
long tChargeBefore = getRealCharge(aStack), tNewCharge = aCharge == Integer.MAX_VALUE ? Long.MAX_VALUE : Math.min(Math.abs(tStats[0]), Long.MAX_VALUE - tTransfer >= tChargeBefore ? tChargeBefore + tTransfer : Long.MAX_VALUE);
if (!aSimulate) setCharge(aStack, tNewCharge);
return tNewCharge - tChargeBefore;
}