Multiblock regression and bug fixes, new Jammed state #6
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.
Regression
After merging #2, a regression in behavior occurred where structures would void crafts when broken unlike before where the craft would only void if the controller was broken. This feature branch restores the prior behavior.
Voiding Bug
While working on it I discovered a related issue where multiblocks were recording all possible recipe outputs rather than truncated outputs determined during recipe setup, and if there was insufficient space to merge all outputs then all outputs would silently void instead of the excess outputs. This has been corrected.
Jammed State
As a contingency against undefined behavior when a machine is broken and reformed with a configuration that cannot handle the running recipe, that machine will become Jammed. In this state, recipe progress will be frozen, no additional power will be drawn, the multiblock controller's GUI will indicate the machine is Jammed, and the craft will not progress or complete until the player rectifies the configuration issue.
For example, if recipe outputs are computed with an LV output bus resulting in more than one output, then the structure is broken and the bus is replaced with a ULV bus, the machine would Jam until the structure is rebuilt with enough output space for all outputs.
The Jammed state logic also calls
RecipeMapMultiblockController::checkRecipe()
to allow for polymorphic behaviors unique to specific multiblocks. For example an EBF will become Jammed if the coils were replaced with different ones of an insufficient tier for the recipe (e.g replacing Kanthal coils with Cupronickel).Shared Parts Considerations
Shared multiblock parts risk a race condition where another multiblock completes its craft, obstructing the outputs for other machines. If there is insufficient space for all outputs when a machine tries to complete the craft, the merge will fail and all outputs of that type would be voided.
To prevent this from happening,
MultiblockRecipeLogic
will verify all recipe conditions are satisfied before allowing the craft to complete. If validation fails, the machine will become Jammed. Validation will be performed each time the structure is invalidated and reformed, or the outputs notify the controller of state change. Once validation succeeds, the machine will stop being Jammed and the recipe will complete.