2023-03-04 23:23:32 +01:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Fri, 24 Jun 2022 12:39:34 +0200
Subject: [PATCH] Add EntityFertilizeEggEvent
diff --git a/src/main/java/net/minecraft/world/entity/animal/Turtle.java b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
2024-10-24 00:32:21 +02:00
index ed7f5eb9b3b700c2f817d61ee0bf8a6952731510..8e91f930e19a91db44274e4ecd98841362867609 100644
2023-03-04 23:23:32 +01:00
--- a/src/main/java/net/minecraft/world/entity/animal/Turtle.java
+++ b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
2024-10-24 00:32:21 +02:00
@@ -448,6 +448,10 @@ public class Turtle extends Animal {
2023-03-04 23:23:32 +01:00
if (entityplayer == null && this.partner.getLoveCause() != null) {
entityplayer = this.partner.getLoveCause();
}
2023-06-09 09:01:08 +02:00
+ // Paper start - Add EntityFertilizeEggEvent event
+ io.papermc.paper.event.entity.EntityFertilizeEggEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityFertilizeEggEvent(this.animal, this.partner);
+ if (event.isCancelled()) return;
+ // Paper end - Add EntityFertilizeEggEvent event
2023-03-04 23:23:32 +01:00
if (entityplayer != null) {
entityplayer.awardStat(Stats.ANIMALS_BRED);
2024-10-24 00:32:21 +02:00
@@ -462,7 +466,7 @@ public class Turtle extends Animal {
2023-06-09 09:01:08 +02:00
RandomSource randomsource = this.animal.getRandom();
2023-03-04 23:23:32 +01:00
2024-10-24 00:32:21 +02:00
if (getServerLevel((Level) this.level).getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
2023-03-04 23:23:32 +01:00
- this.level.addFreshEntity(new ExperienceOrb(this.level, this.animal.getX(), this.animal.getY(), this.animal.getZ(), randomsource.nextInt(7) + 1, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, entityplayer)); // Paper;
2024-10-24 00:32:21 +02:00
+ if (event.getExperience() > 0) this.level.addFreshEntity(new ExperienceOrb(this.level, this.animal.getX(), this.animal.getY(), this.animal.getZ(), randomsource.nextInt(7) + 1, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, entityplayer)); // Paper - Add EntityFertilizeEggEvent event
2023-03-04 23:23:32 +01:00
}
}
2023-06-09 09:01:08 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java b/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
2024-10-24 00:32:21 +02:00
index 100be2ed533450eda32d9c4eb9eb1067846d1516..36846ba6b6c7494c745ebd8b221479a9d02ff318 100644
2023-06-09 09:01:08 +02:00
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
2024-10-24 00:32:21 +02:00
@@ -270,7 +270,12 @@ public class Frog extends Animal implements VariantHolder<Holder<FrogVariant>> {
2023-06-09 09:01:08 +02:00
@Override
public void spawnChildFromBreeding(ServerLevel world, Animal other) {
2024-04-12 21:14:06 +02:00
- this.finalizeSpawnChildFromBreeding(world, other, null);
2023-06-09 09:01:08 +02:00
+ // Paper start - Add EntityFertilizeEggEvent event
+ final io.papermc.paper.event.entity.EntityFertilizeEggEvent result = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityFertilizeEggEvent(this, other);
+ if (result.isCancelled()) return;
+
2024-04-12 21:14:06 +02:00
+ this.finalizeSpawnChildFromBreeding(world, other, null, result.getExperience()); // Paper - use craftbukkit call that takes experience amount
2023-06-09 09:01:08 +02:00
+ // Paper end - Add EntityFertilizeEggEvent event
this.getBrain().setMemory(MemoryModuleType.IS_PREGNANT, Unit.INSTANCE);
}
diff --git a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
2024-10-24 00:32:21 +02:00
index 0395b120590552518a85f36a46b68532e936de49..7f70237a274fde0fb97880c1d47246157e3b3415 100644
2023-06-09 09:01:08 +02:00
--- a/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
+++ b/src/main/java/net/minecraft/world/entity/animal/sniffer/Sniffer.java
2024-10-24 00:32:21 +02:00
@@ -340,11 +340,16 @@ public class Sniffer extends Animal {
2023-06-09 09:01:08 +02:00
@Override
public void spawnChildFromBreeding(ServerLevel world, Animal other) {
+ // Paper start - Add EntityFertilizeEggEvent event
+ final io.papermc.paper.event.entity.EntityFertilizeEggEvent result = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityFertilizeEggEvent(this, other);
+ if (result.isCancelled()) return;
+ // Paper end - Add EntityFertilizeEggEvent event
+
ItemStack itemstack = new ItemStack(Items.SNIFFER_EGG);
ItemEntity entityitem = new ItemEntity(world, this.position().x(), this.position().y(), this.position().z(), itemstack);
entityitem.setDefaultPickUpDelay();
- this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null);
+ this.finalizeSpawnChildFromBreeding(world, other, (AgeableMob) null, result.getExperience()); // Paper - Add EntityFertilizeEggEvent event
2024-01-18 15:56:25 +01:00
if (this.spawnAtLocation(entityitem) != null) { // Paper - Call EntityDropItemEvent
2023-06-09 09:01:08 +02:00
this.playSound(SoundEvents.SNIFFER_EGG_PLOP, 1.0F, (this.random.nextFloat() - this.random.nextFloat()) * 0.2F + 0.5F);
2024-01-18 15:56:25 +01:00
} // Paper - Call EntityDropItemEvent
2023-06-09 09:01:08 +02:00
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-10-24 00:32:21 +02:00
index cb05a94f2856a8bfb478bceb7c8712bc5e7ad5c2..145a278a1b6d9e79c27136e84d8ccea8834c07bc 100644
2023-06-09 09:01:08 +02:00
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
2024-10-24 00:32:21 +02:00
@@ -2195,4 +2195,28 @@ populateFields(victim, event); // Paper - make cancellable
2023-06-09 09:01:08 +02:00
return event.callEvent();
}
// Paper end
+
+ // Paper start - add EntityFertilizeEggEvent
+ /**
2024-02-01 10:15:57 +01:00
+ * Calls the {@link io.papermc.paper.event.entity.EntityFertilizeEggEvent}.
2023-06-09 09:01:08 +02:00
+ * If the event is cancelled, this method also resets the love on both the {@code breeding} and {@code other} entity.
+ *
+ * @param breeding the entity on which #spawnChildFromBreeding was called.
+ * @param other the partner of the entity.
+ * @return the event after it was called. The instance may be used to retrieve the experience of the event.
+ */
2024-02-01 10:15:57 +01:00
+ public static io.papermc.paper.event.entity.EntityFertilizeEggEvent callEntityFertilizeEggEvent(Animal breeding, Animal other) {
+ ServerPlayer serverPlayer = breeding.getLoveCause();
2023-06-09 09:01:08 +02:00
+ if (serverPlayer == null) serverPlayer = other.getLoveCause();
+ final int experience = breeding.getRandom().nextInt(7) + 1; // From Animal#spawnChildFromBreeding(ServerLevel, Animal)
+
2024-02-01 10:15:57 +01:00
+ final io.papermc.paper.event.entity.EntityFertilizeEggEvent event = new io.papermc.paper.event.entity.EntityFertilizeEggEvent((LivingEntity) breeding.getBukkitEntity(), (LivingEntity) other.getBukkitEntity(), serverPlayer == null ? null : serverPlayer.getBukkitEntity(), breeding.breedItem == null ? null : CraftItemStack.asCraftMirror(breeding.breedItem).clone(), experience);
2023-06-09 09:01:08 +02:00
+ if (!event.callEvent()) {
+ breeding.resetLove();
+ other.resetLove(); // stop the pathfinding to avoid infinite loop
+ }
+
+ return event;
+ }
+ // Paper end - add EntityFertilizeEggEvent
}