mojira.dev
MC-138963

You can trample farmland in adventure mode

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 @unknown 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) {

Linked issues

Attachments

Comments 16

I understand there is another bug report with the same name, but it has been auto-resolved several months ago and I am unsure how to re-open it. Forgive me if I accidentally duped a report.

The duplicate bug  is MC-128928

I've resolved that one as a duplicate of this report, just because that one is fairly empty and this one is slightly better. You could comment on the report and ask for it to be reopened, but sometimes such comments are missed unfortunately

Changed the reporter to @unknown since he requested for it on Discord, and the original reporter has been inactive since November 2018.

Reopening and removing duplicate link because this ticket does not report the same issue as MC-76366. The issue there is that adventure mode players can break crops by falling on them. The issue here is that adventure mode players can convert the farmland to dirt. These events have different consequenses: a farmer can replant crops if they break and the farmland is still there. Destruction of farmland in adventure mode is permanent, however, so this issue could break maps.

6 more comments

Following on from my code analysis, I've double-checked my proposed fix and I can confidently confirm that it's fully functioning and works as expected, so I've attached two screenshots to this report, one of which shows the current code and the other that shows the fixed code. I feel this information may be quite insightful hence my reasoning for providing it. 🙂

[media][media]

Might want to make the section before the OR operator in parenthesis too, to prevent ambiguity. (Is it "player in adventure, or mob griefing"; or is it "player, in adventure or mob griefing"?)

@unknown; yes, thank you profusely. I've updated the code analysis to prevent ambiguity here. Thanks once again! 🙂

Can confirm in 23w03a

@unknown
— The issue there is that adventure mode players can break crops by falling on them.
This presents the identical problem. Falling onto the crops can result in their breakage since the farmland shifts to dirt, thereby compromising the support for the crops, leading to their breakage.
— These events have different consequenses: a farmer can replant crops if they break and the farmland is still there.
It has never been possible to trample crops without converting the farmland to dirt.

Peyton Bates

Avoma

(Unassigned)

Confirmed

Gameplay

Low

Player

farmland

Minecraft 1.13.2, Minecraft 18w43b, Minecraft 18w43c, Minecraft 18w44a, Minecraft 18w45a, ..., 1.21.3, 1.21.4, 25w08a, 1.21.5, 1.21.7

Retrieved