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

You can trample farmland in adventure mode

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Unresolved
    • None
    • Minecraft 1.13.2, Minecraft 18w43b, Minecraft 18w43c, Minecraft 18w44a, Minecraft 18w45a, Minecraft 18w46a, Minecraft 18w48a, Minecraft 18w48b, Minecraft 18w49a, Minecraft 19w03c, Minecraft 19w04b, 1.15.2, 20w06a, 20w07a, 20w08a, 20w10a, 20w14a, 20w15a, 20w18a, 20w19a, 20w20b, 20w21a, 20w22a, 1.16 Pre-release 2, 1.16.1, 1.16.2 Pre-release 1, 1.16.2 Pre-release 3, 1.16.2 Release Candidate 1, 1.16.2 Release Candidate 2, 1.16.2, 1.16.3 Release Candidate 1, 1.16.3, 1.16.4 Pre-release 2, 1.16.4 Release Candidate 1, 1.16.4, 20w49a, 21w06a, 21w14a, 1.17, 1.17.1, 21w41a, 21w42a, 21w43a, 1.18 Pre-release 1, 1.18, 1.18.1, 22w03a, 22w05a, 22w06a, 22w07a, 1.18.2 Pre-release 1, 1.18.2, 22w17a, 22w18a, 1.19 Pre-release 1, 1.19, 1.19.2, 22w43a, 1.19.3, 23w03a, 1.19.4, 1.20, 1.20.1, 24w11a, 24w20a, 1.21, 1.21.3
    • Confirmed
    • Adventure
    • Player
    • Low
    • Gameplay

      The Bug:

      You can trample farmland in adventure mode.

      Steps to Reproduce:

      1. Place down some water and farmland close to one another.
      2. Switch into adventure mode and jump on top of the farmland several times.
      3. Take note as to whether or not you can trample farmland in adventure mode.

      Observed Behavior:

      You can trample farmland in adventure mode.

      Expected Behavior:

      You would not be able to trample farmland in adventure mode.

      Code Analysis:

      Code analysis by Avoma can be found below.

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

      net.minecraft.world.level.block.FarmBlock.java
      public class FarmBlock extends Block {
         ...
         public void fallOn(Level level, BlockState blockState, BlockPos blockPos, Entity entity, float f) {
            if (!level.isClientSide
                    && level.random.nextFloat() < f - 0.5F
                    && entity instanceof LivingEntity
                    && (entity instanceof Player || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING))
                    && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) {
               turnToDirt(blockState, level, blockPos);
            }
            super.fallOn(level, blockState, blockPos, entity, f);
         }
         ...

      If we look at the above class, we can see that there is only one necessary check that's carried out before allowing players to trample farmland. This check is to quite simply see if the entity falling on the farmland is a player. If it is, the farmland can be trampled if the other requirements within the "if" statement are met. The game doesn't check to see what abilities the player possesses (what game mode they are in) before allowing them to trample farmland, therefore resulting in this problem occurring.

      Fix:

      Simply altering the existing "if" statement within this piece of code to check what abilities the player possesses before allowing them to trample farmland will resolve this problem.

      Current "if" statement:
      if (!level.isClientSide 
              && level.random.nextFloat() < f - 0.5F 
              && entity instanceof LivingEntity 
              && (entity instanceof Player || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) 
              && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F)
      Fixed "if" statement:
      if (!level.isClientSide 
              && level.random.nextFloat() < f - 0.5F 
              && entity instanceof LivingEntity 
              && ((entity instanceof Player player && player.getAbilities().mayBuild) || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) 
              && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F) {

        1. MC-138963.mp4
          4.21 MB
        2. MC-138963.png
          MC-138963.png
          1.34 MB
        3. MC-138963 - Current Code.png
          MC-138963 - Current Code.png
          38 kB
        4. MC-138963 - Fixed Code.png
          MC-138963 - Fixed Code.png
          42 kB
        5. Screen Shot 2018-11-06 at 11.12.22 PM.png
          Screen Shot 2018-11-06 at 11.12.22 PM.png
          1.60 MB

            Unassigned Unassigned
            Avoma [Mod] Avoma
            Votes:
            29 Vote for this issue
            Watchers:
            12 Start watching this issue

              Created:
              Updated:
              CHK: