From dfc592aec5aecf075597e6c153589794e928c958 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Tue, 11 May 2021 18:33:28 +1000 Subject: [PATCH] SPIGOT-6224: EntityBreedEvent getEntity location inaccuracy By: Martoph --- .../entity/ai/behavior/BehaviorMakeLove.patch | 23 +++++++++---------- .../world/entity/animal/EntityAnimal.patch | 12 ++++++---- .../world/entity/animal/EntityFox.patch | 12 ++++++---- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch index 8cd6dfda6c..44bcab15b3 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.patch @@ -1,22 +1,21 @@ --- a/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.java +++ b/net/minecraft/world/entity/ai/behavior/BehaviorMakeLove.java -@@ -106,6 +106,11 @@ - - private Optional b(WorldServer worldserver, EntityVillager entityvillager, EntityVillager entityvillager1) { - EntityVillager entityvillager2 = entityvillager.createChild(worldserver, entityvillager1); -+ // CraftBukkit start - call EntityBreedEvent -+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityvillager2, entityvillager, entityvillager1, null, null, 0).isCancelled()) { -+ return Optional.empty(); -+ } -+ // CraftBukkit end - +@@ -110,11 +110,16 @@ if (entityvillager2 == null) { return Optional.empty(); -@@ -114,7 +119,7 @@ - entityvillager1.setAgeRaw(6000); + } else { +- entityvillager.setAgeRaw(6000); +- entityvillager1.setAgeRaw(6000); ++ // CraftBukkit start - call EntityBreedEvent entityvillager2.setAgeRaw(-24000); entityvillager2.setPositionRotation(entityvillager.locX(), entityvillager.locY(), entityvillager.locZ(), 0.0F, 0.0F); - worldserver.addAllEntities(entityvillager2); ++ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityvillager2, entityvillager, entityvillager1, null, null, 0).isCancelled()) { ++ return Optional.empty(); ++ } ++ // CraftBukkit end ++ entityvillager.setAgeRaw(6000); ++ entityvillager1.setAgeRaw(6000); + worldserver.addAllEntities(entityvillager2, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason worldserver.broadcastEntityEffect(entityvillager2, (byte) 12); return Optional.of(entityvillager2); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch index 420e983ac8..58dec6a027 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityAnimal.patch @@ -55,7 +55,7 @@ this.world.broadcastEntityEffect(this, (byte) 18); } -@@ -209,11 +227,24 @@ +@@ -209,11 +227,26 @@ EntityAgeable entityageable = this.createChild(worldserver, entityanimal); if (entityageable != null) { @@ -70,6 +70,8 @@ entityplayer = entityanimal.getBreedCause(); } + // CraftBukkit start - call EntityBreedEvent ++ entityageable.setBaby(true); ++ entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F); + int experience = this.getRandom().nextInt(7) + 1; + org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, entityanimal, entityplayer, this.breedItem, experience); + if (entityBreedEvent.isCancelled()) { @@ -80,10 +82,12 @@ if (entityplayer != null) { entityplayer.a(StatisticList.ANIMALS_BRED); -@@ -226,10 +257,14 @@ +@@ -224,12 +257,14 @@ + entityanimal.setAgeRaw(6000); + this.resetLove(); entityanimal.resetLove(); - entityageable.setBaby(true); - entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F); +- entityageable.setBaby(true); +- entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F); - worldserver.addAllEntities(entityageable); + worldserver.addAllEntities(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason worldserver.broadcastEntityEffect(this, (byte) 18); diff --git a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch index b3d471346c..1404ae829a 100644 --- a/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch +++ b/paper-server/nms-patches/net/minecraft/world/entity/animal/EntityFox.patch @@ -60,11 +60,13 @@ super(EntityFox.this, oclass, 10, flag, flag1, predicate); } -@@ -1275,6 +1281,14 @@ +@@ -1275,6 +1281,16 @@ if (entityplayer1 != null && entityplayer != entityplayer1) { entityfox.b(entityplayer1.getUniqueID()); } + // CraftBukkit start - call EntityBreedEvent ++ entityfox.setAgeRaw(-24000); ++ entityfox.setPositionRotation(this.animal.locX(), this.animal.locY(), this.animal.locZ(), 0.0F, 0.0F); + int experience = this.animal.getRandom().nextInt(7) + 1; + org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityfox, animal, partner, entityplayer, this.animal.breedItem, experience); + if (entityBreedEvent.isCancelled()) { @@ -75,10 +77,12 @@ if (entityplayer2 != null) { entityplayer2.a(StatisticList.ANIMALS_BRED); -@@ -1287,10 +1301,14 @@ +@@ -1285,12 +1301,14 @@ + this.partner.setAgeRaw(6000); + this.animal.resetLove(); this.partner.resetLove(); - entityfox.setAgeRaw(-24000); - entityfox.setPositionRotation(this.animal.locX(), this.animal.locY(), this.animal.locZ(), 0.0F, 0.0F); +- entityfox.setAgeRaw(-24000); +- entityfox.setPositionRotation(this.animal.locX(), this.animal.locY(), this.animal.locZ(), 0.0F, 0.0F); - worldserver.addAllEntities(entityfox); + worldserver.addAllEntities(entityfox, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason this.b.broadcastEntityEffect(this.animal, (byte) 18);