--- a/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
+++ b/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
@@ -26,6 +26,7 @@
 import net.minecraft.world.level.gameevent.GameEvent;
 
 public class HarvestFarmland extends Behavior<Villager> {
+
     private static final int HARVEST_DURATION = 200;
     public static final float SPEED_MODIFIER = 0.5F;
     @Nullable
@@ -38,22 +39,22 @@
         super(ImmutableMap.of(MemoryModuleType.LOOK_TARGET, MemoryStatus.VALUE_ABSENT, MemoryModuleType.WALK_TARGET, MemoryStatus.VALUE_ABSENT, MemoryModuleType.SECONDARY_JOB_SITE, MemoryStatus.VALUE_PRESENT));
     }
 
-    @Override
     protected boolean checkExtraStartConditions(ServerLevel world, Villager entity) {
         if (!world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING)) {
             return false;
         } else if (entity.getVillagerData().getProfession() != VillagerProfession.FARMER) {
             return false;
         } else {
-            BlockPos.MutableBlockPos mutableBlockPos = entity.blockPosition().mutable();
+            BlockPos.MutableBlockPos blockposition_mutableblockposition = entity.blockPosition().mutable();
+
             this.validFarmlandAroundVillager.clear();
 
-            for(int i = -1; i <= 1; ++i) {
-                for(int j = -1; j <= 1; ++j) {
-                    for(int k = -1; k <= 1; ++k) {
-                        mutableBlockPos.set(entity.getX() + (double)i, entity.getY() + (double)j, entity.getZ() + (double)k);
-                        if (this.validPos(mutableBlockPos, world)) {
-                            this.validFarmlandAroundVillager.add(new BlockPos(mutableBlockPos));
+            for (int i = -1; i <= 1; ++i) {
+                for (int j = -1; j <= 1; ++j) {
+                    for (int k = -1; k <= 1; ++k) {
+                        blockposition_mutableblockposition.set(entity.getX() + (double) i, entity.getY() + (double) j, entity.getZ() + (double) k);
+                        if (this.validPos(blockposition_mutableblockposition, world)) {
+                            this.validFarmlandAroundVillager.add(new BlockPos(blockposition_mutableblockposition));
                         }
                     }
                 }
@@ -66,92 +67,101 @@
 
     @Nullable
     private BlockPos getValidFarmland(ServerLevel world) {
-        return this.validFarmlandAroundVillager.isEmpty() ? null : this.validFarmlandAroundVillager.get(world.getRandom().nextInt(this.validFarmlandAroundVillager.size()));
+        return this.validFarmlandAroundVillager.isEmpty() ? null : (BlockPos) this.validFarmlandAroundVillager.get(world.getRandom().nextInt(this.validFarmlandAroundVillager.size()));
     }
 
     private boolean validPos(BlockPos pos, ServerLevel world) {
-        BlockState blockState = world.getBlockState(pos);
-        Block block = blockState.getBlock();
-        Block block2 = world.getBlockState(pos.below()).getBlock();
-        return block instanceof CropBlock && ((CropBlock)block).isMaxAge(blockState) || blockState.isAir() && block2 instanceof FarmBlock;
+        BlockState iblockdata = world.getBlockState(pos);
+        Block block = iblockdata.getBlock();
+        Block block1 = world.getBlockState(pos.below()).getBlock();
+
+        return block instanceof CropBlock && ((CropBlock) block).isMaxAge(iblockdata) || iblockdata.isAir() && block1 instanceof FarmBlock;
     }
 
-    @Override
     protected void start(ServerLevel world, Villager entity, long time) {
         if (time > this.nextOkStartTime && this.aboveFarmlandPos != null) {
-            entity.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(this.aboveFarmlandPos));
-            entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1));
+            entity.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, (new BlockPosTracker(this.aboveFarmlandPos))); // CraftBukkit - decompile error
+            entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, (new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1))); // CraftBukkit - decompile error
         }
 
     }
 
-    @Override
-    protected void stop(ServerLevel serverLevel, Villager villager, long l) {
-        villager.getBrain().eraseMemory(MemoryModuleType.LOOK_TARGET);
-        villager.getBrain().eraseMemory(MemoryModuleType.WALK_TARGET);
+    protected void stop(ServerLevel worldserver, Villager entityvillager, long i) {
+        entityvillager.getBrain().eraseMemory(MemoryModuleType.LOOK_TARGET);
+        entityvillager.getBrain().eraseMemory(MemoryModuleType.WALK_TARGET);
         this.timeWorkedSoFar = 0;
-        this.nextOkStartTime = l + 40L;
+        this.nextOkStartTime = i + 40L;
     }
 
-    @Override
-    protected void tick(ServerLevel serverLevel, Villager villager, long l) {
-        if (this.aboveFarmlandPos == null || this.aboveFarmlandPos.closerToCenterThan(villager.position(), 1.0D)) {
-            if (this.aboveFarmlandPos != null && l > this.nextOkStartTime) {
-                BlockState blockState = serverLevel.getBlockState(this.aboveFarmlandPos);
-                Block block = blockState.getBlock();
-                Block block2 = serverLevel.getBlockState(this.aboveFarmlandPos.below()).getBlock();
-                if (block instanceof CropBlock && ((CropBlock)block).isMaxAge(blockState)) {
-                    serverLevel.destroyBlock(this.aboveFarmlandPos, true, villager);
+    protected void tick(ServerLevel worldserver, Villager entityvillager, long i) {
+        if (this.aboveFarmlandPos == null || this.aboveFarmlandPos.closerToCenterThan(entityvillager.position(), 1.0D)) {
+            if (this.aboveFarmlandPos != null && i > this.nextOkStartTime) {
+                BlockState iblockdata = worldserver.getBlockState(this.aboveFarmlandPos);
+                Block block = iblockdata.getBlock();
+                Block block1 = worldserver.getBlockState(this.aboveFarmlandPos.below()).getBlock();
+
+                if (block instanceof CropBlock && ((CropBlock) block).isMaxAge(iblockdata)) {
+                    // CraftBukkit start
+                    if (!org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory.callEntityChangeBlockEvent(entityvillager, this.aboveFarmlandPos, Blocks.AIR.defaultBlockState()).isCancelled()) {
+                        worldserver.destroyBlock(this.aboveFarmlandPos, true, entityvillager);
+                    }
+                    // CraftBukkit end
                 }
 
-                if (blockState.isAir() && block2 instanceof FarmBlock && villager.hasFarmSeeds()) {
-                    SimpleContainer simpleContainer = villager.getInventory();
+                if (iblockdata.isAir() && block1 instanceof FarmBlock && entityvillager.hasFarmSeeds()) {
+                    SimpleContainer inventorysubcontainer = entityvillager.getInventory();
 
-                    for(int i = 0; i < simpleContainer.getContainerSize(); ++i) {
-                        ItemStack itemStack = simpleContainer.getItem(i);
-                        boolean bl = false;
-                        if (!itemStack.isEmpty()) {
-                            if (itemStack.is(Items.WHEAT_SEEDS)) {
-                                BlockState blockState2 = Blocks.WHEAT.defaultBlockState();
-                                serverLevel.setBlockAndUpdate(this.aboveFarmlandPos, blockState2);
-                                serverLevel.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(villager, blockState2));
-                                bl = true;
-                            } else if (itemStack.is(Items.POTATO)) {
-                                BlockState blockState3 = Blocks.POTATOES.defaultBlockState();
-                                serverLevel.setBlockAndUpdate(this.aboveFarmlandPos, blockState3);
-                                serverLevel.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(villager, blockState3));
-                                bl = true;
-                            } else if (itemStack.is(Items.CARROT)) {
-                                BlockState blockState4 = Blocks.CARROTS.defaultBlockState();
-                                serverLevel.setBlockAndUpdate(this.aboveFarmlandPos, blockState4);
-                                serverLevel.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(villager, blockState4));
-                                bl = true;
-                            } else if (itemStack.is(Items.BEETROOT_SEEDS)) {
-                                BlockState blockState5 = Blocks.BEETROOTS.defaultBlockState();
-                                serverLevel.setBlockAndUpdate(this.aboveFarmlandPos, blockState5);
-                                serverLevel.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(villager, blockState5));
-                                bl = true;
+                    for (int j = 0; j < inventorysubcontainer.getContainerSize(); ++j) {
+                        ItemStack itemstack = inventorysubcontainer.getItem(j);
+                        boolean flag = false;
+
+                        if (!itemstack.isEmpty()) {
+                            BlockState iblockdata1;
+
+                            // CraftBukkit start
+                            if (itemstack.is(Items.WHEAT_SEEDS)) {
+                                iblockdata1 = Blocks.WHEAT.defaultBlockState();
+                                flag = true;
+                            } else if (itemstack.is(Items.POTATO)) {
+                                iblockdata1 = Blocks.POTATOES.defaultBlockState();
+                                flag = true;
+                            } else if (itemstack.is(Items.CARROT)) {
+                                iblockdata1 = Blocks.CARROTS.defaultBlockState();
+                                flag = true;
+                            } else if (itemstack.is(Items.BEETROOT_SEEDS)) {
+                                iblockdata1 = Blocks.BEETROOTS.defaultBlockState();
+                                flag = true;
+                            } else {
+                                iblockdata1 = null;
+                            }
+
+                            if (iblockdata1 != null && !org.bukkit.craftbukkit.v1_19_R1.event.CraftEventFactory.callEntityChangeBlockEvent(entityvillager, this.aboveFarmlandPos, iblockdata1).isCancelled()) {
+                                worldserver.setBlockAndUpdate(this.aboveFarmlandPos, iblockdata1);
+                                worldserver.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(entityvillager, iblockdata1));
+                            } else {
+                                flag = false;
                             }
+                            // CraftBukkit end
                         }
 
-                        if (bl) {
-                            serverLevel.playSound((Player)null, (double)this.aboveFarmlandPos.getX(), (double)this.aboveFarmlandPos.getY(), (double)this.aboveFarmlandPos.getZ(), SoundEvents.CROP_PLANTED, SoundSource.BLOCKS, 1.0F, 1.0F);
-                            itemStack.shrink(1);
-                            if (itemStack.isEmpty()) {
-                                simpleContainer.setItem(i, ItemStack.EMPTY);
+                        if (flag) {
+                            worldserver.playSound((Player) null, (double) this.aboveFarmlandPos.getX(), (double) this.aboveFarmlandPos.getY(), (double) this.aboveFarmlandPos.getZ(), SoundEvents.CROP_PLANTED, SoundSource.BLOCKS, 1.0F, 1.0F);
+                            itemstack.shrink(1);
+                            if (itemstack.isEmpty()) {
+                                inventorysubcontainer.setItem(j, ItemStack.EMPTY);
                             }
                             break;
                         }
                     }
                 }
 
-                if (block instanceof CropBlock && !((CropBlock)block).isMaxAge(blockState)) {
+                if (block instanceof CropBlock && !((CropBlock) block).isMaxAge(iblockdata)) {
                     this.validFarmlandAroundVillager.remove(this.aboveFarmlandPos);
-                    this.aboveFarmlandPos = this.getValidFarmland(serverLevel);
+                    this.aboveFarmlandPos = this.getValidFarmland(worldserver);
                     if (this.aboveFarmlandPos != null) {
-                        this.nextOkStartTime = l + 20L;
-                        villager.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1));
-                        villager.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(this.aboveFarmlandPos));
+                        this.nextOkStartTime = i + 20L;
+                        entityvillager.getBrain().setMemory(MemoryModuleType.WALK_TARGET, (new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1))); // CraftBukkit - decompile error
+                        entityvillager.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, (new BlockPosTracker(this.aboveFarmlandPos))); // CraftBukkit - decompile error
                     }
                 }
             }
@@ -160,8 +170,7 @@
         }
     }
 
-    @Override
-    protected boolean canStillUse(ServerLevel serverLevel, Villager villager, long l) {
+    protected boolean canStillUse(ServerLevel worldserver, Villager entityvillager, long i) {
         return this.timeWorkedSoFar < 200;
     }
 }
