summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityWolf.patch
blob: 71e0577715e572c0c7e291a14b61b20b38fb50a2 (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
--- ../work/decompile-8eb82bde/net/minecraft/server/EntityWolf.java	2014-12-10 18:34:37.316492559 +0000
+++ src/main/java/net/minecraft/server/EntityWolf.java	2014-12-10 18:34:29.104492649 +0000
@@ -1,5 +1,10 @@
 package net.minecraft.server;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.entity.EntityTargetEvent.TargetReason;
+// CraftBukkit end
+
 public class EntityWolf extends EntityTameableAnimal {
 
     private float bm;
@@ -51,8 +56,19 @@
         } else if (!this.isTamed()) {
             this.setAngry(true);
         }
+    }
 
+    // CraftBukkit - add overriden version
+    @Override
+    public void setGoalTarget(EntityLiving entityliving, org.bukkit.event.entity.EntityTargetEvent.TargetReason reason, boolean fire) {
+        super.setGoalTarget(entityliving, reason, fire);
+        if (entityliving == null) {
+            this.setAngry(false);
+        } else if (!this.isTamed()) {
+            this.setAngry(true);
+        }
     }
+    // CraftBukkit end
 
     protected void E() {
         this.datawatcher.watch(18, Float.valueOf(this.getHealth()));
@@ -85,7 +101,8 @@
     }
 
     protected String z() {
-        return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getFloat(18) < 10.0F ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
+        // CraftBukkit - (getFloat(18) < 10) -> (getFloat(18) < this.getMaxHealth() / 2)
+        return this.isAngry() ? "mob.wolf.growl" : (this.random.nextInt(3) == 0 ? (this.isTamed() && this.datawatcher.getFloat(18) < this.getMaxHealth() / 2 ? "mob.wolf.whine" : "mob.wolf.panting") : "mob.wolf.bark");
     }
 
     protected String bn() {
@@ -176,7 +193,8 @@
         } else {
             Entity entity = damagesource.getEntity();
 
-            this.bk.setSitting(false);
+            // CraftBukkit - moved into EntityLiving.d(DamageSource, float)
+            // this.bk.setSitting(false);
             if (entity != null && !(entity instanceof EntityHuman) && !(entity instanceof EntityArrow)) {
                 f = (f + 1.0F) / 2.0F;
             }
@@ -219,7 +237,7 @@
                             --itemstack.count;
                         }
 
-                        this.heal((float) itemfood.getNutrition(itemstack));
+                        this.heal((float) itemfood.getNutrition(itemstack), org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason.EATING); // CraftBukkit
                         if (itemstack.count <= 0) {
                             entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, (ItemStack) null);
                         }
@@ -244,7 +262,7 @@
                 this.bk.setSitting(!this.isSitting());
                 this.aW = false;
                 this.navigation.n();
-                this.setGoalTarget((EntityLiving) null);
+                this.setGoalTarget((EntityLiving) null, TargetReason.FORGOT_TARGET, true); // CraftBukkit - reason
             }
         } else if (itemstack != null && itemstack.getItem() == Items.BONE && !this.isAngry()) {
             if (!entityhuman.abilities.canInstantlyBuild) {
@@ -256,12 +274,13 @@
             }
 
             if (!this.world.isStatic) {
-                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.n();
-                    this.setGoalTarget((EntityLiving) null);
+                    this.setGoalTarget((EntityLiving) null, TargetReason.FORGOT_TARGET, true);
                     this.bk.setSitting(true);
-                    this.setHealth(20.0F);
+                    this.setHealth(this.getMaxHealth()); // CraftBukkit - 20.0 -> getMaxHealth()
                     this.setOwnerUUID(entityhuman.getUniqueID().toString());
                     this.l(true);
                     this.world.broadcastEntityEffect(this, (byte) 7);
@@ -348,7 +367,7 @@
     }
 
     protected boolean isTypeNotPersistent() {
-        return !this.isTamed() && this.ticksLived > 2400;
+        return !this.isTamed() /*&& this.ticksLived > 2400*/; // CraftBukkit
     }
 
     public boolean a(EntityLiving entityliving, EntityLiving entityliving1) {