Minecraft Redstone – What’s Happening When a BUD Switch Activates?

minecraft-java-editionminecraft-redstone

I understand completely what a BUD switch is and what purpose it serves. But what within the game is happening when a BUD switch works? What allows it to work and what is the game thinking?

Best Answer

Here is a more detailed explanation (it is still a bit simplified though):

Block updates theory and examples

The Minecraft world changes constantly and the game needs to constantly calculate the new state of the world. This happens 20 times per second and is called a tick. In most game ticks there are quite a few entity changes - mobs movement and behavior, projectiles and dropped items movement, etc.

In the game code, each block has certain behavior associated with it - doors open or close, pistons move, water flows, etc. The game needs to execute this behavior to calculate the new state of blocks. In typical settings there are tens of millions of blocks around the player, but block changes are relatively rare. In a single tick there are hardly any block changes. That is why it doesn't make sense to execute (calculate) the behavior for all the blocks all the time, but instead it is much more reasonable to do it only for changed blocks. This means that the game needs to track which blocks are changing.

Fortunately keeping track of changes is easy - changes are typically transfered from one block to its neighbors. So if one block changes - for example when player places block or flips a lever, all six adjacent blocks are scheduled for update. When their change is calculated, they in turn schedule all their adjacent blocks for update etc. The process stops if a 'passive' block is reached, like air or most solid blocks.

reed

For example, consider what happens if the player breaks the bottom of grown reed: the block is removed (replaced by air) and a reed item is created in its place. It then notifies all adjacent six blocks to update themselves. The middle reed 'realizes' it is not supported and deletes itself and creates a second reed item. The adjacent water 'realizes' it can flow in the free space where the bottom reed was and places flowing water there. Finally the top reed updates, scheduled by the second reed - it 'realizes' it is not supported and deletes itself and creates a third reed item. The rest of the adjacent blocks are air or ground, and they don't change, so they don't notify any more adjacent blocks to update themselves.

lamp

When a redstone lamp is scheduled for update, it checks any of the surrounding blocks are powered and lights up (or turns off if not). When the player places a redstone block next to it, the redstone block schedules updates for all adjacent blocks including the lamp. The lamp then 'realizes' it is powered and lights up.

power line

This is also how redstone signal 'travels' - each redstone dust piece notifies adjacent blocks and adjacent dust pieces update their power level and notify the adjacent blocks etc.

How BUD works

When a piston is scheduled for update, it checks if any of the adjacent blocks are powered. However for some reason, it also checks if any of the adjacent blocks of the block above it are powered. In a picture, it checks if any of the glass blocks are powered:

piston power

This is why it is possible to build this simple non-resettable BUD:

bud

When you place the redstone block, it notifies the grass below and the air around it to update, and they do nothing. The redstone block does not notify the piston to update, because it is not adjacent to the redstone block, so the piston stays retracted. If after that the piston receives any notification for update in some other way (for example placed block next to piston or crop growing next to piston), the piston will 'realize' it is powered (because it will check the place diagonally above where the redstone block is) and it will extend.

Droppers and dispensers have the same weird pattern of checking if they are powered, so they can be used as BUDs as well.

More block updates theory

Usually block updates are triggered by some player or mob action, but there is also another source of updates - the game schedules a special kind of update (different from normal update) for randomly chosen blocks each tick. Some blocks react to these random updates - for example crops can decide to grow on this random update. If they decide to grow, they then schedule regular updates to their adjacent blocks. Another example is water can choose to turn into ice if it is in a cold biome or high above the ground.