3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-20 21:40:06 +01:00
Paper/nms-patches/EntityAnimal.patch

99 Zeilen
4.1 KiB
Diff

2015-05-25 12:37:24 +02:00
--- a/net/minecraft/server/EntityAnimal.java
+++ b/net/minecraft/server/EntityAnimal.java
@@ -3,11 +3,16 @@
import java.util.Random;
import java.util.UUID;
import javax.annotation.Nullable;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityEnterLoveModeEvent;
+// CraftBukkit end
public abstract class EntityAnimal extends EntityAgeable {
2019-06-21 12:00:00 +02:00
2019-04-23 04:00:00 +02:00
public int loveTicks;
2018-10-22 21:00:00 +02:00
public UUID breedCause;
2016-06-19 07:00:39 +02:00
+ public ItemStack breedItem; // CraftBukkit - Add breedItem variable
2019-04-23 04:00:00 +02:00
protected EntityAnimal(EntityTypes<? extends EntityAnimal> entitytypes, World world) {
2018-07-15 02:00:00 +02:00
super(entitytypes, world);
@@ -44,6 +49,9 @@
}
+ /* CraftBukkit start
+ // Function disabled as it has no special function anymore after
+ // setSitting is disabled.
2019-04-23 04:00:00 +02:00
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (this.isInvulnerable(damagesource)) {
@@ -53,6 +61,7 @@
return super.damageEntity(damagesource, f);
}
}
+ // CraftBukkit end */
2019-04-23 04:00:00 +02:00
@Override
2018-07-15 02:00:00 +02:00
public float a(BlockPosition blockposition, IWorldReader iworldreader) {
@@ -143,10 +152,17 @@
}
public void g(@Nullable EntityHuman entityhuman) {
- this.loveTicks = 600;
+ // CraftBukkit start
+ EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(entityhuman, this, 600);
+ if (entityEnterLoveModeEvent.isCancelled()) {
+ return;
+ }
+ this.loveTicks = entityEnterLoveModeEvent.getTicksInLove();
+ // CraftBukkit end
2017-05-14 04:00:00 +02:00
if (entityhuman != null) {
2018-10-22 21:00:00 +02:00
this.breedCause = entityhuman.getUniqueID();
2017-05-14 04:00:00 +02:00
}
2016-06-19 07:00:39 +02:00
+ this.breedItem = entityhuman.inventory.getItemInHand(); // CraftBukkit
2017-05-14 04:00:00 +02:00
2016-06-19 07:00:39 +02:00
this.world.broadcastEntityEffect(this, (byte) 18);
}
@@ -186,11 +202,24 @@
2020-08-11 23:00:00 +02:00
EntityAgeable entityageable = this.createChild(worldserver, entityanimal);
2020-06-25 02:00:00 +02:00
if (entityageable != null) {
+ // CraftBukkit start - set persistence for tame animals
+ if (entityageable instanceof EntityTameableAnimal && ((EntityTameableAnimal) entityageable).isTamed()) {
+ entityageable.persistent = true;
+ }
+ // CraftBukkit end
EntityPlayer entityplayer = this.getBreedCause();
if (entityplayer == null && entityanimal.getBreedCause() != null) {
entityplayer = entityanimal.getBreedCause();
}
+ // CraftBukkit start - call EntityBreedEvent
+ 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()) {
+ return;
+ }
+ experience = entityBreedEvent.getExperience();
+ // CraftBukkit end
if (entityplayer != null) {
entityplayer.a(StatisticList.ANIMALS_BRED);
@@ -203,10 +232,14 @@
2020-06-25 02:00:00 +02:00
entityanimal.resetLove();
2020-08-11 23:00:00 +02:00
entityageable.setBaby(true);
2020-06-25 02:00:00 +02:00
entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F);
2020-08-11 23:00:00 +02:00
- worldserver.addAllEntities(entityageable);
+ worldserver.addAllEntities(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
worldserver.broadcastEntityEffect(this, (byte) 18);
if (worldserver.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
- worldserver.addEntity(new EntityExperienceOrb(worldserver, this.locX(), this.locY(), this.locZ(), this.getRandom().nextInt(7) + 1));
2020-06-25 02:00:00 +02:00
+ // CraftBukkit start - use event experience
+ if (experience > 0) {
2020-08-11 23:00:00 +02:00
+ worldserver.addEntity(new EntityExperienceOrb(worldserver, this.locX(), this.locY(), this.locZ(), experience));
2020-06-25 02:00:00 +02:00
+ }
+ // CraftBukkit end
}
}