Clouds Clouds Airship Belthil Tower Nether Temple
📚 Learn more about The Shire's history on our Timeline. 🕰

Hanging Railways with Command Blocks

Options
Ok, I messed with command blocks a bit after seeing someone make high-speed railways with command blocks.
His device teleports the cart quickly forward in the direction the player is looking at, but does not work on diagonals. It works server wide, since it uses execute.

So, having not used command blocks in my life before, I decided to have a crack at making hanging rails work. The result is:
image
The rail can make turns, and uses 14 command blocks:
image
The commands:
The two command blocks on the left rapidly place rails under the player when there's iron bars overhead, keeping them afloat:
/execute @a ~ ~ ~ detect ~ ~3 ~ minecraft:iron_bars 0 /fill ~ ~ ~ ~ ~ ~ minecraft:barrier 0 keep
/execute @a ~ ~ ~ detect ~ ~3 ~ minecraft:iron_bars 0 /fill ~ ~1 ~ ~ ~1 ~ minecraft:rail 0 keep

The four columns build rails depending on the shape of the iron bars above. The green block is set to conditional, all blocks are always ticking (should not cause too much lag, but can be activated by detector rail).
Commands left to right, in the order of:
<Green>
<Middle purple>
<Top purple>
//left
/execute @a ~ ~ ~ detect ~ ~3 ~-1 minecraft:iron_bars 0 /fill ~2 ~1 ~1 ~-2 ~ ~2 air 0 replace minecraft:barrier
/execute @a ~ ~ ~ detect ~ ~3 ~-1 minecraft:iron_bars 0 /setblock ~ ~1 ~-1 minecraft:rail 0 keep
/execute @a ~ ~ ~ detect ~ ~3 ~-1 minecraft:iron_bars 0 /setblock ~ ~ ~-1 minecraft:barrier 0 keep

//middle left
/execute @a ~ ~ ~ detect ~1 ~3 ~ minecraft:iron_bars 0 /fill ~-1 ~1 ~2 ~-2 ~ ~-2 air 0 replace minecraft:barrier
/execute @a ~ ~ ~ detect ~1 ~3 ~ minecraft:iron_bars 0 /setblock ~1 ~1 ~ minecraft:rail 0 keep
/execute @a ~ ~ ~ detect ~1 ~3 ~ minecraft:iron_bars 0 /setblock ~1 ~ ~ minecraft:barrier 0 keep

//middle right
/execute @a ~ ~ ~ detect ~ ~3 ~1 minecraft:iron_bars 0 /fill ~2 ~1 ~-1 ~-2 ~ ~-2 air 0 replace minecraft:barrier
/execute @a ~ ~ ~ detect ~ ~3 ~1 minecraft:iron_bars 0 /setblock ~ ~1 ~1 minecraft:rail 0 keep
/execute @a ~ ~ ~ detect ~ ~3 ~1 minecraft:iron_bars 0 /setblock ~ ~ ~1 minecraft:barrier 0 keep

//right
/execute @a ~ ~ ~ detect ~-1 ~3 ~ minecraft:iron_bars 0 /fill ~1 ~1 ~2 ~2 ~ ~-2 air 0 replace minecraft:barrier
/execute @a ~ ~ ~ detect ~-1 ~3 ~ minecraft:iron_bars 0 /setblock ~-1 ~1 ~ minecraft:rail 0 keep
/execute @a ~ ~ ~ detect ~-1 ~3 ~ minecraft:iron_bars 0 /setblock ~-1 ~ ~ minecraft:barrier 0 keep

Restrictions:
-Players MUST NOT stand directly under the bars, it will trick the command blocks to place rails and barrier blocks without removing them. Can be solved by containing hanging sections in barriers.

-Although it theoretically should work server-wide, it hasn't been tested. Chunk unloading may cause issues.

-The transition between hanging rail and normal rail MUST NOT be made of normal rail, the command blocks will destroy them after boarding.

-The player MUST NOT get off mid-way, it will leave residue tracks (though this is unlikely since there isn't much hanging rail to begin with). Can be solved by setting up track-clearing command blocks that delete everything after/before the section.

-Rails will not be deleted if the block under it isn't barrier. Mostly benign.

-More beta-testing needed, compatible so far with super-fast-minecarts.