summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityWolf.patch
blob: 85f3026fc6876fd8e9c33805773a50975ee92ad7 (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
--- a/net/minecraft/server/EntityWolf.java
+++ b/net/minecraft/server/EntityWolf.java
@@ -4,6 +4,11 @@
 import java.util.UUID;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
+// CraftBukkit end
+
 public class EntityWolf extends EntityTameableAnimal {
 
     private static final DataWatcherObject<Float> DATA_HEALTH = DataWatcher.a(EntityWolf.class, DataWatcherRegistry.c);
@@ -62,6 +67,22 @@
         this.getAttributeMap().b(GenericAttributes.ATTACK_DAMAGE).setValue(2.0D);
     }
 
+    // CraftBukkit - add overriden version
+    @Override
+    public boolean setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fire) {
+        if (!super.setGoalTarget(entityliving, reason, fire)) {
+            return false;
+        }
+        entityliving = getGoalTarget();
+        if (entityliving == null) {
+            this.setAngry(false);
+        } else if (!this.isTamed()) {
+            this.setAngry(true);
+        }
+        return true;
+    }
+    // CraftBukkit end
+
     public void setGoalTarget(@Nullable EntityLiving entityliving) {
         super.setGoalTarget(entityliving);
         if (entityliving == null) {
@@ -200,9 +221,10 @@
             Entity entity = damagesource.getEntity();
 
             if (this.goalSit != null) {
-                this.goalSit.setSitting(false);
+                // CraftBukkit - moved into EntityLiving.d(DamageSource, float)
+                // PAIL : checkme
+                // this.goalSit.setSitting(false);
             }
-
             if (entity != null && !(entity instanceof EntityHuman) && !(entity instanceof EntityArrow)) {
                 f = (f + 1.0F) / 2.0F;
             }
@@ -245,7 +267,7 @@
                             itemstack.subtract(1);
                         }
 
-                        this.heal((float) itemfood.getNutrition(itemstack));
+                        this.heal((float) itemfood.getNutrition(itemstack), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit
                         return true;
                     }
                 } else if (itemstack.getItem() == Items.DYE) {
@@ -266,7 +288,7 @@
                 this.goalSit.setSitting(!this.isSitting());
                 this.bd = false;
                 this.navigation.o();
-                this.setGoalTarget((EntityLiving) null);
+                this.setGoalTarget((EntityLiving) null, TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason
             }
         } else if (itemstack.getItem() == Items.BONE && !this.isAngry()) {
             if (!entityhuman.abilities.canInstantlyBuild) {
@@ -274,12 +296,14 @@
             }
 
             if (!this.world.isClientSide) {
-                if (this.random.nextInt(3) == 0) {
+                // CraftBukkit - added event call and isCancelled check.
+                if (this.random.nextInt(3) == 0 && !CraftEventFactory.callEntityTameEvent(this, entityhuman).isCancelled()) {
                     this.setTamed(true);
                     this.navigation.o();
                     this.setGoalTarget((EntityLiving) null);
                     this.goalSit.setSitting(true);
                     this.setHealth(20.0F);
+                    this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
                     this.setOwnerUUID(entityhuman.getUniqueID());
                     this.p(true);
                     this.world.broadcastEntityEffect(this, (byte) 7);