mojira.dev
MC-120938

Burned-out redstone torch has inconsistent behavior for turning on again

The bug

When a redstone torch burns out because of a redstone dust that both powers the redstone torch and gets powered by it, the redstone torch will stay turned off forever until it receives a block update.

Example for a setup:

[media]

However, if the redstone torch burns out by powering itself with a short delay, it will turn on without any update after 8 seconds or 160 game ticks.

Example setup:

[media]

Code analysis

Fabric 1.14.4 build 12 names.

This happens, because the redstone torch gets set with the changed state before the update is scheduled. in onBlockAdded, the redstone torch updates other blocks that receive power from it.
If that action updates redstone wire, so that the torch, in turn, receives an update, this will cause the torch to schedule an update with the usual 2 tick delay. This makes it impossible to schedule the 2nd tick.

An easy fix is to simply move setBlockState after the tick is scheduled.

public static void update(final BlockState state, final World world, final BlockPos pos, final Random rand, final boolean unpower) {
    final List<BurnoutEntry> burnedOutTorches = RedstoneTorchBlock.BURNOUT_MAP.get(world);
    //remove torches that were burned out for more than 60 ticks.
    while (burnedOutTorches  != null && !burnedOutTorches .isEmpty() && world.getTime() - burnedOutTorches .get(0).time > 60L) {
        burnedOutTorches .remove(0);
    }

    if (state.get(RedstoneTorchBlock.LIT)) {
        if (unpower) {
            //don't change the state here
            //world.setBlockState(pos, state.with(RedstoneTorchBlock.LIT, false), 0b11);

            if (isBurnedOut(world, pos, true)) {
                world.playLevelEvent(1502, pos, 0);
                //schedule tick
                world.getBlockTickScheduler().schedule(pos, world.getBlockState(pos).getBlock(), 160);
            }
            //change the state here instead
            world.setBlockState(pos, state.with(LIT, false), 0b11);
        }
    }

    else if (!unpower && !isBurnedOut(world, pos, false)) {
        world.setBlockState(pos, (state).with(RedstoneTorchBlock.LIT, true), 0b11);
    }
}

Linked issues

Attachments

Comments 4

Can confirm for 18w50a

Can confirm in 20w48a.

Can confirm in 1.17.1.

NeunEinser

(Unassigned)

Confirmed

Redstone

Minecraft 1.12.1, Minecraft 1.12.2 Pre-Release 1, Minecraft 1.12.2 Pre-Release 2, Minecraft 1.12.2, Minecraft 17w43a, ..., 20w28a, 1.16.4, 20w48a, 1.17.1, 24w39a

Retrieved