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 #01, 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 distance1 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.
2 Update Behavior of Diagonal Rails
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.
2.2 Source Code Analysis
2.2.1 Call Stack
2.2.2 Source Code Explanation
3 Redstone Dust Updates and Code Analysis
4 Recursive Checking Behavior of Rail Chains
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. Ifdistance=8, the check terminates and returnsFalse, 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
Trueand the rail shape is north-south/east-west oriented, it checks the south/west side rail; when the rail shape is ascendingshape=ascending_*, it checks the rail above on the south/west side. When the boolean isFalse, the opposite occurs. This boolean value is firstTrue, thenFalsewhen checking begins. Due to short-circuit evaluation2: if the first check with booleanTruesucceeds, the second check with booleanFalsewill not be performed. During the recursive checking process (see step 6), this boolean value does not change. - 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
Falseand 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, returnFalse, 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
Trueand 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).
- Check if the current position is a rail. If not, return
- If step 6 returns
True, terminate the check and returnTrue. - (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 returnsFalse, then check the rail below on the south side of the original rail.
4.2 Source Code Analysis
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
5 Lit Observer Placement Without Neighbor NC Updates
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 callssetBlockStatewithflags=67 - Forced placement: Calls
PistonBlockEntity.finish, which callssetBlockStatewithflags=3
- Normal placement: Calls
- In
setBlockState, callsworldChunk.setBlockState, then callsonBlockAdded - 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=trueand there is no observer scheduled tick at the current position, judgment istrue, proceed to next step setBlockStatewithflags=18, changes its activation state frompowered=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
- Checks if the old block at the current position is an observer. Since the old block is b36, judgment is
- Since in step 3.iii, the observer's
poweredproperty changed, step 1'ssetBlockStatecontinues, but becauseblockState2 == state(i.e., whether the state changed) isfalse,setBlockStateno longer emits conventional NC updates and ends directly
Call stack:
Footnotes
-
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, returnsFalse, and no longer judges whether B is true; inA or B, if A is true, the logical judgment short-circuits, returnsTrue, and no longer judges whether B is true. ↩





