Paper/patches/api/0414-Add-EntityFertilizeEggEvent.patch

141 lines
3.9 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com>
Date: Fri, 24 Jun 2022 11:56:32 +0200
Subject: [PATCH] Add EntityFertilizeEggEvent
diff --git a/src/main/java/io/papermc/paper/event/entity/EntityFertilizeEggEvent.java b/src/main/java/io/papermc/paper/event/entity/EntityFertilizeEggEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..159b3b541991be34a5db856e3706a97afc8afb3d
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/entity/EntityFertilizeEggEvent.java
@@ -0,0 +1,128 @@
+package io.papermc.paper.event.entity;
+
+import com.google.common.base.Preconditions;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+import org.bukkit.inventory.ItemStack;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when a mating occurs that results in a pregnancy.
+ * After a bit of time, the mother will lay an egg.
+ */
+public class EntityFertilizeEggEvent extends EntityEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final LivingEntity mother;
+ private final LivingEntity father;
+ private final Player breeder;
+ private final ItemStack bredWith;
+ private int experience;
+
+ private boolean cancel;
+
+ public EntityFertilizeEggEvent(@NotNull LivingEntity mother, @NotNull LivingEntity father, @Nullable Player breeder, @Nullable ItemStack bredWith, int experience) {
+ super(mother);
+ Preconditions.checkArgument(mother != null, "Cannot have null mother");
+ Preconditions.checkArgument(father != null, "Cannot have null father");
+
+ // Breeder can be null in the case of spontaneous conception
+ this.mother = mother;
+ this.father = father;
+ this.breeder = breeder;
+ this.bredWith = bredWith;
+ this.experience = experience;
+ }
+
+ @NotNull
+ @Override
+ public LivingEntity getEntity() {
+ return (LivingEntity) entity;
+ }
+
+ /**
+ * Gets the parent creating this entity.
+ *
+ * @return The "birth" parent
+ */
+ @NotNull
+ public LivingEntity getMother() {
+ return mother;
+ }
+
+ /**
+ * Gets the other parent of the newly born entity.
+ *
+ * @return the other parent
+ */
+ @NotNull
+ public LivingEntity getFather() {
+ return father;
+ }
+
+ /**
+ * Gets the Entity responsible for fertilization. Breeder is null for spontaneous
+ * conception.
+ *
+ * @return The Entity who initiated breeding.
+ */
+ @Nullable
+ public Player getBreeder() {
+ return breeder;
+ }
+
+ /**
+ * The ItemStack that was used to initiate fertilization, if present.
+ *
+ * @return ItemStack used to initiate breeding.
+ */
+ @Nullable
+ public ItemStack getBredWith() {
+ return bredWith;
+ }
+
+ /**
+ * Get the amount of experience granted by fertilization.
+ *
+ * @return experience amount
+ */
+ public int getExperience() {
+ return experience;
+ }
+
+ /**
+ * Set the amount of experience granted by fertilization.
+ * If the amount is negative or zero, no experience will be dropped.
+ *
+ * @param experience experience amount
+ */
+ public void setExperience(int experience) {
+ this.experience = experience;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancel;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancel = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}