Add EntityFertilizeEggEvent

This commit is contained in:
Lulu13022002
2022-06-24 12:39:34 +02:00
parent b5442da875
commit ab040d534d
4 changed files with 69 additions and 7 deletions

View File

@@ -2195,4 +2195,28 @@ public class CraftEventFactory {
return event.callEvent();
}
// Paper end
// Paper start - add EntityFertilizeEggEvent
/**
* Calls the {@link io.papermc.paper.event.entity.EntityFertilizeEggEvent}.
* 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.
*/
public static io.papermc.paper.event.entity.EntityFertilizeEggEvent callEntityFertilizeEggEvent(Animal breeding, Animal other) {
ServerPlayer serverPlayer = breeding.getLoveCause();
if (serverPlayer == null) serverPlayer = other.getLoveCause();
final int experience = breeding.getRandom().nextInt(7) + 1; // From Animal#spawnChildFromBreeding(ServerLevel, Animal)
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);
if (!event.callEvent()) {
breeding.resetLove();
other.resetLove(); // stop the pathfinding to avoid infinite loop
}
return event;
}
// Paper end - add EntityFertilizeEggEvent
}