summaryrefslogtreecommitdiffstats
path: root/nms-patches/PathfinderGoalBreed.patch
blob: 2c1691108d0dec4537f6b8ba818c77a9a5c03bd8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
--- a/net/minecraft/server/PathfinderGoalBreed.java
+++ b/net/minecraft/server/PathfinderGoalBreed.java
@@ -75,11 +75,24 @@
         EntityAgeable entityageable = this.animal.createChild(this.partner);
 
         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.animal.getBreedCause();
 
             if (entityplayer == null && this.partner.getBreedCause() != null) {
                 entityplayer = this.partner.getBreedCause();
             }
+            // CraftBukkit start - call EntityBreedEvent
+            int experience = this.animal.getRandom().nextInt(7) + 1;
+            org.bukkit.event.entity.EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, animal, partner, entityplayer, this.animal.breedItem, experience);
+            if (entityBreedEvent.isCancelled()) {
+                return;
+            }
+            experience = entityBreedEvent.getExperience();
+            // CraftBukkit end
 
             if (entityplayer != null) {
                 entityplayer.b(StatisticList.C);
@@ -92,7 +105,7 @@
             this.partner.resetLove();
             entityageable.setAgeRaw(-24000);
             entityageable.setPositionRotation(this.animal.locX, this.animal.locY, this.animal.locZ, 0.0F, 0.0F);
-            this.a.addEntity(entityageable);
+            this.a.addEntity(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING); // CraftBukkit - added SpawnReason
             Random random = this.animal.getRandom();
 
             for (int i = 0; i < 7; ++i) {
@@ -107,7 +120,11 @@
             }
 
             if (this.a.getGameRules().getBoolean("doMobLoot")) {
-                this.a.addEntity(new EntityExperienceOrb(this.a, this.animal.locX, this.animal.locY, this.animal.locZ, random.nextInt(7) + 1));
+                // CraftBukkit start - use event experience
+                if (experience > 0) {
+                    this.a.addEntity(new EntityExperienceOrb(this.a, this.animal.locX, this.animal.locY, this.animal.locZ, experience));
+                }
+                // CraftBukkit end
             }
 
         }