IMG.BANNERISO 100 f/2.8 1/125s | 50mm Lens WB 5600K | EV +0.3 AF-S RAW
// Some special update ranges
Translation may be out of date
03 Special Update Behaviors
This section introduces special update behaviors of certain blocks.
1 Redstone Dust Update Behavior
1.1 The Concept of 2nd-Order Neighbor Updates
In , we introduced the concept of "update source" for NC updates. The most common block updates, such as those triggered by placing or breaking blocks, use the position of the changed block as the update source and send NC updates in six directions. This is called a "1st-order neighbor update."
Redstone dust behaves differently. For example, when the power level of redstone dust changes, it emits a "2nd-order neighbor update," meaning the redstone dust uses its own position and the six blocks adjacent to it as update sources, each sending NC updates in six directions.
The naming of "1st-order" and "2nd-order" comes from the Manhattan distance of the farthest block receiving an NC update from the block emitting the update. A 1st-order neighbor update means the farthest block receiving an NC update has a Manhattan distance of 1 from the emitting block, while a 2nd-order neighbor update means this distance is 2.
1.2 Update Source Order for Redstone Dust 2nd-Order Neighbor Updates (Locational Nature of Redstone Dust Updates)
When redstone dust emits 2nd-order neighbor updates, the order of the 7 update sources is determined by hash values derived from the redstone dust's coordinates. This is what gives redstone dust updates their locational nature. These update sources have a 97% probability of being divided into three groups (-Y, +Z, +X, O, +Y, -Z, -X), and emit updates in the following order:
Note: In the table, O represents the source redstone dust, -X etc. represent the direction of the update source relative to the source redstone dust
The update order within each group is fixed, but the arrangement order of groups is random. Additionally, there are some other extremely low-probability arrangement options.
ADVANCED
3 Redstone Dust Updates and Code AnalysisADVANCED
First
Then
Last
Probability of This Order
-Y, +Z, +X
O
+Y, -Z, -X
24.267%
+Y, -Z, -X
O
-Y, +Z, +X
24.267%
O
-Y, +Z, +X
+Y, -Z, -X
12.133%
O
+Y, -Z, -X
-Y, +Z, +X
12.133%
-Y, +Z, +X
+Y, -Z, -X
O
12.133%
+Y, -Z, -X
-Y, +Z, +X
O
12.133%
ADVANCED
2 Update Behavior of Diagonal RailsADVANCED
2.1 Overview
When the activation state (powered=true|false) of a diagonally placed powered rail (PoweredRailBlock) changes, it emits two groups of updates in the following order:
First group: Sequentially emit NC updates with the block above, itself, and the block below as update sources.
Second group: Sequentially emit NC updates with itself, the block below, and the block above as update sources.
4 Recursive Checking Behavior of Rail ChainsADVANCED
4.1 Overview
When a rail receives an NC update, it checks its own powered state. It sets itself to powered=true when either of the following two conditions is met:
Directly receiving a redstone signal, i.e., being directly powered
Being powered by connected rails, i.e., being indirectly powered
A rail checking whether it is indirectly powered does not simply check if connected rails are powered. Instead, it recursively searches the entire rail chain for directly powered rails within 8 rails of itself (considering the distance between two directly connected rails as 1 rail). The process is as follows:
Initially, the distance variable is 0. If distance=8, the check terminates and returns False, meaning not indirectly powered.
A rail has two directions. When checking begins, which direction the rail checks first is controlled by a boolean value. When the boolean is True and the rail shape is north-south/east-west oriented, it checks the south/west side rail; when the rail shape is ascending shape=ascending_*, it checks the rail above on the south/west side. When the boolean is , the opposite occurs. This boolean value is first , then when checking begins. Due to short-circuit evaluation: if the first check with boolean succeeds, the second check with boolean will not be performed. During the recursive checking process , this boolean value does not change.
ADVANCED
5 Lit Observer Placement Without Neighbor NC UpdatesADVANCED
When a piston pushes a lit observer into position and there is no observer scheduled tick at the destination position, it will not emit the conventional NC update triggered by piston movement to neighboring blocks (except the block pointed to by the output face) (referring to the NC update triggered by setBlockState with flags=3 that normally occurs after a piston pushes a regular block into position). The principle is as follows:
Placement has two cases:
Normal placement: Calls PistonBlockEntity.tick, which calls setBlockState with flags=67
Forced placement: Calls PistonBlockEntity.finish, which calls setBlockState with flags=3
In setBlockState, calls worldChunk.setBlockState, then calls
Move coordinates (i, j, k) to the position of the next rail to check.
Determine whether the current rail could possibly connect with a rail below in the current checking direction. If the current rail is ascending east/west/south/north and the checking direction is east/west/south/north, it is considered impossible. This step prepares for step 8. For example: if the current rail is ascending north, and checking toward the south, then this rail could connect with a rail below on the south side; if the current rail is ascending north and checking toward the north, then this rail cannot connect with a rail below on the south side.
If the current rail shape is ascending south/north or ascending east/west, consider the current rail shape as north-south oriented or east-west oriented—this shape change prepares for the next step (6.b.).
Check coordinates (i, j, k):
Check if the current position is a rail. If not, return False and end the current step check.
Check if the current position is connected to the original rail. This step does not check "connected," but rather checks "not connected": if the original rail shape is east-west oriented, and the current rail shape is north-south/ascending north/ascending south, they are not connected, return False, and end step 6 check. If the original rail is north-south oriented, and the current rail shape is east-west/ascending east/ascending west, they are not connected, return False, and end the current step check.
Steps i and ii are actually preconditions for iii and iv. This step checks if the rail at the current position is directly powered. If so, return True and end the current step check.
Jump to step 1, increase distance by 1, and check the next rail according to the starting boolean value (recursion).
If step 6 returns True, terminate the check and return True.
(See step 4 judgment) If the current rail could possibly connect with a rail below in the current checking direction, check the block below coordinates (i, j, k), i.e., jump to step 6, but check coordinates (i, j-1, k). In the example from step 4, if step 3 returns False, then check the rail below on the south side of the original rail.
4.2 Source Code Analysis
java
127 LINES||
// SYNTAX_HIGHLIGHT
// IMG_LOAD
A flat rail may be considered connected to a diagonal rail that appears unconnected. With the same structure, if a redstone block directly powers the flat rail, the diagonal rail will not be powered
onBlockAdded
In ObserverBlock.onBlockAdded:
Checks if the old block at the current position is an observer. Since the old block is b36, judgment is true, proceed to next step
Checks if itself is activated and there is no observer scheduled tick at the current position. Since itself is lit powered=true and there is no observer scheduled tick at the current position, judgment is true, proceed to next step
setBlockState with flags=18, changes its activation state from powered=true -> powered=false, and emits PP update
Emits conventional observer NC updates, i.e., emits NC updates to the block pointed to by the output face and neighboring blocks of the pointed block
Since in step 3.iii, the observer's powered property changed, step 1's setBlockState continues, but because blockState2 == state (i.e., whether the state changed) is false, setBlockState no longer emits conventional NC updates and ends directly
Manhattan distance is the sum of distances along each coordinate axis. In Minecraft's three-dimensional space: d=|x|+|y|+|z|
Short-circuit evaluation is a "circuit breaker" mechanism when computers evaluate logical expressions. For example, in A and B, if A is false, the logical judgment short-circuits, returns False, and no longer judges whether B is true; in A or B, if A is true, the logical judgment short-circuits, returns True, and no longer judges whether B is true.