Let insert pre-consumers see what part of an insertion was already accounted for - #1720
Open
rubensworks wants to merge 1 commit into
Open
Let insert pre-consumers see what part of an insertion was already accounted for#1720rubensworks wants to merge 1 commit into
rubensworks wants to merge 1 commit into
Conversation
…counted for All insert pre-consumers of an ingredient channel observe the same insertion, chained by the remaining instance. A pre-consumer that attributes part of an insertion to itself without consuming it, such as one that waits for an ingredient to be produced, therefore left the instance unchanged, after which the next pre-consumer attributed that very same instance to itself as well. Integrated Crafting's crafting job output observer works exactly like that, so with several crafting interfaces running parallel jobs for the same output, one produced item resolved the pending output of every one of those jobs at once. IIngredientChannelInsertPreConsumer now takes and returns the unaccounted part of the insertion next to the remaining part, and applyAll chains both. The single-instance method is deprecated, and its default keeps the old behaviour for pre-consumers that have not migrated yet. INetworkIngredientsChannel additionally accepts an insertion that was already partially accounted for before it reached the channel, which is needed when a crafting interface first offers its own results to its own jobs. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EypmxuPjaJ4cFGh2DvZYbf
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.
Companion of CyclopsMC/IntegratedCrafting#226, which needs this to fix parallel crafting jobs all completing on a single produced output. This PR is the API half; on its own it changes no behaviour.
Problem
Every insert pre-consumer registered on an ingredient channel observes the same insertion, chained by the remaining instance:
That works for a pre-consumer that consumes part of the insertion, since what it takes is gone from the instance it passes on. It does not work for one that attributes part of the insertion to itself without consuming it, because the instance it passes on is unchanged, so the next pre-consumer attributes that very same instance to itself as well.
Integrated Crafting's crafting job output observer is exactly the second kind: it resolves a job's pending output when the produced ingredient shows up, and then still lets it flow into storage. With several crafting interfaces running parallel jobs for the same output, one produced item resolved the pending output of every one of those jobs at once.
Change
IIngredientChannelInsertPreConsumernow also carries the unaccounted part of an insertion, next to the remaining part:insert(channel, ingredient, unaccounted, simulate)returns aResult(remaining, unaccounted). Consuming reduces both, attributing reduces only the unaccounted part.insert(channel, ingredient, simulate)is deprecated. Its default keeps the old behaviour for pre-consumers that have not migrated, andapplyAllclamps the unaccounted part to the remaining part so such a pre-consumer can not cause over-accounting.applyAllholds the chaining that was duplicated inIngredientChannelAdapterandIngredientChannelAdapterWrapperSlotted.INetworkIngredientsChanneladditionally accepts an insertion that was already partially accounted for before it reached the channel (insert(ingredient, unaccounted, simulate), defaulting to the plain insert). Integrated Crafting needs this because a crafting interface offers its results to its own jobs before flushing them into the network, and those results must not be accounted for a second time by the channel's pre-consumers.Testing
TestIngredientChannelInsertPreConsumercovers the chaining: two attributing pre-consumers no longer share one instance, they do split a larger one, a consumed quantity can not be attributed again, and a deprecated pre-consumer can not push the unaccounted quantity above the remaining quantity../gradlew buildpasses../gradlew runGameTestServerpasses, all 942 tests.🤖 Generated with Claude Code
https://claude.ai/code/session_01EypmxuPjaJ4cFGh2DvZYbf
Generated by Claude Code