PaperMC/nms-patches/EntityAnimal.patch
2020-06-26 11:12:25 +10:00

98 lines
4 KiB
Diff

--- 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 {
public int loveTicks;
public UUID breedCause;
+ public ItemStack breedItem; // CraftBukkit - Add breedItem variable
protected EntityAnimal(EntityTypes<? extends EntityAnimal> entitytypes, World world) {
super(entitytypes, world);
@@ -44,6 +49,9 @@
}
+ /* CraftBukkit start
+ // Function disabled as it has no special function anymore after
+ // setSitting is disabled.
@Override
public boolean damageEntity(DamageSource damagesource, float f) {
if (this.isInvulnerable(damagesource)) {
@@ -53,6 +61,7 @@
return super.damageEntity(damagesource, f);
}
}
+ // CraftBukkit end */
@Override
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
if (entityhuman != null) {
this.breedCause = entityhuman.getUniqueID();
}
+ this.breedItem = entityhuman.inventory.getItemInHand(); // CraftBukkit
this.world.broadcastEntityEffect(this, (byte) 18);
}
@@ -186,11 +202,24 @@
EntityAgeable entityageable = this.createChild(entityanimal);
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 @@
entityanimal.resetLove();
entityageable.a(true);
entityageable.setPositionRotation(this.locX(), this.locY(), this.locZ(), 0.0F, 0.0F);
- world.addEntity(entityageable);
+ world.addEntity(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
world.broadcastEntityEffect(this, (byte) 18);
if (world.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
- world.addEntity(new EntityExperienceOrb(world, this.locX(), this.locY(), this.locZ(), this.getRandom().nextInt(7) + 1));
+ // CraftBukkit start - use event experience
+ if (experience > 0) {
+ world.addEntity(new EntityExperienceOrb(world, this.locX(), this.locY(), this.locZ(), experience));
+ }
+ // CraftBukkit end
}
}