summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntityHorseAbstract.patch
blob: c050ff85ce4464ddb412462d3c0aa3d8941760dd (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
--- a/net/minecraft/server/EntityHorseAbstract.java
+++ b/net/minecraft/server/EntityHorseAbstract.java
@@ -6,6 +6,7 @@
 import java.util.UUID;
 import java.util.function.Predicate;
 import javax.annotation.Nullable;
+import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason; // CraftBukkit
 
 public abstract class EntityHorseAbstract extends EntityAnimal implements IInventoryListener, IJumpable {
 
@@ -33,6 +34,7 @@
     private float bY;
     protected boolean bK = true;
     protected int bL;
+    public int maxDomestication = 100; // CraftBukkit - store max domestication value
 
     protected EntityHorseAbstract(EntityTypes<?> entitytypes, World world) {
         super(entitytypes, world);
@@ -212,7 +214,7 @@
     public void loadChest() {
         InventoryHorseChest inventoryhorsechest = this.inventoryChest;
 
-        this.inventoryChest = new InventoryHorseChest(this.getDisplayName(), this.dB());
+        this.inventoryChest = new InventoryHorseChest(this.getDisplayName(), this.dB(), this); // CraftBukkit
         this.inventoryChest.a(this.getCustomName());
         if (inventoryhorsechest != null) {
             inventoryhorsechest.b(this);
@@ -348,7 +350,7 @@
     }
 
     public int getMaxDomestication() {
-        return 100;
+        return this.maxDomestication; // CraftBukkit - return stored max domestication instead of 100
     }
 
     protected float cD() {
@@ -408,7 +410,7 @@
         }
 
         if (this.getHealth() < this.getMaxHealth() && f > 0.0F) {
-            this.heal(f);
+            this.heal(f, RegainReason.EATING); // CraftBukkit
             flag = true;
         }
 
@@ -459,7 +461,7 @@
     }
 
     public void die(DamageSource damagesource) {
-        super.die(damagesource);
+        // super.die(damagesource); // Moved down
         if (!this.world.isClientSide && this.inventoryChest != null) {
             for (int i = 0; i < this.inventoryChest.getSize(); ++i) {
                 ItemStack itemstack = this.inventoryChest.getItem(i);
@@ -470,6 +472,7 @@
             }
 
         }
+        super.die(damagesource); // CraftBukkit
     }
 
     public void k() {
@@ -480,7 +483,7 @@
         super.k();
         if (!this.world.isClientSide) {
             if (this.random.nextInt(900) == 0 && this.deathTicks == 0) {
-                this.heal(1.0F);
+                this.heal(1.0F, RegainReason.REGEN); // CraftBukkit
             }
 
             if (this.dZ()) {
@@ -716,6 +719,7 @@
         if (this.getOwnerUUID() != null) {
             nbttagcompound.setString("OwnerUUID", this.getOwnerUUID().toString());
         }
+        nbttagcompound.setInt("Bukkit.MaxDomestication", this.maxDomestication); // CraftBukkit
 
         if (!this.inventoryChest.getItem(0).isEmpty()) {
             nbttagcompound.set("SaddleItem", this.inventoryChest.getItem(0).save(new NBTTagCompound()));
@@ -742,6 +746,11 @@
         if (!s.isEmpty()) {
             this.setOwnerUUID(UUID.fromString(s));
         }
+        // CraftBukkit start
+        if (nbttagcompound.hasKey("Bukkit.MaxDomestication")) {
+            this.maxDomestication = nbttagcompound.getInt("Bukkit.MaxDomestication");
+        }
+        // CraftBukkit end
 
         AttributeInstance attributeinstance = this.getAttributeMap().a("Speed");
 
@@ -794,6 +803,18 @@
     }
 
     public void b(int i) {
+        // CraftBukkit start
+        float power;
+        if (i >= 90) {
+            power = 1.0F;
+        } else {
+            power = 0.4F + 0.4F * (float) i / 90.0F;
+        }
+        org.bukkit.event.entity.HorseJumpEvent event = org.bukkit.craftbukkit.event.CraftEventFactory.callHorseJumpEvent(this, power);
+        if (event.isCancelled()) {
+            return;
+        }
+        // CraftBukkit end
         this.canSlide = true;
         this.dI();
     }