Skip to content

Commit ea5060f

Browse files
authored
Fix overflow when using Creative Storage Unit on FE consumer (#1134)
1 parent c5a997b commit ea5060f

File tree

1 file changed

+2
-0
lines changed
  • src/main/java/aztech/modern_industrialization/api/energy

1 file changed

+2
-0
lines changed

src/main/java/aztech/modern_industrialization/api/energy/EnergyApi.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ public boolean canConnect(CableTier cableTier) {
206206
@Override
207207
public long receive(long maxReceive, boolean simulate) {
208208
long ratio = ratio();
209+
maxReceive = Math.min(maxReceive, Long.MAX_VALUE / ratio); // avoid overflow
209210
maxReceive *= ratio;
210211
if (ratio > 1) {
211212
// Do a simulate insertion to round down to a multiple of ratio that should be accepted.
@@ -217,6 +218,7 @@ public long receive(long maxReceive, boolean simulate) {
217218
@Override
218219
public long extract(long maxExtract, boolean simulate) {
219220
long ratio = ratio();
221+
maxExtract = Math.min(maxExtract, Long.MAX_VALUE / ratio); // avoid overflow
220222
maxExtract *= ratio;
221223
if (ratio > 1) {
222224
// Do a simulate extraction to round down to a multiple of ratio that should be accepted.

0 commit comments

Comments
 (0)