--- a/net/minecraft/world/entity/PathfinderMob.java
+++ b/net/minecraft/world/entity/PathfinderMob.java
@@ -1,5 +1,6 @@
 package net.minecraft.world.entity;
 
+import java.util.Iterator;
 import net.minecraft.core.BlockPos;
 import net.minecraft.world.entity.ai.goal.Goal;
 import net.minecraft.world.entity.ai.goal.PanicGoal;
@@ -9,14 +10,21 @@
 import net.minecraft.world.level.LevelAccessor;
 import net.minecraft.world.level.LevelReader;
 import net.minecraft.world.phys.Vec3;
+// CraftBukkit start
+import org.bukkit.event.entity.EntityUnleashEvent;
+// CraftBukkit end
 
 public abstract class PathfinderMob extends Mob {
+
     protected static final float DEFAULT_WALK_TARGET_VALUE = 0.0F;
 
     protected PathfinderMob(EntityType<? extends PathfinderMob> type, Level world) {
         super(type, world);
     }
 
+    public org.bukkit.craftbukkit.entity.CraftCreature getBukkitCreature() { return (org.bukkit.craftbukkit.entity.CraftCreature) super.getBukkitEntity(); } // Paper
+    public BlockPos movingTarget = null; public BlockPos getMovingTarget() { return movingTarget; } // Paper
+
     public float getWalkTargetValue(BlockPos pos) {
         return this.getWalkTargetValue(pos, this.level());
     }
@@ -38,13 +46,19 @@
         if (this.brain.hasMemoryValue(MemoryModuleType.IS_PANICKING)) {
             return this.brain.getMemory(MemoryModuleType.IS_PANICKING).isPresent();
         } else {
-            for (WrappedGoal wrappedGoal : this.goalSelector.getAvailableGoals()) {
-                if (wrappedGoal.isRunning() && wrappedGoal.getGoal() instanceof PanicGoal) {
-                    return true;
+            Iterator iterator = this.goalSelector.getAvailableGoals().iterator();
+
+            WrappedGoal pathfindergoalwrapped;
+
+            do {
+                if (!iterator.hasNext()) {
+                    return false;
                 }
-            }
 
-            return false;
+                pathfindergoalwrapped = (WrappedGoal) iterator.next();
+            } while (!pathfindergoalwrapped.isRunning() || !(pathfindergoalwrapped.getGoal() instanceof PanicGoal));
+
+            return true;
         }
     }
 
@@ -58,12 +72,12 @@
         if (this.shouldStayCloseToLeashHolder() && !this.isPanicking()) {
             this.goalSelector.enableControlFlag(Goal.Flag.MOVE);
             float f = 2.0F;
-            float g = this.distanceTo(entity);
-            Vec3 vec3 = new Vec3(entity.getX() - this.getX(), entity.getY() - this.getY(), entity.getZ() - this.getZ())
-                .normalize()
-                .scale((double)Math.max(g - 2.0F, 0.0F));
-            this.getNavigation().moveTo(this.getX() + vec3.x, this.getY() + vec3.y, this.getZ() + vec3.z, this.followLeashSpeed());
+            float f1 = this.distanceTo(entity);
+            Vec3 vec3d = (new Vec3(entity.getX() - this.getX(), entity.getY() - this.getY(), entity.getZ() - this.getZ())).normalize().scale((double) Math.max(f1 - 2.0F, 0.0F));
+
+            this.getNavigation().moveTo(this.getX() + vec3d.x, this.getY() + vec3d.y, this.getZ() + vec3d.z, this.followLeashSpeed());
         }
+
     }
 
     @Override
@@ -73,6 +87,6 @@
     }
 
     protected double followLeashSpeed() {
-        return 1.0;
+        return 1.0D;
     }
 }
