aboutsummaryrefslogtreecommitdiffhomepage
path: root/patch-remap/mache-vineflower-stripped/net/minecraft/world/entity/animal/Animal.java.patch
blob: f5e68c0a5232e95d050f855b6257516963bd54d7 (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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
--- a/net/minecraft/world/entity/animal/Animal.java
+++ b/net/minecraft/world/entity/animal/Animal.java
@@ -29,12 +29,18 @@
 import net.minecraft.world.level.LevelReader;
 import net.minecraft.world.level.block.Blocks;
 import net.minecraft.world.level.pathfinder.BlockPathTypes;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityBreedEvent;
+import org.bukkit.event.entity.EntityEnterLoveModeEvent;
+// CraftBukkit end
 
 public abstract class Animal extends AgeableMob {
     protected static final int PARENT_AGE_AFTER_BREEDING = 6000;
     private int inLove;
     @Nullable
-    private UUID loveCause;
+    public UUID loveCause;
+    public ItemStack breedItem; // CraftBukkit - Add breedItem variable
 
     protected Animal(EntityType<? extends Animal> entityType, Level level) {
         super(entityType, level);
@@ -74,8 +83,13 @@
         if (this.isInvulnerableTo(source)) {
             return false;
         } else {
+            // CraftBukkit start
+            boolean result = super.hurt(source, amount);
+            if (result) {
             this.inLove = 0;
-            return super.hurt(source, amount);
+            }
+            return result;
+            // CraftBukkit end
         }
     }
 
@@ -166,10 +183,17 @@
     }
 
     public void setInLove(@Nullable Player player) {
-        this.inLove = 600;
+        // CraftBukkit start
+        EntityEnterLoveModeEvent entityEnterLoveModeEvent = CraftEventFactory.callEntityEnterLoveModeEvent(player, this, 600);
+        if (entityEnterLoveModeEvent.isCancelled()) {
+            return;
+        }
+        this.inLove = entityEnterLoveModeEvent.getTicksInLove();
+        // CraftBukkit end
         if (player != null) {
             this.loveCause = player.getUUID();
         }
+        this.breedItem = player.getInventory().getSelected(); // CraftBukkit
 
         this.level().broadcastEntityEvent(this, (byte)18);
     }
@@ -205,27 +230,51 @@
     }
 
     public void spawnChildFromBreeding(ServerLevel level, Animal mate) {
-        AgeableMob breedOffspring = this.getBreedOffspring(level, mate);
-        if (breedOffspring != null) {
-            breedOffspring.setBaby(true);
-            breedOffspring.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
-            this.finalizeSpawnChildFromBreeding(level, mate, breedOffspring);
-            level.addFreshEntityWithPassengers(breedOffspring);
+        AgeableMob entityageable = this.getBreedOffspring(level, mate);
+
+        if (entityageable != null) {
+            entityageable.setBaby(true);
+            entityageable.moveTo(this.getX(), this.getY(), this.getZ(), 0.0F, 0.0F);
+            // CraftBukkit start - call EntityBreedEvent
+            ServerPlayer breeder = Optional.ofNullable(this.getLoveCause()).or(() -> {
+                return Optional.ofNullable(mate.getLoveCause());
+            }).orElse(null);
+            int experience = this.getRandom().nextInt(7) + 1;
+            EntityBreedEvent entityBreedEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callEntityBreedEvent(entityageable, this, mate, breeder, this.breedItem, experience);
+            if (entityBreedEvent.isCancelled()) {
+                return;
+            }
+            experience = entityBreedEvent.getExperience();
+            this.finalizeSpawnChildFromBreeding(level, mate, entityageable, experience);
+            level.addFreshEntityWithPassengers(entityageable, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.BREEDING);
+            // CraftBukkit end
         }
     }
 
     public void finalizeSpawnChildFromBreeding(ServerLevel level, Animal animal, @Nullable AgeableMob baby) {
-        Optional.ofNullable(this.getLoveCause()).or(() -> Optional.ofNullable(animal.getLoveCause())).ifPresent(player -> {
-            player.awardStat(Stats.ANIMALS_BRED);
-            CriteriaTriggers.BRED_ANIMALS.trigger(player, this, animal, baby);
+        // CraftBukkit start
+        this.finalizeSpawnChildFromBreeding(level, animal, baby, this.getRandom().nextInt(7) + 1);
+    }
+
+    public void finalizeSpawnChildFromBreeding(ServerLevel worldserver, Animal entityanimal, @Nullable AgeableMob entityageable, int experience) {
+        // CraftBukkit end
+        Optional.ofNullable(this.getLoveCause()).or(() -> {
+            return Optional.ofNullable(entityanimal.getLoveCause());
+        }).ifPresent((entityplayer) -> {
+            entityplayer.awardStat(Stats.ANIMALS_BRED);
+            CriteriaTriggers.BRED_ANIMALS.trigger(entityplayer, this, entityanimal, entityageable);
         });
         this.setAge(6000);
         animal.setAge(6000);
         this.resetLove();
-        animal.resetLove();
-        level.broadcastEntityEvent(this, (byte)18);
-        if (level.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
-            level.addFreshEntity(new ExperienceOrb(level, this.getX(), this.getY(), this.getZ(), this.getRandom().nextInt(7) + 1));
+        entityanimal.resetLove();
+        worldserver.broadcastEntityEvent(this, (byte) 18);
+        if (worldserver.getGameRules().getBoolean(GameRules.RULE_DOMOBLOOT)) {
+            // CraftBukkit start - use event experience
+            if (experience > 0) {
+                worldserver.addFreshEntity(new ExperienceOrb(worldserver, this.getX(), this.getY(), this.getZ(), experience));
+            }
+            // CraftBukkit end
         }
     }