fix integer overflow resulting in item lose
This commit is contained in:
@@ -95,13 +95,14 @@ public class FluidStorageDisk implements IStorageDisk<FluidStack> {
|
|||||||
|
|
||||||
return StackUtils.copy(otherStack, size - remainingSpace);
|
return StackUtils.copy(otherStack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
|
int maxConsumable = Math.min(size, Integer.MAX_VALUE - otherStack.getAmount());
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
otherStack.grow(size);
|
otherStack.grow(maxConsumable);
|
||||||
|
|
||||||
onChanged();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return FluidStack.EMPTY;
|
return StackUtils.copy(otherStack, size - maxConsumable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -102,14 +102,15 @@ public class ItemStorageDisk implements IStorageDisk<ItemStack> {
|
|||||||
|
|
||||||
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
return ItemHandlerHelper.copyStackWithSize(otherStack, size - remainingSpace);
|
||||||
} else {
|
} else {
|
||||||
|
int maxConsumable = Math.min(size, Integer.MAX_VALUE - otherStack.getCount());
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
otherStack.grow(size);
|
otherStack.grow(maxConsumable);
|
||||||
itemCount += size;
|
itemCount += maxConsumable;
|
||||||
|
|
||||||
onChanged();
|
onChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
return ItemStack.EMPTY;
|
return ItemHandlerHelper.copyStackWithSize(otherStack, size - maxConsumable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user