mojira.dev
MC-231663

Dragon egg does not check whether there is a block under the destination when teleporting

The Bug

Dragon egg does not check whether there is a block under the destination when teleporting.

May cause the dragon egg to fall into the void.

Steps to Reproduce

  1. Create a Superflat world:

    100*minecraft:air,minecraft:glass;minecraft:plains
  2. Place a dragon egg.

  3. Right-click it to make it teleport.

  4. Note that the dragon egg will teleport into the air and fall into the void.

Code analysis provided by @unknown

Linked issues

Attachments

Comments 9

This issue is different from MC-174759.
MC-174759 mainly states that the dragon egg can teleport to -Y.

I am able to confirm this behavior in 21w38a though, this may be a duplicate ofย MC-229536. Please correct me if I'm wrong as I'm not 100% sure.

@@unknown
MC-229536 is about the dragon eggs can teleport in the air.
This issue mainly focuses on whether to check that there is void below the dragon eggs.

Ahh, I see. Thank you for this info ๐Ÿ™‚

Can confirm in 1.18.1.

Here's a code analysis of this issue.

Code Analysis:

The following is based on a decompiled version of Minecraft 1.18.1 using MCP-Reborn.

net.minecraft.world.level.block.DragonEggBlock.java

public class DragonEggBlock extends FallingBlock {
   ...
 ย  private void teleport(BlockState $bs, Level $l, BlockPos $bp) {
      WorldBorder worldborder = $l.getWorldBorder();

      for(int i = 0; i < 1000; ++i) {
         BlockPos blockpos = $bp.offset($l.random.nextInt(16) - $l.random.nextInt(16), $l.random.nextInt(8) - $l.random.nextInt(8), $l.random.nextInt(16) - $l.random.nextInt(16));
         if ($l.getBlockState(blockpos).isAir() && worldborder.isWithinBounds(blockpos)) {
            ...

If we look at the above class, we can see that no checks are carried out to see whether the block below the dragon egg's teleportation destination is air. The only checks that are in place are to see whether or not its desired teleportation destination is air, and is within the world border. This is evident through the following line of code:

if ($l.getBlockState(blockpos).isAir() && worldborder.isWithinBounds(blockpos))

Because of this, dragon eggs can teleport on top of any block.

Can confirm in 22w06a.

Can confirm in 1.18.2.

[Mod]Les3awe

(Unassigned)

Confirmed

Block states

dragon_egg

1.17.1, 21w37a, 21w38a, 21w40a, 21w43a, ..., 25w17a, 1.21.6 Pre-Release 3, 1.21.8, 25w32a, 25w34b

Retrieved