Skip zero-amount ingredients when computing parallel ratio - #5347
Open
winli84354 wants to merge 1 commit into
Open
Skip zero-amount ingredients when computing parallel ratio#5347winli84354 wants to merge 1 commit into
winli84354 wants to merge 1 commit into
Conversation
getMaxParallelRatio divides by each ingredient's required amount to work out how many parallel runs an inventory can sustain. Nothing filtered out ingredients whose amount is zero, so such an ingredient became a zero divisor and killed the machine tick with ArithmeticException. An ingredient that requires nothing cannot constrain the parallel count, so keep it out of the consumables map rather than special-casing the division. This also matches the existing IntCircuitIngredient skip. Applies to both capabilities: the report is on the fluid path, but ItemRecipeCapability has the identical division and SizedIngredient#getAmount can equally return zero. Fixes GregTechCEu#5289 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Fixes #5289.
getMaxParallelRatiodivides by each ingredient's required amount to work out how manyparallel runs an inventory can sustain. Nothing filters out ingredients whose amount is
zero, so a recipe carrying a zero-amount input makes the divisor zero and the machine tick
dies with
ArithmeticException: / by zero.GTCEu does not generate zero-amount inputs itself, but nothing rejects them either — the
reporter hit this through
OillessGTemitting a recipe with a zero-amount fluid input.Implementation Details
The divisor comes from the
consumablesmap built at the top ofgetMaxParallelRatio:I skip these ingredients while the map is being built rather than guarding the division.
An ingredient that requires nothing cannot constrain the parallel count, so keeping it out
of the map is the statement of intent; special-casing it at the division would only
re-derive the same fact further away from the cause. It also matches the
IntCircuitIngredientskip a few lines above inItemRecipeCapability.Both capabilities are changed. The issue only reports the fluid path, but
ItemRecipeCapabilityhas the identical division andSizedIngredient#getAmountcanequally return 0, so fixing only fluids would leave the same crash reachable through items.
Zero-amount non-consumables (
chance() == 0) are skipped as well. That is a no-op inbehaviour — the satisfaction loop below only fails when
needed > 0— but it keeps bothbranches consistent.
AI Usage
Agent Used
Claude Code (Claude Fable 5)
Agent Usage Description
The agent read
getMaxParallelRatioin both capabilities to confirm the reporter'sdiagnosis, noticed that
ItemRecipeCapabilitycarries the same defect (which the issuedoes not mention), and wrote the two guards and their comments. I reviewed the diff line by
line against the surrounding code, checked the non-consumable reasoning myself, and
verified the build locally.
Outcome
Fixes: #5289
Machines no longer crash when a recipe contains a zero-amount item or fluid input. Such
inputs are ignored for parallel calculation, which is what they already mean semantically.
How Was This Tested
compileJavaandspotlessJavaCheckboth pass locally.neededoriginates fromaddTo(ing, amount)withamountunfiltered, and reachesavailable / neededunchecked. The guard removes theonly route by which a zero can enter that map.
needed == 0the satisfaction loopcomputes
lesser = min(0, count) = 0, leavesneededat 0, and theneeded > 0testnever fires — so skipping those is behaviour-preserving, not just crash-avoiding.
I could not reproduce the original
OillessGTrecipe in-game, so this is not an in-gameverified fix. If a maintainer prefers a regression test over the reasoning above, say so
and I will add one.
Potential Compatibility Issues
None. No API, recipe, item, block, material, or machine changes. The only behavioural
difference is that a zero-amount input no longer participates in the parallel calculation —
previously it crashed, so no existing working setup can depend on the old behaviour.