The bug
Powered rails do not update when additional power sources are added or removed.
How to reproduce
Build the setup as shown in the attachment below (
)
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
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
is duplicated by
relates to
Attachments
Comments


<Comment removed by MOD>

I'm spanish don't insult me man

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.

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

Confirmed for 12w49a

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.

Still happens in 13w05b

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

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

still in 1.6.1 pre

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.

This is still valid indeed.

Still present in 08a

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.

Confirmed in 14w11b.

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.

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.

Still not fixed as of 14w27b
This can be exploited by mapmakers to create enormous self-powered tracks with but a pair of torches.

Still reproduceable in 14w32d!

Confirmed in 1.8-pre 3.

Confirmed in 1.8.6
Confirmed 15w31c

Confirmed for 15w44b

Confirmed for 1.8.9 and 15w51b.

Confirmed for 16w03a.

Confirmed for 1.9-pre1

Confirmed for 1.9-pre3

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

Confirmed for 1.10.1.

Confirmed for 1.10.2.

Confirmed for 1.12.1
Can confirm for 17w43a/b

Bug still present in 18w03b

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

Confirmed for MC 1.13-pre4too.

Confirmed in 1.13-pre7.

Confirmed for 1.13-pre8.

Confirmed for 1.13-pre9.

Confirmed for 1.13-pre10.

Confirmed for 1.13.

Confirmed for 18w30a.

Confirmed for 18w30b.

Confirmed for 18w31a.

Confirmed for 18w32a.

Confirmed for 18w33a.

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

Confirmed for 1.13.2-pre1.

Confirmed for 1.13.2-pre2.

Confirmed for 18w48a

Confirmed for 18w48b

Confirmed for 18w49a

Confirmed for 18w50a

Confirmed for 19w02a

Confirmed for 19w03a

Confirmed for 19w03b

Confirmed for 19w03c

Comfirmed for 19w04a

Confirmed for 19w04b and 19w05a

Confirmed for 19w06a

Confirmed for 19w07a

Confirmed for 19w09a

Confirmed for 19w11a

Confirmed for 19w11b

Confirmed for 19w12a

Confirmed for 19w12b

Confirmed for 19w13a

Confirmed for 19w13b

Confirmed for 19w14a

Confirmed for 19w14b

Confirmed for 1.14 pre-1

Still in 1.14 Pre-Release 2

Confirmed for 1.14 pre-3

Confirmed for 1.14 pre-4

Confirmed for 1.14 pre-5

Still in 1.14 Release

Confirmed for 1.14 Release

Confirmed for 1.14.1 pre-1

Confirmed for 1.14.1 pre-2

Confirmed for 1.14.1

Can also confirm for 1.14.1 Release

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

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.

Still in snapshot 20w17a

and 20w18a

Affects 1.16 pre2

Confirmed in 1.16-pre5.

Confirmed in 1.16-pre6.

affects 20w27a

confirmed for 20w45a

cofirmed in 1.4.1

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

Confimed on 1.16.4

Also affects Activator Rails.

There is an easy workaround, just break the rail, add the source and it works.
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.
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.

Can confirm in Release 1.17.1

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

Can confirm in 23w03a

Can confirm in 23w04a

Can confirm in 23w06a

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.

In 1.20.2 Pre-Release 2

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

This could be fixed in the experimental redstone improvements hopefully

confirmed in 1.21.1

Confirm 1.21.5