-
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:
- Place down some water and farmland close to one another.
- Switch into adventure mode and jump on top of the farmland several times.
- 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.
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.
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)
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) {
- is duplicated by
-
MC-128928 Adventure mode players can trample farmland
- Resolved
-
MC-269148 Farmland gets trampled when in adventure mode
- Resolved
- relates to
-
MC-223323 You can trample farmland in spawn protection
- Open
-
MC-76366 Players in adventure mode can trample crops
- Resolved
-
MCPE-103500 Farmland can be trampled by players in adventure mode
- Reopened