Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Yesterday a player on MetaMechanists reported their grid showing their cobblestone in the negative billions, indicating the display had overflown (not the actual amount as they could still withdraw items), so today I worked on fixing the bug.
First I re-did the
NetworkRoot#getAllNetworkItems
method to use NumberUtils#flowSafeAddition instead of the manual method using longs being used, also just cleaning up the method by usingMap#compute
, when that didn't fix it (which I didn't expect it to but did it regardless) I did a little more debugging and found the problem was actually that theBarrelIdentity#getAmount
had already overflowed, so I tracked it down to be theNetworkRoot#getNetworkStorage
andNetworkRoot#getInfinityBarrel
methods, both add the stored amount and the amount in the output slot, so if either have a stored amount of integer max when you add the output amount it overflows. After finding that out I just made it use flow safe addition and also moved around a couple of guard statements to avoid unnecessary logic. Afterwards I noticed that in a lot of places there was a call to StackUtils#getAsQuantity(itemStack, 1) and in some spots there was just a replication of that logic (itemStack.clone(), clone.setAmount(1), so I added a method overload,StackUtils#getAsOne
and replaced the usages and logic replications with it.After testing in game with a infinite quantum storage and a 4k quantum storage both full with cobble completely and inputs and output slots filled, before these changes it overflows, after these changes it does not 👍