Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-120938

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

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.12.1, Minecraft 1.12.2 Pre-Release 1, Minecraft 1.12.2 Pre-Release 2, Minecraft 1.12.2, Minecraft 17w43a, Minecraft 17w43b, Minecraft 17w45b, Minecraft 17w46a, Minecraft 17w47a, Minecraft 17w47b, Minecraft 18w03b, Minecraft 1.13-pre3, Minecraft 1.13-pre6, Minecraft 1.13-pre7, Minecraft 1.13.1, Minecraft 1.13.2, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 18w50a, 1.14.4, 1.16.1, 20w28a, 1.16.4, 20w48a, 1.17.1
    • None
    • Confirmed
    • Redstone

      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:

      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:

      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);
          }
      }
      

        1. burned-out-not-turning-on.png
          78 kB
          [Mod] NeunEinser
        2. burned-out-turning-on.png
          82 kB
          [Mod] NeunEinser

            Unassigned Unassigned
            Schortan [Mod] NeunEinser
            Votes:
            9 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              CHK: