mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-28 23:38:25 +01:00
Add EntityFertilizeEggEvent (#8041)
This commit is contained in:
parent
2dd20a5904
commit
562a36f98b
2 changed files with 214 additions and 0 deletions
140
patches/api/Add-EntityFertilizeEggEvent.patch
Normal file
140
patches/api/Add-EntityFertilizeEggEvent.patch
Normal file
|
@ -0,0 +1,140 @@
|
|||
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..0000000000000000000000000000000000000000
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/entity/EntityFertilizeEggEvent.java
|
||||
@@ -0,0 +0,0 @@
|
||||
+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;
|
||||
+ }
|
||||
+}
|
74
patches/server/Add-EntityFertilizeEggEvent.patch
Normal file
74
patches/server/Add-EntityFertilizeEggEvent.patch
Normal file
|
@ -0,0 +1,74 @@
|
|||
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
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/animal/Turtle.java
|
||||
@@ -0,0 +0,0 @@ public class Turtle extends Animal {
|
||||
if (entityplayer == null && this.partner.getLoveCause() != null) {
|
||||
entityplayer = this.partner.getLoveCause();
|
||||
}
|
||||
+ // Paper start
|
||||
+ RandomSource randomsource = this.animal.getRandom();
|
||||
+ int experience = randomsource.nextInt(7) + 1;
|
||||
+ io.papermc.paper.event.entity.EntityFertilizeEggEvent event = new io.papermc.paper.event.entity.EntityFertilizeEggEvent((org.bukkit.entity.LivingEntity) turtle.getBukkitEntity(), (org.bukkit.entity.LivingEntity) partner.getBukkitEntity(), entityplayer == null ? null : entityplayer.getBukkitEntity(), turtle.breedItem == null ? null : org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(turtle.breedItem).clone(), experience);
|
||||
+ if (!event.callEvent()) {
|
||||
+ animal.resetLove();
|
||||
+ partner.resetLove(); // stop the pathfinding to avoid infinite loop
|
||||
+ return;
|
||||
+ }
|
||||
+ experience = event.getExperience();
|
||||
+ // Paper end
|
||||
|
||||
if (entityplayer != null) {
|
||||
entityplayer.awardStat(Stats.ANIMALS_BRED);
|
||||
@@ -0,0 +0,0 @@ public class Turtle extends Animal {
|
||||
this.partner.setAge(6000);
|
||||
this.animal.resetLove();
|
||||
this.partner.resetLove();
|
||||
- RandomSource randomsource = this.animal.getRandom();
|
||||
|
||||
- if (this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
|
||||
- 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;
|
||||
+ if (experience > 0 && this.level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Paper
|
||||
+ this.level.addFreshEntity(new ExperienceOrb(this.level, this.animal.getX(), this.animal.getY(), this.animal.getZ(), experience, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, entityplayer)); // Paper
|
||||
}
|
||||
|
||||
}
|
||||
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
|
||||
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
|
||||
--- a/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
|
||||
+++ b/src/main/java/net/minecraft/world/entity/animal/frog/Frog.java
|
||||
@@ -0,0 +0,0 @@ public class Frog extends Animal implements VariantHolder<FrogVariant> {
|
||||
serverPlayer = other.getLoveCause();
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ int experience = this.getRandom().nextInt(7) + 1;
|
||||
+ io.papermc.paper.event.entity.EntityFertilizeEggEvent event = new io.papermc.paper.event.entity.EntityFertilizeEggEvent((org.bukkit.entity.LivingEntity) this.getBukkitEntity(), (org.bukkit.entity.LivingEntity) other.getBukkitEntity(), serverPlayer == null ? null : serverPlayer.getBukkitEntity(), this.breedItem == null ? null : org.bukkit.craftbukkit.inventory.CraftItemStack.asCraftMirror(this.breedItem).clone(), experience);
|
||||
+ if (!event.callEvent()) {
|
||||
+ resetLove();
|
||||
+ other.resetLove(); // stop the pathfinding to avoid infinite loop
|
||||
+ return;
|
||||
+ }
|
||||
+ experience = event.getExperience();
|
||||
+ // Paper end
|
||||
+
|
||||
if (serverPlayer != null) {
|
||||
serverPlayer.awardStat(Stats.ANIMALS_BRED);
|
||||
CriteriaTriggers.BRED_ANIMALS.trigger(serverPlayer, this, other, (AgeableMob)null);
|
||||
@@ -0,0 +0,0 @@ public class Frog extends Animal implements VariantHolder<FrogVariant> {
|
||||
other.resetLove();
|
||||
this.getBrain().setMemory(MemoryModuleType.IS_PREGNANT, Unit.INSTANCE);
|
||||
world.broadcastEntityEvent(this, (byte)18);
|
||||
- if (world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
|
||||
- world.addFreshEntity(new ExperienceOrb(world, this.getX(), this.getY(), this.getZ(), this.getRandom().nextInt(7) + 1, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, serverPlayer)); // Paper
|
||||
+ if (experience > 0 && world.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) { // Paper
|
||||
+ world.addFreshEntity(new ExperienceOrb(world, this.getX(), this.getY(), this.getZ(), experience, org.bukkit.entity.ExperienceOrb.SpawnReason.BREED, serverPlayer)); // Paper
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue