Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-222492

You can break turtle eggs by standing on them in adventure mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • 1.16.5, 21w13a, 21w14a, 21w15a, 21w16a, 21w17a, 21w18a, 21w19a, 21w20a, 1.17 Pre-release 1, 1.17 Pre-release 3, 1.17 Pre-release 4, 1.17 Pre-release 5, 1.17 Release Candidate 1, 1.17 Release Candidate 2, 1.17, 1.17.1 Pre-release 1, 1.17.1 Pre-release 2, 1.17.1 Release Candidate 1, 1.17.1, 21w37a, 21w43a, 1.18, 1.18.1, 22w05a, 22w06a, 1.18.2 Pre-release 1, 1.18.2, 22w11a, 1.19, 1.19.2, 22w43a, 1.19.3, 1.19.4, 1.20.1, 1.20.4, 23w51b
    • Community Consensus
    • Adventure
    • Block states, Player

      The Bug:

      You can break turtle eggs by standing on them in adventure mode.

      Steps to Reproduce:

      1. Place down some turtle eggs.
      2. Switch into adventure mode and stand on the turtle eggs.
      3. Take note as to whether or not you can break turtle eggs by standing on them in adventure mode.

      Observed Behavior:

      You can break turtle eggs by standing on them.

      Expected Behavior:

      You would not be able to break turtle eggs by standing on them.

      Code Analysis:

      Code analysis by Avoma 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 no checks are carried out to see what abilities the player possesses before allowing them to break turtle eggs by standing on them. The only relevant check that is in place is to see if the entity standing on the turtle egg is a player, and if it is, the turtle eggs can be trampled. This is evident through the following line of code:

      $e instanceof Player

      Since the presence of a player and not what abilities they possess is the only relevant requirement for a turtle egg to be trampled, we can therefore safely assume that players in adventure mode can break turtle eggs by standing on them.

      Potential Fix:

      Simply altering the existing "if" statement within this piece of code to check what abilities the player possesses before allowing them to break turtle eggs by standing on them, should resolve this problem. The following line of code could be used in order to fix this:

      !$PLAYER.getAbilities().mayBuild

      The fixed and correct piece of code within its class should look something like the following:

      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 && !((Player)$e).getAbilities().mayBuild || $l.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING);
               }
            } else {
               return false;
            }
         }
         ...

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            7 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              CHK: