SPIGOT-5257: Call EntityBreedEvent for foxes and set the child's spawn reason to BREEDING

This commit is contained in:
Brokkonaut 2019-08-09 04:34:33 +02:00
parent 1ec1b05e2a
commit 54f4e7f958

View File

@ -68,3 +68,35 @@
this.c = this.j;
if (this.k != null) {
this.l = this.k.ct();
@@ -1225,6 +1230,14 @@
if (entityplayer1 != null && entityplayer != entityplayer1) {
entityfox.b(entityplayer1.getUniqueID());
}
+ // CraftBukkit start - call EntityBreedEvent
+ int experience = this.animal.getRandom().nextInt(7) + 1;
+ org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityfox, animal, partner, entityplayer, this.animal.breedItem, experience);
+ if (entityBreedEvent.isCancelled()) {
+ return;
+ }
+ experience = entityBreedEvent.getExperience();
+ // CraftBukkit end
if (entityplayer2 != null) {
entityplayer2.a(StatisticList.ANIMALS_BRED);
@@ -1239,10 +1252,14 @@
this.partner.resetLove();
entityfox.setAgeRaw(-24000);
entityfox.setPositionRotation(this.animal.locX, this.animal.locY, this.animal.locZ, 0.0F, 0.0F);
- this.b.addEntity(entityfox);
+ this.b.addEntity(entityfox, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
this.b.broadcastEntityEffect(this.animal, (byte) 18);
if (this.b.getGameRules().getBoolean(GameRules.DO_MOB_LOOT)) {
- this.b.addEntity(new EntityExperienceOrb(this.b, this.animal.locX, this.animal.locY, this.animal.locZ, this.animal.getRandom().nextInt(7) + 1));
+ // CraftBukkit start - use event experience
+ if (experience > 0) {
+ this.b.addEntity(new EntityExperienceOrb(this.b, this.animal.locX, this.animal.locY, this.animal.locZ, experience));
+ }
+ // CraftBukkit end
}
}