-
Bug
-
Resolution: Unresolved
-
None
-
Minecraft 1.14 Pre-Release 5, Minecraft 1.14, Minecraft 1.14.1 Pre-Release 1, Minecraft 1.14.1 Pre-Release 2, Minecraft 1.14.2, Minecraft 1.14.3 Pre-Release 3, Minecraft 1.14.3 Pre-Release 4, Minecraft 1.14.3, 1.14.4, 19w44a, 1.15.1, 1.15.2, 20w13b, 20w14a, 20w16a, 20w19a, 20w22a, 1.16 Release Candidate 1, 1.16, 1.16.2, 1.16.3, 1.17, 1.17.1, 1.18.1, 1.18.2 Pre-release 1, 1.18.2, 1.19, 1.19.2, 22w43a, 1.19.3, 23w03a, 1.19.4, 1.20, 1.20.1, 1.20.4, 23w51b, 1.20.6, 1.21, 1.21.3
-
Confirmed
-
Mob behaviour, Village system
-
Normal
-
Gameplay
The Bug:
Villagers can trample farmland.
This issue can commonly be seen when farmer villagers wander and jump around their workstations.
Steps to Reproduce:
- Build the setup as shown in the attachment below. setup.png
- Summon a villager and wait for it to claim the composter as its workstation.
- Give the villager some carrots so it can begin working.
- Observe the behavior of the villager for around a minute and watch closely as it wanders and jumps around its workstation.
- Take note as to whether or not villagers can trample farmland.
Observed Behavior:
Villagers can trample farmland.
Expected Behavior:
Villagers would not be able to trample farmland.
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 are only two necessary checks that are carried out before allowing villagers to trample farmland. One of these checks is to quite simply see if the entity falling on the farmland is a living entity and if it is, the other check is then to see if "mobGriefing" gamerule is set to "true". If these two requirements are met along with the other criteria within the "if" statement, the farmland can be trampled. The game doesn't check to see if the living entity is a villager 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 if the living entity is a villager 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 Villager)) && (entity instanceof Player || level.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) && entity.getBbWidth() * entity.getBbWidth() * entity.getBbHeight() > 0.512F)
- is duplicated by
-
MC-148611 Farmers Trample Farmland
- Resolved
-
MC-149205 Vilagers go on top of compost
- Resolved
-
MC-149606 Villagers destroying their own farm on accident
- Resolved
-
MC-150062 Farmland tramped to dirt by farmers keep their seeds
- Resolved
-
MC-150541 Farmer villager not planting crops
- Resolved
-
MC-151314 Villagers (Farmers) jump down from the composter, so that crash the harvest and farmland
- Resolved
-
MC-151324 Villagers often jump over composters, causing trampling farmlands.
- Resolved
-
MC-154133 Villager AI
- Resolved
-
MC-155456 Farmer Villagers
- Resolved
-
MC-156047 Farmer Villagers
- Resolved
-
MC-176329 Farmer villagers destroy crops when getting on top of a composter and getting down
- Resolved
-
MC-198083 Farmer stomps on crops
- Resolved
-
MC-201700 Villager Farmers Trample Crops
- Resolved
- relates to
-
MC-148715 Farmers can plant seeds on a non-farmland dirt block
- Open