mojira.dev
MC-957

Powered rails do not update when additional power sources are added or removed

The bug

Powered rails do not update when additional power sources are added or removed.

How to reproduce

  1. Build the setup as shown in the attachment below (

[media]
  1. )

  2. Place a redstone block on top of the diamond block

  3. Take note of how many powered rails are activated

  4. Place a redstone block on top of the emerald block

  5. Once again, take note of how many powered rails are activated

  6. Take note as to whether or not powered rails update when additional power sources are added or removed
    → ❌ Powered rails do not update when additional power sources are added or removed

Expected behavior

Powered rails would update when additional power sources are added or removed.

Code analysis

Code analysis by @unknown can be found in this comment.

Related issues

MC-10947 Odd Powered Rail behavior with Redstone Blocks and torches MC-49318 Rails powered by redstone don't update when you break torches MC-60708 Redstone torch and powered rails MC-65748 Powered Rail "power level" does not propagate properly MC-68447 Powered rails will not extend their distance correctly when redstone updates. MC-75801 Powered rail not updating by torch when powered MC-76665 Powered Rails not Deactivating MC-103976 Minecart tracks powering MC-183176 Powered rails not transmiting redstone signal once powered MC-208256 Powered rail power-level does not update MC-233149 Powered rails not updating when a redstone block is placed next to an already powered Powered rail MC-239800 powered rail work without redstone MC-263385 Powered Rails don't update MC-275518 Rail not updated by redstone MC-275932 powered rails dont update properly

Attachments

Comments

migrated
[media][media][media][media][media][media][media][media][media]
migrated

<Comment removed by MOD>

migrated

I'm spanish don't insult me man

migrated

Recreated in 1.4.2, moving the torch doesn't update the rails, normally only 8 rails are powered either side of the torch but with this bug I managed to get 16 rails powered one side of the torch this is because the rails don't update from their powered state once the torch is moved.

migrated

As you can see from the screenshot, more rails are powered one side of the torch than should be powered due to this bug.

kumasasa

Confirmed for 12w49a

migrated

This is still and issue in 1.4.7 and in Snapshot 13w02b
In 13w02b this effects the Activator Rail and Powered Rail in the same way.

The powered rail update changes slightly depending on the power source type(torch or leaver).
Please look at the screen shot attached named 13w02b Powered Rail Bug
From left to right:

  • The first leaver was turned on. Then the second leaver. No power was given to the rail to the north of the second leaver.
    Only when the first unpowered piece of track to the north has a block update will the track get powered.

  • When torches are used as the source(at the same position), the tracks are then powered.

  • When torches are used again, but placed at a different position it has the similar effect as the leavers.

migrated

Still happens in 13w05b

migrated

This affects 13w09b. Activator rails are affected as well.

migrated

Still in 13w10a. Redstone Blocks behave like the levers do in Nic's comment.

migrated

still in 1.6.1 pre

Ezekiel

Is this still a concern in the latest Minecraft version 14w03b? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

migrated

This is still valid indeed.

migrated

Still present in 08a

migrated

I believe this bug has been present since powered rails were added. I've tested it back to 1.0 but not in beta 1.5 because of no creative mode back then. I'm surprised such an old bug hasn't been fixed lol.

migrated

Confirmed in 14w11b.

migrated

This is not a bug! You see, when you put redstone current (e.g, lever or redstone torch etc.) down it is carried through the rails. Thus, if you destroyed another redstone current, the other redstone current would be carried on.

Torabi

A redstone torch can normally only power a rail up to 9 blocks away, which makes a total of 17 rails in a row, if the torch is placed next to them. The bug here is that in some cases, redstone torches placed or removed next to an active powered rail are not updating the rails, meaning that some rails do not go inactive, while others do not become active. This means that a single torch can be made to power extremely long (perhaps infinite) sections of powered rail, if the torches are added and removed in the right places, and the right order.

Placing or removing a torch only seems to update the rails if it is placed next to the last active powered rail in a row that is correctly powered by another torch. If it is the only torch within range, then the rails will be updated correctly.

migrated

Still not fixed as of 14w27b

This can be exploited by mapmakers to create enormous self-powered tracks with but a pair of torches.

migrated

Still reproduceable in 14w32d!

migrated

Confirmed in 1.8-pre 3.

migrated

Confirmed in 1.8.6

[Mod] Neko

Confirmed 15w31c

migrated

Confirmed for 15w44b

migrated

Confirmed for 1.8.9 and 15w51b.

migrated

Confirmed for 16w03a.

migrated

Confirmed for 1.9-pre1

migrated

Confirmed for 1.9-pre3

FaRo1

Confirmed for 1.10.
Should be easy to fix by adding power levels like in redstone.

migrated

Confirmed for 1.10.1.

migrated

Confirmed for 1.10.2.

migrated

Confirmed for 1.12.1

NeunEinser

Can confirm for 17w43a/b

migrated

Bug still present in 18w03b

migrated

You could fix that adding a redstone torch near the non-activated rail. It worked for me.

 

 

NeunEinser

Can confirm for 1.13-pre3

migrated

Confirmed for MC 1.13-pre4too.

migrated

Confirmed in 1.13-pre7.

migrated

Confirmed for 1.13-pre8.

migrated

Confirmed for 1.13-pre9.

migrated

Confirmed for 1.13-pre10.

migrated

Confirmed for 1.13.

migrated

Confirmed for 18w30a.

migrated

Confirmed for 18w30b.

migrated

Confirmed for 18w31a.

migrated

Confirmed for 18w32a.

migrated

Confirmed for 18w33a.

migrated

Confirmed for the last snapshots (1.13.1-pre1, pre-2) and 1.13.1.

migrated

Confirmed for 1.13.2-pre1.

migrated

Confirmed for 1.13.2-pre2.

Jack McKalling

Confirmed for 18w48a

Jack McKalling

Confirmed for 18w48b

Jack McKalling

Confirmed for 18w49a

Jack McKalling

Confirmed for 18w50a

Jack McKalling

Confirmed for 19w02a

Jack McKalling

Confirmed for 19w03a

Jack McKalling

Confirmed for 19w03b

Jack McKalling

Confirmed for 19w03c

Jack McKalling

Comfirmed for 19w04a

Jack McKalling

Confirmed for 19w04b and 19w05a

Jack McKalling

Confirmed for 19w06a

Jack McKalling

Confirmed for 19w07a

Jack McKalling

Confirmed for 19w09a

Jack McKalling

Confirmed for 19w11a

Jack McKalling

Confirmed for 19w11b

Jack McKalling

Confirmed for 19w12a

Jack McKalling

Confirmed for 19w12b

Jack McKalling

Confirmed for 19w13a

Jack McKalling

Confirmed for 19w13b

Jack McKalling

Confirmed for 19w14a

Jack McKalling

Confirmed for 19w14b

Jack McKalling

Confirmed for 1.14 pre-1

ZeNico13

Still in 1.14 Pre-Release 2

Jack McKalling

Confirmed for 1.14 pre-3

Jack McKalling

Confirmed for 1.14 pre-4

Jack McKalling

Confirmed for 1.14 pre-5

ZeNico13

Still in 1.14 Release

migrated

Confirmed for 1.14 Release

Jack McKalling

Confirmed for 1.14.1 pre-1

Jack McKalling

Confirmed for 1.14.1 pre-2

Jack McKalling

Confirmed for 1.14.1

ZeNico13

Can also confirm for 1.14.1 Release

ZeNico13

Still in 1.14.2 Pre-Release 1 and 1.14.2 Pre-Release 2

migrated

Glad someone reported this, I thought I was going crazy (built a string farm from Pixlriffs but the minecart keeps stopping on a powered rail). Still an issue in 1.14.2 pre-release 4. 

migrated

Still in snapshot 20w17a

T3sT3ro

and 20w18a

numeritos

Affects 1.16 pre2

migrated

Confirmed in 1.16-pre5.

migrated

Confirmed in 1.16-pre6.

pulpetti

affects 20w27a

migrated

confirmed for 20w45a

migrated

cofirmed in 1.4.1

FaRo1

Only the latest release and the latest snapshot are useful. And that version is already in the list.

migrated

Confimed on 1.16.4

 

migrated

Also affects Activator Rails.

migrated

There is an easy workaround, just break the rail, add the source and it works.

Avoma

I am able to confirm this behavior in 21w39a. Here are some extra details regarding this problem.

The Bug:

Powered rails do not update when additional power sources are added or removed.

Steps to Reproduce:

  • Build the setup as shown in the attachment below.

[media]
  • Place a redstone block on top of the diamond block.

  • Take note of how many powered rails are activated.

  • Place a redstone block on top of the emerald block.

  • Once again, take note of how many powered rails are activated.

Observed Behavior:

Powered rails do not update when additional power sources are added or removed.

Expected Behavior:

Powered rails would be updated when additional power sources are added or removed.

PiTheGuy

Can confirm in Release 1.17.1

Arisa Bot

An attachment with a disallowed file extension has been removed from this ticket.

Executable files and documents are not allowed as attachments.
Please attach crash reports, log files and screenshots as they are instead of pasting them into a document.
-- I am a bot. This action was performed automatically! If you think it was incorrect, please notify us on Discord or Reddit

Brain81505

Can confirm in 23w03a

Brain81505

Can confirm in 23w04a

Brain81505

Can confirm in 23w06a

ISRosillo14

Hey Avoma! Though this is not a code analysis, it is a possible fix for this bug, I hope this will help Mojang fix it.

Cause

Powered rails try to check and update when a neighbour change happens, that is okay. The problem is that if you set a redstone power source next to an already powered "on" rail, neighbors will not update because there are no block state changes (powered=true is equal to powered=true). A possible way to fix this is by making the powered block state depend on a power number state, so every time a redstone signal changes every rail will update neighbour rails up until they're far enough from source.

Workaround

A few months ago I was messing with PoweredRailBlock.java to make curved powered rails, and I noticed how unsafe are methods findPoweredRailSignal(Level,BlockPos,BlockState,boolean,int) and isSameRailWithPower(Level,BlockPos,boolean,int,RailShape).

Basically what I did was remove the proximity variable (the int param of this method that increases every time it checks a further rail) and make powered rails use a new "power" block state that goes from 0 to 9 (0 equals to unpowered, 9 is fully powered). Then, changed findPoweredRailSignal again to only check directly connected powered rails (and not all 8) and isSameRailWithPower to only check the given's rail "power" state (previously it did check if that rail had a redstone source or else check for a further away neighbour block). Also, the two methods mentioned above will now return power state (int) instead of powered state (boolean).

In other words, the new behaviour will make findPoweredRailSignal and isSameRailWithPower get their direct adjacent's power. End result of these two methods:

 

public class PoweredRailBlock extends BaseRailBlock {
    ...
    protected int findPoweredRailSignal(Level p_55220_, BlockPos p_55221_, BlockState p_55222_, boolean reverse) {
        int i = p_55221_.getX();
        int j = p_55221_.getY();
        int k = p_55221_.getZ();
        boolean checkBelow = true;
        RailShape railshape = p_55222_.getValue(SHAPE);

        switch (railshape) {
            case NORTH_SOUTH:
                if (reverse) {
                    ++k;
                } else {
                    --k;
                }
                break;
            case EAST_WEST:
                if (reverse) {
                    --i;
                } else {
                    ++i;
                }
                break;
            case ASCENDING_EAST:
                if (reverse) {
                    --i;
                } else {
                    ++i;
                    ++j;
                    checkBelow = false;
                }

                railshape = RailShape.EAST_WEST;
                break;
            case ASCENDING_WEST:
                if (reverse) {
                    --i;
                    ++j;
                    checkBelow = false;
                } else {
                    ++i;
                }

                railshape = RailShape.EAST_WEST;
                break;
            case ASCENDING_NORTH:
                if (reverse) {
                    ++k;
                } else {
                    --k;
                    ++j;
                    checkBelow = false;
                }

                railshape = RailShape.NORTH_SOUTH;
                break;
            case ASCENDING_SOUTH:
                if (reverse) {
                    ++k;
                    ++j;
                    checkBelow = false;
                } else {
                    --k;
                }

                railshape = RailShape.NORTH_SOUTH;
        }

        int pow;

        if ((pow = this.getSameRailPower(p_55220_, new BlockPos(i, j, k), railshape)) > 0) {
            return pow;
        } else {
            return checkBelow ? this.getSameRailPower(p_55220_, new BlockPos(i, j - 1, k), railshape) : 0;
        }
    }

    /* renamed from isSameRailWithPower
     * I also removed the boolean param because it was not used anymore
     */
    protected int getSameRailPower(Level p_55226_, BlockPos p_55227_, RailShape p_55230_) {
        BlockState blockstate = p_55226_.getBlockState(p_55227_);

        if (!blockstate.is(this)) {
            return 0;
        } else {
            RailShape railshape = blockstate.getValue(SHAPE);

            if (p_55230_ != RailShape.EAST_WEST || railshape != RailShape.NORTH_SOUTH && railshape != RailShape.ASCENDING_NORTH && railshape != RailShape.ASCENDING_SOUTH) {
                if (p_55230_ != RailShape.NORTH_SOUTH || railshape != RailShape.EAST_WEST && railshape != RailShape.ASCENDING_EAST && railshape != RailShape.ASCENDING_WEST) {
                    if (blockstate.getValue(POWER) > 0) {
                        return blockstate.getValue(POWER);
                    } else {
                        return 0;
                    }
                } else {
                    return 0;
                }
            } else {
                return 0;
            }
        }
    }
    ...

 

Now, we are missing something: method updateState(BlockState,Level,BlockPos,Block). This is the only method that uses findPoweredRailSignal, and is the one that sets the rail's power value when it detects a neighbor change. We will update it in order to set the proper "power" block state, by getting instead the adjacent connected powered rails highest signal, and decrease it by 1 (so power will be lesser the further the rail is full from source rail):

 

public class PoweredRailBlock extends BaseRailBlock {
    ...
    @Override
    protected void updateState(BlockState p_55232_, Level p_55233_, BlockPos p_55234_, Block p_55235_) {
        int thisPower = p_55232_.getValue(POWER);
        /* Give nine of power instead of redstone power in order to keep the original behavior */
        int checkPower = Math.max(p_55233_.hasNeighborSignal(p_55234_) ? 9 : 0, Math.max(this.findPoweredRailSignal(p_55233_, p_55234_, p_55232_, true), this.findPoweredRailSignal(p_55233_, p_55234_, p_55232_, false)) - 1);

        if (checkPower != thisPower) {
            p_55233_.setBlock(p_55234_, p_55232_.setValue(POWER, Integer.valueOf(checkPower)), 3);
            p_55233_.updateNeighborsAt(p_55234_.below(), this);

            if (p_55232_.getValue(SHAPE).isAscending()) {
                p_55233_.updateNeighborsAt(p_55234_.above(), this);
            }
        }
    }
    ...

 

After this workaround, the bug seemed fixed.

Problems:

  • After changing powered rail's "powered" state, file assets/minecraft/blockstates/powered_rail.json went HUGE.

  • I couldn't find a way to datafix existing powered rail blocks from previous world version to give them the proper power value. You will have to destroy and place again the rail block.

migrated

In 1.20.2 Pre-Release 2

migrated

Can confirm, bug still occurs in 1.20.2 Pre-release 2.

Ceresjanin123

This could be fixed in the experimental redstone improvements hopefully

migrated

confirmed in 1.21.1

Loweredgames

Confirm 1.21.5

Avoma

(Unassigned)

Confirmed

Platform

Low

Block states, Minecart, Redstone

power, powered_rail, rails, redstone, update, update-failure

Minecraft 1.4.1, Minecraft 1.4.2, Snapshot 12w49a, Minecraft 1.4.6, Minecraft 1.4.7, ..., 24w34a, 1.21.3, 1.21.4, 25w08a, 1.21.5

Retrieved