How to make a bridge egg in vanilla Minecraft?

In Minecraft Hypixel Bed Wars, we have an item called Bridge Egg. When thrown, it creates a bridge.

enter image description here

(source)

Is it possible to make a bridge egg in vanilla Minecraft?


Yes, it is possible!

It is actually very easy to make a bridge egg in vanilla Minecraft. To avoid unwanted chickens from spawning, snowballs are used in this post instead of eggs. (That does not really make a difference.)

Think of it this way: we throw a snowball, and the snowball constantly place a block in its place. This sounds so easy, so we place an always-active repeating command block, and type in:

execute at @e[type=minecraft:snowball] run setblock ~ ~ ~ minecraft:white_wool

Unfortunately, this doesn't work at all. The snowball placed a block in the player as soon as it is fired, and it crashes into the block. We have to fix these problems.

The first problem is simple to fix: let the snowball place the block only if it is far enough away from the player. This can be achieved with an unless clause:

execute at @e[type=minecraft:snowball] unless entity @a[distance=..3] run setblock ~ ~ ~ minecraft:white_wool

This way, at least the first block appears in front of the player, not inside. But still, only one block is placed. We can fix this issue by placing the block beneath the snowball instead of in place of it. We replace setblock ~ ~ ~ with setblock ~ ~-2 ~:

execute at @e[type=minecraft:snowball] unless entity @a[distance=..3] run setblock ~ ~-2 ~ minecraft:white_wool

A (broken) bridge is appearing! However, the bridge replaces everything (even the floor). This is not desired. We can add keep to the setblock command to make sure that it only places a block in an air block.

execute at @e[type=minecraft:snowball] unless entity @a[distance=..3] run setblock ~ ~-2 ~ minecraft:white_wool keep

Now we still have the broken bridge problem. We fix it by using fill ~ ~-2 ~ ~1 ~-2 ~1, thus setting the width to 2 blocks:

execute at @e[type=minecraft:snowball] unless entity @a[distance=..3] run fill ~ ~-2 ~ ~1 ~-2 ~1 minecraft:white_wool keep

It's working fine:

enter image description here