fix integer overflow resulting in item lose

This commit is contained in:
MelanX
2022-04-11 20:33:16 +02:00
committed by Raoul
parent bdb51e0d21
commit c66a17452c
2 changed files with 7 additions and 5 deletions

View File

@@ -95,13 +95,14 @@ public class FluidStorageDisk implements IStorageDisk<FluidStack> {
return StackUtils.copy(otherStack, size - remainingSpace);
} else {
int maxConsumable = Math.min(size, Integer.MAX_VALUE - otherStack.getAmount());
if (action == Action.PERFORM) {
otherStack.grow(size);
otherStack.grow(maxConsumable);
onChanged();
}
return FluidStack.EMPTY;
return StackUtils.copy(otherStack, size - maxConsumable);
}
}
}

View File

@@ -102,14 +102,15 @@ public class ItemStorageDisk implements IStorageDisk<ItemStack> {
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
} else {
int maxConsumable = Math.min(size, Integer.MAX_VALUE - otherStack.getCount());
if (action == Action.PERFORM) {
otherStack.grow(size);
itemCount += size;
otherStack.grow(maxConsumable);
itemCount += maxConsumable;
onChanged();
}
return ItemStack.EMPTY;
return ItemHandlerHelper.copyStackWithSize(otherStack, size - maxConsumable);
}
}
}