--- a/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
+++ b/net/minecraft/world/entity/ai/behavior/HarvestFarmland.java
@@ -21,12 +21,18 @@
 import net.minecraft.world.item.ItemStack;
 import net.minecraft.world.level.GameRules;
 import net.minecraft.world.level.block.Block;
+import net.minecraft.world.level.gameevent.GameEvent;
+
+// CraftBukkit start
+import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.block.CropBlock;
 import net.minecraft.world.level.block.FarmBlock;
 import net.minecraft.world.level.block.state.BlockState;
-import net.minecraft.world.level.gameevent.GameEvent;
+import org.bukkit.craftbukkit.v1_20_R2.event.CraftEventFactory;
+// CraftBukkit end
 
 public class HarvestFarmland extends Behavior<Villager> {
+
     private static final int HARVEST_DURATION = 200;
     public static final float SPEED_MODIFIER = 0.5F;
     @Nullable
@@ -39,22 +45,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));
                         }
                     }
                 }
@@ -67,26 +73,25 @@
 
     @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 serverLevel, Villager villager, long l) {
-        if (l > this.nextOkStartTime && this.aboveFarmlandPos != null) {
-            villager.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, new BlockPosTracker(this.aboveFarmlandPos));
-            villager.getBrain().setMemory(MemoryModuleType.WALK_TARGET, new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1));
+    protected void start(ServerLevel worldserver, Villager entityvillager, long i) {
+        if (i > this.nextOkStartTime && this.aboveFarmlandPos != null) {
+            entityvillager.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, (new BlockPosTracker(this.aboveFarmlandPos))); // CraftBukkit - decompile error
+            entityvillager.getBrain().setMemory(MemoryModuleType.WALK_TARGET, (new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1))); // CraftBukkit - decompile error
         }
 
     }
 
-    @Override
     protected void stop(ServerLevel world, Villager entity, long time) {
         entity.getBrain().eraseMemory(MemoryModuleType.LOOK_TARGET);
         entity.getBrain().eraseMemory(MemoryModuleType.WALK_TARGET);
@@ -94,52 +99,59 @@
         this.nextOkStartTime = time + 40L;
     }
 
-    @Override
     protected void tick(ServerLevel world, Villager entity, long time) {
         if (this.aboveFarmlandPos == null || this.aboveFarmlandPos.closerToCenterThan(entity.position(), 1.0D)) {
             if (this.aboveFarmlandPos != null && time > this.nextOkStartTime) {
-                BlockState blockState = world.getBlockState(this.aboveFarmlandPos);
-                Block block = blockState.getBlock();
-                Block block2 = world.getBlockState(this.aboveFarmlandPos.below()).getBlock();
-                if (block instanceof CropBlock && ((CropBlock)block).isMaxAge(blockState)) {
+                BlockState iblockdata = world.getBlockState(this.aboveFarmlandPos);
+                Block block = iblockdata.getBlock();
+                Block block1 = world.getBlockState(this.aboveFarmlandPos.below()).getBlock();
+
+                if (block instanceof CropBlock && ((CropBlock) block).isMaxAge(iblockdata)) {
+                    if (CraftEventFactory.callEntityChangeBlockEvent(entity, this.aboveFarmlandPos, iblockdata.getFluidState().createLegacyBlock())) { // CraftBukkit // Paper - fix wrong block state
                     world.destroyBlock(this.aboveFarmlandPos, true, entity);
+                    } // CraftBukkit
                 }
 
-                if (blockState.isAir() && block2 instanceof FarmBlock && entity.hasFarmSeeds()) {
-                    SimpleContainer simpleContainer = entity.getInventory();
+                if (iblockdata.isAir() && block1 instanceof FarmBlock && entity.hasFarmSeeds()) {
+                    SimpleContainer inventorysubcontainer = entity.getInventory();
 
-                    for(int i = 0; i < simpleContainer.getContainerSize(); ++i) {
-                        ItemStack itemStack = simpleContainer.getItem(i);
-                        boolean bl = false;
-                        if (!itemStack.isEmpty() && itemStack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS)) {
-                            Item blockState2 = itemStack.getItem();
-                            if (blockState2 instanceof BlockItem) {
-                                BlockItem blockItem = (BlockItem)blockState2;
-                                BlockState blockState2 = blockItem.getBlock().defaultBlockState();
-                                world.setBlockAndUpdate(this.aboveFarmlandPos, blockState2);
-                                world.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(entity, blockState2));
-                                bl = true;
+                    for (int j = 0; j < inventorysubcontainer.getContainerSize(); ++j) {
+                        ItemStack itemstack = inventorysubcontainer.getItem(j);
+                        boolean flag = false;
+
+                        if (!itemstack.isEmpty() && itemstack.is(ItemTags.VILLAGER_PLANTABLE_SEEDS)) {
+                            Item item = itemstack.getItem();
+
+                            if (item instanceof BlockItem) {
+                                BlockItem itemblock = (BlockItem) item;
+                                BlockState iblockdata1 = itemblock.getBlock().defaultBlockState();
+
+                                if (CraftEventFactory.callEntityChangeBlockEvent(entity, this.aboveFarmlandPos, iblockdata1)) { // CraftBukkit
+                                world.setBlockAndUpdate(this.aboveFarmlandPos, iblockdata1);
+                                world.gameEvent(GameEvent.BLOCK_PLACE, this.aboveFarmlandPos, GameEvent.Context.of(entity, iblockdata1));
+                                flag = true;
+                                } // CraftBukkit
                             }
                         }
 
-                        if (bl) {
-                            world.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) {
+                            world.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(world);
                     if (this.aboveFarmlandPos != null) {
                         this.nextOkStartTime = time + 20L;
-                        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));
+                        entity.getBrain().setMemory(MemoryModuleType.WALK_TARGET, (new WalkTarget(new BlockPosTracker(this.aboveFarmlandPos), 0.5F, 1))); // CraftBukkit - decompile error
+                        entity.getBrain().setMemory(MemoryModuleType.LOOK_TARGET, (new BlockPosTracker(this.aboveFarmlandPos))); // CraftBukkit - decompile error
                     }
                 }
             }
@@ -148,8 +160,7 @@
         }
     }
 
-    @Override
-    protected boolean canStillUse(ServerLevel serverLevel, Villager villager, long l) {
+    protected boolean canStillUse(ServerLevel worldserver, Villager entityvillager, long i) {
         return this.timeWorkedSoFar < 200;
     }
 }
