aboutsummaryrefslogtreecommitdiffhomepage
path: root/paper-server/patches/sources/net/minecraft/world/entity/Mob.java.patch
blob: aeaafc3a1b9e30a3162844274f33f42512d57daa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
--- a/net/minecraft/world/entity/Mob.java
+++ b/net/minecraft/world/entity/Mob.java
@@ -84,6 +84,17 @@
 import net.minecraft.world.level.storage.loot.parameters.LootContextParamSets;
 import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
 import net.minecraft.world.phys.AABB;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.entity.CraftLivingEntity;
+import org.bukkit.event.entity.CreatureSpawnEvent;
+import org.bukkit.event.entity.EntityRemoveEvent;
+import org.bukkit.event.entity.EntityTargetLivingEntityEvent;
+import org.bukkit.event.entity.EntityTargetEvent;
+import org.bukkit.event.entity.EntityTransformEvent;
+import org.bukkit.event.entity.EntityUnleashEvent;
+import org.bukkit.event.entity.EntityUnleashEvent.UnleashReason;
+// CraftBukkit end
 
 public abstract class Mob extends LivingEntity implements EquipmentUser, Leashable, Targeting {
 
@@ -112,6 +123,7 @@
     private final BodyRotationControl bodyRotationControl;
     protected PathNavigation navigation;
     public GoalSelector goalSelector;
+    @Nullable public net.minecraft.world.entity.ai.goal.FloatGoal goalFloat; // Paper - Allow nerfed mobs to jump and float
     public GoalSelector targetSelector;
     @Nullable
     private LivingEntity target;
@@ -132,6 +144,8 @@
     private BlockPos restrictCenter;
     private float restrictRadius;
 
+    public boolean aware = true; // CraftBukkit
+
     protected Mob(EntityType<? extends Mob> type, Level world) {
         super(type, world);
         this.handItems = NonNullList.withSize(2, ItemStack.EMPTY);
@@ -157,8 +171,14 @@
         if (world instanceof ServerLevel) {
             this.registerGoals();
         }
+
+    }
 
+    // CraftBukkit start
+    public void setPersistenceRequired(boolean persistenceRequired) {
+        this.persistenceRequired = persistenceRequired;
     }
+    // CraftBukkit end
 
     protected void registerGoals() {}
 
@@ -264,13 +284,44 @@
 
     @Nullable
     protected final LivingEntity getTargetFromBrain() {
-        return (LivingEntity) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse((Object) null);
+        return (LivingEntity) this.getBrain().getMemory(MemoryModuleType.ATTACK_TARGET).orElse(null); // CraftBukkit - decompile error
     }
 
     public void setTarget(@Nullable LivingEntity target) {
-        this.target = target;
+        // CraftBukkit start - fire event
+        this.setTarget(target, EntityTargetEvent.TargetReason.UNKNOWN, true);
     }
 
+    public boolean setTarget(LivingEntity entityliving, EntityTargetEvent.TargetReason reason, boolean fireEvent) {
+        if (this.getTarget() == entityliving) return false;
+        if (fireEvent) {
+            if (reason == EntityTargetEvent.TargetReason.UNKNOWN && this.getTarget() != null && entityliving == null) {
+                reason = this.getTarget().isAlive() ? EntityTargetEvent.TargetReason.FORGOT_TARGET : EntityTargetEvent.TargetReason.TARGET_DIED;
+            }
+            if (reason == EntityTargetEvent.TargetReason.UNKNOWN) {
+                this.level().getCraftServer().getLogger().log(java.util.logging.Level.WARNING, "Unknown target reason, please report on the issue tracker", new Exception());
+            }
+            CraftLivingEntity ctarget = null;
+            if (entityliving != null) {
+                ctarget = (CraftLivingEntity) entityliving.getBukkitEntity();
+            }
+            EntityTargetLivingEntityEvent event = new EntityTargetLivingEntityEvent(this.getBukkitEntity(), ctarget, reason);
+            this.level().getCraftServer().getPluginManager().callEvent(event);
+            if (event.isCancelled()) {
+                return false;
+            }
+
+            if (event.getTarget() != null) {
+                entityliving = ((CraftLivingEntity) event.getTarget()).getHandle();
+            } else {
+                entityliving = null;
+            }
+        }
+        this.target = entityliving;
+        return true;
+        // CraftBukkit end
+    }
+
     @Override
     public boolean canAttackType(EntityType<?> type) {
         return type != EntityType.GHAST;
@@ -399,6 +450,12 @@
         return null;
     }
 
+    // CraftBukkit start - Add delegate method
+    public SoundEvent getAmbientSound0() {
+        return this.getAmbientSound();
+    }
+    // CraftBukkit end
+
     @Override
     public void addAdditionalSaveData(CompoundTag nbt) {
         super.addAdditionalSaveData(nbt);
@@ -473,13 +530,25 @@
             nbt.putBoolean("NoAI", this.isNoAi());
         }
 
+        nbt.putBoolean("Bukkit.Aware", this.aware); // CraftBukkit
     }
 
     @Override
     public void readAdditionalSaveData(CompoundTag nbt) {
         super.readAdditionalSaveData(nbt);
-        this.setCanPickUpLoot(nbt.getBoolean("CanPickUpLoot"));
-        this.persistenceRequired = nbt.getBoolean("PersistenceRequired");
+        // CraftBukkit start - If looting or persistence is false only use it if it was set after we started using it
+        if (nbt.contains("CanPickUpLoot", 99)) {
+            boolean data = nbt.getBoolean("CanPickUpLoot");
+            if (isLevelAtLeast(nbt, 1) || data) {
+                this.setCanPickUpLoot(data);
+            }
+        }
+
+        boolean data = nbt.getBoolean("PersistenceRequired");
+        if (isLevelAtLeast(nbt, 1) || data) {
+            this.persistenceRequired = data;
+        }
+        // CraftBukkit end
         ListTag nbttaglist;
         CompoundTag nbttagcompound1;
         int i;
@@ -540,13 +609,18 @@
         this.readLeashData(nbt);
         this.setLeftHanded(nbt.getBoolean("LeftHanded"));
         if (nbt.contains("DeathLootTable", 8)) {
-            this.lootTable = Optional.of(ResourceKey.create(Registries.LOOT_TABLE, ResourceLocation.parse(nbt.getString("DeathLootTable"))));
+            this.lootTable = Optional.ofNullable(ResourceLocation.tryParse(nbt.getString("DeathLootTable"))).map((rs) -> ResourceKey.create(Registries.LOOT_TABLE, rs)); // Paper - Validate ResourceLocation
         } else {
             this.lootTable = Optional.empty();
         }
 
         this.lootTableSeed = nbt.getLong("DeathLootTableSeed");
         this.setNoAi(nbt.getBoolean("NoAI"));
+        // CraftBukkit start
+        if (nbt.contains("Bukkit.Aware")) {
+            this.aware = nbt.getBoolean("Bukkit.Aware");
+        }
+        // CraftBukkit end
     }
 
     @Override
@@ -608,6 +682,11 @@
                     ItemEntity entityitem = (ItemEntity) iterator.next();
 
                     if (!entityitem.isRemoved() && !entityitem.getItem().isEmpty() && !entityitem.hasPickUpDelay() && this.wantsToPickUp(worldserver, entityitem.getItem())) {
+                        // Paper start - Item#canEntityPickup
+                        if (!entityitem.canMobPickup) {
+                            continue;
+                        }
+                        // Paper end - Item#canEntityPickup
                         this.pickUpItem(worldserver, entityitem);
                     }
                 }
@@ -623,23 +702,29 @@
 
     protected void pickUpItem(ServerLevel world, ItemEntity itemEntity) {
         ItemStack itemstack = itemEntity.getItem();
-        ItemStack itemstack1 = this.equipItemIfPossible(world, itemstack.copy());
+        ItemStack itemstack1 = this.equipItemIfPossible(world, itemstack.copy(), itemEntity); // CraftBukkit - add item
 
         if (!itemstack1.isEmpty()) {
             this.onItemPickup(itemEntity);
             this.take(itemEntity, itemstack1.getCount());
             itemstack.shrink(itemstack1.getCount());
             if (itemstack.isEmpty()) {
-                itemEntity.discard();
+                itemEntity.discard(EntityRemoveEvent.Cause.PICKUP); // CraftBukkit - add Bukkit remove cause
             }
         }
 
     }
 
     public ItemStack equipItemIfPossible(ServerLevel world, ItemStack stack) {
-        EquipmentSlot enumitemslot = this.getEquipmentSlotForItem(stack);
+        // CraftBukkit start - add item
+        return this.equipItemIfPossible(world, stack, null);
+    }
+
+    public ItemStack equipItemIfPossible(ServerLevel worldserver, ItemStack itemstack, ItemEntity entityitem) {
+        // CraftBukkit end
+        EquipmentSlot enumitemslot = this.getEquipmentSlotForItem(itemstack);
         ItemStack itemstack1 = this.getItemBySlot(enumitemslot);
-        boolean flag = this.canReplaceCurrentItem(stack, itemstack1, enumitemslot);
+        boolean flag = this.canReplaceCurrentItem(itemstack, itemstack1, enumitemslot);
 
         if (enumitemslot.isArmor() && !flag) {
             enumitemslot = EquipmentSlot.MAINHAND;
@@ -647,14 +732,22 @@
             flag = itemstack1.isEmpty();
         }
 
-        if (flag && this.canHoldItem(stack)) {
+        // CraftBukkit start
+        boolean canPickup = flag && this.canHoldItem(itemstack);
+        if (entityitem != null) {
+            canPickup = !org.bukkit.craftbukkit.event.CraftEventFactory.callEntityPickupItemEvent(this, entityitem, 0, !canPickup).isCancelled();
+        }
+        if (canPickup) {
+            // CraftBukkit end
             double d0 = (double) this.getEquipmentDropChance(enumitemslot);
 
             if (!itemstack1.isEmpty() && (double) Math.max(this.random.nextFloat() - 0.1F, 0.0F) < d0) {
-                this.spawnAtLocation(world, itemstack1);
+                this.forceDrops = true; // CraftBukkit
+                this.spawnAtLocation(worldserver, itemstack1);
+                this.forceDrops = false; // CraftBukkit
             }
 
-            ItemStack itemstack2 = enumitemslot.limit(stack);
+            ItemStack itemstack2 = enumitemslot.limit(itemstack);
 
             this.setItemSlotAndDropWhenKilled(enumitemslot, itemstack2);
             return itemstack2;
@@ -768,25 +861,29 @@
     @Override
     public void checkDespawn() {
         if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {
-            this.discard();
+            this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
         } else if (!this.isPersistenceRequired() && !this.requiresCustomPersistence()) {
-            Player entityhuman = this.level().getNearestPlayer(this, -1.0D);
+            Player entityhuman = this.level().findNearbyPlayer(this, -1.0D, EntitySelector.PLAYER_AFFECTS_SPAWNING); // Paper - Affects Spawning API
 
             if (entityhuman != null) {
-                double d0 = entityhuman.distanceToSqr((Entity) this);
-                int i = this.getType().getCategory().getDespawnDistance();
-                int j = i * i;
-
-                if (d0 > (double) j && this.removeWhenFarAway(d0)) {
-                    this.discard();
+                // Paper start - Configurable despawn distances
+                final io.papermc.paper.configuration.WorldConfiguration.Entities.Spawning.DespawnRangePair despawnRangePair = this.level().paperConfig().entities.spawning.despawnRanges.get(this.getType().getCategory());
+                final io.papermc.paper.configuration.type.DespawnRange.Shape shape = this.level().paperConfig().entities.spawning.despawnRangeShape;
+                final double dy = Math.abs(entityhuman.getY() - this.getY());
+                final double dySqr = Math.pow(dy, 2);
+                final double dxSqr = Math.pow(entityhuman.getX() - this.getX(), 2);
+                final double dzSqr = Math.pow(entityhuman.getZ() - this.getZ(), 2);
+                final double distanceSquared = dxSqr + dzSqr + dySqr;
+                // Despawn if hard/soft limit is exceeded
+                if (despawnRangePair.hard().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy) && this.removeWhenFarAway(distanceSquared)) {
+                    this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
                 }
-
-                int k = this.getType().getCategory().getNoDespawnDistance();
-                int l = k * k;
-
-                if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && d0 > (double) l && this.removeWhenFarAway(d0)) {
-                    this.discard();
-                } else if (d0 < (double) l) {
+                if (despawnRangePair.soft().shouldDespawn(shape, dxSqr, dySqr, dzSqr, dy)) {
+                    if (this.noActionTime > 600 && this.random.nextInt(800) == 0 && this.removeWhenFarAway(distanceSquared)) {
+                        this.discard(EntityRemoveEvent.Cause.DESPAWN); // CraftBukkit - add Bukkit remove cause
+                    }
+                } else {
+                // Paper end - Configurable despawn distances
                     this.noActionTime = 0;
                 }
             }
@@ -799,6 +896,15 @@
     @Override
     protected final void serverAiStep() {
         ++this.noActionTime;
+        // Paper start - Allow nerfed mobs to jump and float
+        if (!this.aware) {
+            if (goalFloat != null) {
+                if (goalFloat.canUse()) goalFloat.tick();
+                this.getJumpControl().tick();
+            }
+            return;
+        }
+        // Paper end - Allow nerfed mobs to jump and float
         ProfilerFiller gameprofilerfiller = Profiler.get();
 
         gameprofilerfiller.push("sensing");
@@ -994,23 +1100,36 @@
 
     @Override
     public void setItemSlot(EquipmentSlot slot, ItemStack stack) {
+        // Paper start - Fix silent equipment change
+        setItemSlot(slot, stack, false);
+    }
+
+    @Override
+    public void setItemSlot(EquipmentSlot slot, ItemStack stack, boolean silent) {
+        // Paper end - Fix silent equipment change
         this.verifyEquippedItem(stack);
         switch (slot.getType()) {
             case HAND:
-                this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack);
+                this.onEquipItem(slot, (ItemStack) this.handItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
                 break;
             case HUMANOID_ARMOR:
-                this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack);
+                this.onEquipItem(slot, (ItemStack) this.armorItems.set(slot.getIndex(), stack), stack, silent); // Paper - Fix silent equipment change
                 break;
             case ANIMAL_ARMOR:
                 ItemStack itemstack1 = this.bodyArmorItem;
 
                 this.bodyArmorItem = stack;
-                this.onEquipItem(slot, itemstack1, stack);
+                this.onEquipItem(slot, itemstack1, stack, silent); // Paper - Fix silent equipment change
         }
 
     }
 
+    // Paper start
+    protected boolean shouldSkipLoot(EquipmentSlot slot) { // method to avoid to fallback into the global mob loot logic (i.e fox)
+        return false;
+    }
+    // Paper end
+
     @Override
     protected void dropCustomDeathLoot(ServerLevel world, DamageSource source, boolean causedByPlayer) {
         super.dropCustomDeathLoot(world, source, causedByPlayer);
@@ -1018,6 +1137,7 @@
 
         while (iterator.hasNext()) {
             EquipmentSlot enumitemslot = (EquipmentSlot) iterator.next();
+            if (this.shouldSkipLoot(enumitemslot)) continue; // Paper
             ItemStack itemstack = this.getItemBySlot(enumitemslot);
             float f = this.getEquipmentDropChance(enumitemslot);
 
@@ -1042,7 +1162,13 @@
                     }
 
                     this.spawnAtLocation(world, itemstack);
+                    if (this.clearEquipmentSlots) { // Paper
                     this.setItemSlot(enumitemslot, ItemStack.EMPTY);
+                    // Paper start
+                    } else {
+                        this.clearedEquipmentSlots.add(enumitemslot);
+                    }
+                    // Paper end
                 }
             }
         }
@@ -1338,7 +1464,7 @@
         if (itemstack.getItem() instanceof SpawnEggItem) {
             if (this.level() instanceof ServerLevel) {
                 SpawnEggItem itemmonsteregg = (SpawnEggItem) itemstack.getItem();
-                Optional<Mob> optional = itemmonsteregg.spawnOffspringFromSpawnEgg(player, this, this.getType(), (ServerLevel) this.level(), this.position(), itemstack);
+                Optional<Mob> optional = itemmonsteregg.spawnOffspringFromSpawnEgg(player, this, (EntityType<? extends Mob>) this.getType(), (ServerLevel) this.level(), this.position(), itemstack); // CraftBukkit - decompile error
 
                 optional.ifPresent((entityinsentient) -> {
                     this.onOffspringSpawnedFromEgg(player, entityinsentient);
@@ -1389,28 +1515,51 @@
         return this.restrictRadius != -1.0F;
     }
 
+    // CraftBukkit start
     @Nullable
     public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, EntitySpawnReason reason, ConversionParams.AfterConversion<T> finalizer) {
+        return this.convertTo(entityType, context, reason, finalizer, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
+    }
+
+    @Nullable
+    public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+    // Paper start - entity zap event - allow cancellation of conversion post creation
+        return this.convertTo(entitytypes, conversionparams, entityspawnreason, e -> { conversionparams_a.finalizeConversion(e); return true; }, transformReason, spawnReason);
+    }
+    @Nullable
+    public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, EntitySpawnReason entityspawnreason, ConversionParams.CancellingAfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+    // Paper end - entity zap event - allow cancellation of conversion post creation
+        // CraftBukkit end
         if (this.isRemoved()) {
             return null;
         } else {
-            T t0 = (Mob) entityType.create(this.level(), reason);
+            T t0 = entitytypes.create(this.level(), EntitySpawnReason.CONVERSION); // CraftBukkit - decompile error
 
             if (t0 == null) {
                 return null;
             } else {
-                context.type().convert(this, t0, context);
-                finalizer.finalizeConversion(t0);
+                conversionparams.type().convert(this, t0, conversionparams);
+                if (!conversionparams_a.finalizeConversionOrCancel(t0)) return null; // Paper - entity zap event - return null if conversion was cancelled
                 Level world = this.level();
 
+                // CraftBukkit start
+                if (transformReason == null) {
+                    // Special handling for slime split and pig lightning
+                    return t0;
+                }
+
+                if (CraftEventFactory.callEntityTransformEvent(this, t0, transformReason).isCancelled()) {
+                    return null;
+                }
+                // CraftBukkit end
                 if (world instanceof ServerLevel) {
                     ServerLevel worldserver = (ServerLevel) world;
 
-                    worldserver.addFreshEntity(t0);
+                    worldserver.addFreshEntity(t0, spawnReason); // CraftBukkit
                 }
 
-                if (context.type().shouldDiscardAfterConversion()) {
-                    this.discard();
+                if (conversionparams.type().shouldDiscardAfterConversion()) {
+                    this.discard(EntityRemoveEvent.Cause.TRANSFORMATION); // CraftBukkit - add Bukkit remove cause
                 }
 
                 return t0;
@@ -1420,10 +1569,22 @@
 
     @Nullable
     public <T extends Mob> T convertTo(EntityType<T> entityType, ConversionParams context, ConversionParams.AfterConversion<T> finalizer) {
-        return this.convertTo(entityType, context, EntitySpawnReason.CONVERSION, finalizer);
+        // CraftBukkit start
+        return this.convertTo(entityType, context, finalizer, EntityTransformEvent.TransformReason.UNKNOWN, CreatureSpawnEvent.SpawnReason.DEFAULT);
     }
 
     @Nullable
+    public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, ConversionParams.AfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+    // Paper start - entity zap event - allow cancellation of conversion post creation
+        return this.convertTo(entitytypes, conversionparams, e -> { conversionparams_a.finalizeConversion(e); return true; }, transformReason, spawnReason);
+    }
+    public <T extends Mob> T convertTo(EntityType<T> entitytypes, ConversionParams conversionparams, ConversionParams.CancellingAfterConversion<T> conversionparams_a, EntityTransformEvent.TransformReason transformReason, CreatureSpawnEvent.SpawnReason spawnReason) {
+    // Paper start - entity zap event - allow cancellation of conversion post creation
+        return this.convertTo(entitytypes, conversionparams, EntitySpawnReason.CONVERSION, conversionparams_a, transformReason, spawnReason);
+        // CraftBukkit end
+    }
+
+    @Nullable
     @Override
     public Leashable.LeashData getLeashData() {
         return this.leashData;
@@ -1458,7 +1619,15 @@
         boolean flag1 = super.startRiding(entity, force);
 
         if (flag1 && this.isLeashed()) {
-            this.dropLeash();
+            // Paper start - Expand EntityUnleashEvent
+            EntityUnleashEvent event = new EntityUnleashEvent(this.getBukkitEntity(), EntityUnleashEvent.UnleashReason.UNKNOWN, true);
+            if (!event.callEvent()) { return flag1; }
+            if (event.isDropLeash()) {
+                this.dropLeash();
+            } else {
+                this.removeLeash();
+            }
+            // Paper end - Expand EntityUnleashEvent
         }
 
         return flag1;
@@ -1542,7 +1711,7 @@
 
             if (f1 > 0.0F && target instanceof LivingEntity) {
                 entityliving = (LivingEntity) target;
-                entityliving.knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)));
+                entityliving.knockback((double) (f1 * 0.5F), (double) Mth.sin(this.getYRot() * 0.017453292F), (double) (-Mth.cos(this.getYRot() * 0.017453292F)), this, io.papermc.paper.event.entity.EntityKnockbackEvent.Cause.ENTITY_ATTACK); // CraftBukkit // Paper - knockback events
                 this.setDeltaMovement(this.getDeltaMovement().multiply(0.6D, 1.0D, 0.6D));
             }