mojira.dev
MC-248332

Bees, ghasts, phantoms, and allays can destroy turtle eggs

The Bug:

Bees, ghasts, phantoms, and allays can destroy turtle eggs.

Steps to Reproduce:

  1. Place down some turtle eggs.

  2. Use a spawn egg to summon a bee, ghast, phantom, or an allay on top of them.

  3. Take note as to whether or not bees, ghasts, phantoms, and allays can destroy turtle eggs.

Observed Behavior:

Bees, ghasts, phantoms, and allays can destroy turtle eggs.

Expected Behavior:

Bees, ghasts, phantoms, and allays would not be able to destroy turtle eggs.

Code Analysis:

Code analysis by @unknown can be found below.

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

net.minecraft.world.level.block.TurtleEggBlock.java

public class TurtleEggBlock extends Block {
   ...
   private boolean canDestroyEgg(Level $l, Entity $e) {
      if (!($e instanceof Turtle) && !($e instanceof Bat)) {
         if (!($e instanceof LivingEntity)) {
            return false;
         } else {
            return $e instanceof Player || $l.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
         }
      } else {
         return false;
      }
   }
   ...

If we look at the above class, we can see that the only entities that are not able to break turtle eggs are turtles and bats. This is evident through the following line of code:

if (!($e instanceof Turtle) && !($e instanceof Bat))

Since no checks are carried out to prevent bees, ghasts, or phantoms from breaking turtle eggs, this results in these entities being able to destroy these blocks.

Potential Fix:

Simply altering the appropriate "if" statement to prevent bees, ghasts, and phantoms from being able to break turtle eggs, should resolve this problem. The following line of code could be used in order to fix this:

if (!($e instanceof Turtle) && !($e instanceof Bat) && !($e instanceof Bee) && !($e instanceof Ghast) && !($e instanceof Phantom))

Linked issues

Attachments

Comments 5

This ticket relates to MC-173825

In 22w13a, this also now affects allays so I've updated this ticket accordingly to reflect this new information.

I have attached a short video of this bug occurring.

[media]

I am using an allay to collect turtle scutes, and I lost a few of them due to eggs getting crushed. I didn't witness it happening but I heard the eggs crack and then there were 3 eggs on squares where I had placed 4. Allays can fit into very tight spaces just like baby turtles so it's not easy to keep the allays separate from the eggs while making sure they can reach the scutes when the babies grow up.

Can confirm in 23w04a

Avoma

(Unassigned)

Confirmed

Gameplay

Normal

Block states, Entities

allay, bee, ghast, phantom

1.18.1, 22w03a, 22w05a, 22w06a, 1.18.2 Pre-release 1, ..., 23w04a, 1.19.4, 1.20.1, 1.21, 1.21.4

Retrieved