Allow zero-tick recipes to apply immediately #1272
Merged
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.
Summary
This PR allows a recipe's effects to be applied within the same tick if
time: 0
is specified for the recipe.The previous behavior was that if the
time
of the recipe was zero, it would nonetheless behave the same astime: 1
, and the entity updates would not be applied until the next tick.This new behavior is useful when "abusing" the
drill
command to emulate various other games via help from a system robot.Motivation
For the "Lights Out" game (#1273) I have implemented a system robot that
instant
-ly toggles the four adjacent lights and the center light when a center light isdrill
-ed by the player. The light entities are named"off"
and"on"
.I did some experiments to see if the system robot would react "fast enough" if the player drilled quickly in succession.
Experiments
The 5x5 light grid is initially
"off"
. I moved the player robot to the center of the grid, facingeast
. From this position, I tried three command sequence variations both before and after this PR. The recipes for toggling lights specifytime: 0
.Before this PR
1. Drilling twice in succession
This resulted in an error:
so only the first
drill
got applied:This is because I believe the sequence of events was:
drill
command, queue entity modificationdrill
is applied. Execute seconddrill
command, queue second entity modificationsdrill
command. Throw an error because the system robot has toggled the drill's target entity toon
whereas thedrill
was initially executed when it was stilloff
.2. Instant for both drills
In this case, both of the player's
drill
commands were executed, but the system robot then failed to doubly-invert one of the cells:This is due to some kind of race condition in the system robot's logic. However, it is irrelevant because the
instant
command shall not be available to the player.3. Instant for first drill only, then second drill
This accomplished what approach number 1 was supposed to; both drill commands were applied and the two overlapping cells got properly inverted:
Explanation: In this case, the entire drilling operation (including applying all effects to entities on the ground) was completed within the player's first tick, so the system robot updated the lights appropriately on its turn. Then, in the next tick the player robot applied another drill command, and again the system robot appropriately did another inversion on the two overlapping middle cells.
After this PR
1. Drilling twice in succession
Now works as expected:
2. and 3.
Behaved identically to before the PR.