Skip to content

Incomplete analysis of MCBE redstone system operation (1)

Arie edited this page Jun 19, 2022 · 10 revisions

Opening:

Bedrock Redstone has been around for more than five years. Along with the story's characteristic, it also has many amazing players and works. A highly flawless theoretical system module based on practice and experience has also been established thanks to the efforts of many players. However, the source-level examination of pure theory remains nearly blank. In this column (series), I (hhhxiao) attempt to fill in the gaps, get as much done as possible, and leave the hole open at any time.

One thing to note is that I don't even know how to do, so this column could virtually be said to be from the hands of cloud players, so please keep an eye on it. (wut)

Targeting:

  • Understand the basic functions of the most basic Redstone logic

Classification of redstone originals

Inside the game, the classification of redstone originals is such a tree structure, which is also the basis for the operation of the entire redstone system. See the table for details.

  • BaseCircuitComponent CSSC
  • BaseRailTransporter MCPR
  • ProducerComponent
    • CapacitorComponent CSCA
      • ComparatorCapacitor
      • PulseCapacitor
      • RedstoneTorchCapacitor
  • ConsumerComponent CSCC
    • PistonConsumer
  • PoweredBlockComponent CSPB
  • ProducerComponent CSPC
  • TransporterComponent CSTR

Don't worry if you don't understand the name, just read the following:

  • The producer is the one that sends out signals (such as redstone blocks, levers, etc.), hereinafter referred to as the producer

  • Capacitor is the comparator, the repeater, the torch, and the observer

  • The transporter is the redstone wire (transmitting the signal)

  • Consumer is to receive signals, such as pistons, transmitters, etc..., hereinafter collectively referred to as consumers

  • Rails? What are rails?

Redstone original signal source (Source)

Signal source

Here, we must first give a concept called signal source, which, to put it bluntly, is the original that provides redstone energy to the original. Let's look at an example:

  • The comparator is powered by redstone blocks and torches, so it has two signal sources, the torch on the right and the relic on the left.

  • The energy supplied to the repeater is the comparator, so its source is the middle comparator.

  • Similarly, the signal source of the redstone lamp and the redstone wire to the right of the redstone lamp is the repeater.

Notice

  • Redstone wire will not be used as a signal source, because it can only transmit energy and does not generate redstone power.

  • The producer itself can provide redstone power, so it has no signal source.

Distance

Each element in the game keeps track of its own sources and distances from them. When a redstone original is added or removed, the original will re-search the complete circuit for its own signal source, calculating the distance between itself and the signal source in the process. This distance will be adjusted with the various connection characteristics of the original redstone in the simplest scenario, which is Manhattan distance minus 1. Because these aren't the key points, I won't go into detail about them (and I have not read them carefully). For instance, if we remove the redstone block in the lower right corner, the repeater will only have one signal source - the torch.

Redstone Signal Strength Calculation

The algorithm is actually very simple: First, calculate the signal strength provided by each signal source for itself. To
int power_strength = source::strength() - distance(a, b)
put bluntly, it is to subtract the distance between the signal source and itself from the signal strength of the signal source. Then select the strongest signal from the signal strength provided by all signal sources as your own signal (of course, if this signal is negative, it will take 0). Let's see a simple example:

The redstone line above the green block has two signal sources. The distance between it and the redstone block on the upper left is 3, so the signal strength provided by the redstone block is 12, and the distance from the redstone block on the lower left is 12. 1. The signal strength provided is 15 - 1 = 14. The final signal strength of the redstone line is max(12,14) = 14.

After the appetizers are completed, the slightly hardcore GT-level micro-sequence analysis is followed

Signal update process

Redstone carving

Look at the picture and talk. The picture below shows the operation of the game. A square is 1gt. We call the red gt redstone carvings, and the white ones are temporarily called ordinary carvings. . In such a gt will update the redstone signal. The interval between two redstone ticks is also called redstone tick (rt), which is easy to translate 1rt = 2gt = 0.1s (if only the TPS is 20).

How the signal is updated

There are two ways to update the original:

  • First calculate all the signal values ​​according to the current circuit state and update them together later, temporarily called cache update.

  • Update immediately, the calculated value will be updated immediately

Capacitors (comparators, repeaters, torches) and redstone wires are caches-updated, others such as producers and consumers are updated immediately

What 1rt did

There are not many things to do in the game about the 1rt of redstone. There are three things in total (in order):

  • Calculate the signal of the capacitor and the redstone line according to the current circuit state (that is, the circuit of the previous rt), and how to calculate it is the above algorithm (max (signal value - distance)). Note that because these are cached and updated, the calculated new values ​​are actually stored, and the actual signal of the original is not updated.

  • Calculate and set the signal of the capacitor and the producer, and only update the actual value of the capacitor at this step (the current value = the new value). There is nothing to say to the producer, it is as many as it is. For example, if you pull the lever on 1gt, the value of the lever will be updated to 15 at this time.

  • Update redstone wires and consumer signals. Also for redstone wires (current value = new value), and for consumers the current value is set to max (signal value - distance).

For ease of understanding, here is an example:

  • After pulling down the lever, the lever's signal changes to 15 immediately (this has nothing to do with the redstone system):

  • Then wait until the next redstone tick starts:

  • The only signal source of the two redstone wires and the repeater is the pull rod, and then they calculate the new value according to the pull rod. The new value is cached and not updated)

  • The next action lever signal is still 15 and nothing happens. At this time, the new value of the repeater is synchronized with the old value, and its signal becomes 15 (although the repeater has a delay, the signal is updated immediately)

  • On to the next behavior, the redstone wire synchronizes its old and new values ​​from 0 to 14 and 15; the only source of the green light is 15, and the distance is 1, so its signal goes from 0 to 15-1 = 14 (note this The value has nothing to do with the redstone wire connected to him), the only signal source of the blue light is the repeater, and its distance from the repeater is 0, so the signal update is 15 - 0 = 15

Then this rt is over, wait until the next gt redstone line and both lights are on at the same time (this rendering detail has nothing to do with the redstone system).

? ? ?

You may be wondering why both lights are on at the same time, or you may think that the repeater has a delay and doesn't update the signal immediately. But that's what it is. This phenomenon is determined by the update order and the signal calculation.

Let's do a simple exercise and analyze the signal changes of all the originals after pulling the lower lever:

To be continued in 2.

source by hhhxiao