-
Bug
-
Resolution: Unresolved
-
None
-
1.16.5, 21w15a, 21w16a, 21w18a, 21w19a, 21w20a, 1.17, 1.17.1, 1.18.1, 1.18.2 Pre-release 1, 1.18.2, 1.19, 1.19.2, 1.19.3, 1.19.4, 1.20.1, 1.21
-
Confirmed
-
Player
The Bug:
Players without operator permissions cannot normally interact with or destroy blocks inside spawn protection, however, you are able to trample farmland, regardless of whether or not it's inside of spawn protection.
Steps to Reproduce:
- Start a server, join it, give operator permissions to yourself, and switch into creative mode.
- Set the world spawn to your current location and summon some water and farmland nearby by using the commands provided below.
/setworldspawn ~ ~ ~
/setblock ~1 ~-1 ~-2 minecraft:water
/setblock ~ ~-1 ~-2 minecraft:farmland
- Switch into survival mode, remove your operator permissions, and grant anyone else with them in order to activate spawn protection.
- Attempt to trample the farmland by jumping on it.
- Take note as to whether or not you can trample farmland in spawn protection.
Observed Behavior:
Farmland is trampled.
Expected Behavior:
Farmland would not be trampled.
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.
public class FarmBlock extends Block { ... public void fallOn(Level $l, BlockState $bs, BlockPos $bp, Entity $e, float $f) { if (!$l.isClientSide && $l.random.nextFloat() < $f - 0.5F && $e instanceof LivingEntity && ($e instanceof Player || $l.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && $e.getBbWidth() * $e.getBbWidth() * $e.getBbHeight() > 0.512F) { turnToDirt($bs, $l, $bp); } super.fallOn($l, $bs, $bp, $e, $f); } ...
If we look at the above class, we can see that no checks are carried out to see whether or not the farmland block is within spawn protection, before allowing it to be trampled. The mayInteract() method (a method used for determining whether a block is inside of spawn protection and is within the world border) is never called within this piece of code, thus resulting in the problem of being able to trample farmland in spawn protection.
Potential Fix:
Simply adding some lines of code that check if the farmland block is within spawn protection before allowing it to be trampled, should resolve this problem. This can be achieved by calling the mayInteract() method and adding it appropriately somewhere within the existing "if" statement. The following line of code could be used in order to fix this:
$e.mayInteract($l, $bp)
The fixed and correct piece of code within its class should look something like the following:
public class FarmBlock extends Block { ... public void fallOn(Level $l, BlockState $bs, BlockPos $bp, Entity $e, float $f) { if (!$l.isClientSide && $l.random.nextFloat() < $f - 0.5F && $e instanceof LivingEntity && ($e instanceof Player || $l.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && $e.mayInteract($l, $bp) && $e.getBbWidth() * $e.getBbWidth() * $e.getBbHeight() > 0.512F) { turnToDirt($bs, $l, $bp); } super.fallOn($l, $bs, $bp, $e, $f); } ...
- relates to
-
MC-138963 You can trample farmland in adventure mode
- Reopened