aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0276-Slime-Pathfinder-Events.patch
blob: ba88f01bb1129d629ee16ba0e5a03da414295022 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 24 Aug 2018 08:18:42 -0500
Subject: [PATCH] Slime Pathfinder Events


diff --git a/src/main/java/net/minecraft/server/EntitySlime.java b/src/main/java/net/minecraft/server/EntitySlime.java
index 9c83389c56083d9febf604bf30da47c89330902e..a4642cc7390b08580d00689a853d59e3e1ef6496 100644
--- a/src/main/java/net/minecraft/server/EntitySlime.java
+++ b/src/main/java/net/minecraft/server/EntitySlime.java
@@ -3,6 +3,14 @@ package net.minecraft.server;
 import java.util.EnumSet;
 import java.util.Random;
 import javax.annotation.Nullable;
+// Paper start
+import com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent;
+import com.destroystokyo.paper.event.entity.SlimeSwimEvent;
+import com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent;
+import com.destroystokyo.paper.event.entity.SlimeWanderEvent;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Slime;
+// Paper end
 // CraftBukkit start
 import java.util.ArrayList;
 import java.util.List;
@@ -65,6 +73,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
         super.saveData(nbttagcompound);
         nbttagcompound.setInt("Size", this.getSize() - 1);
         nbttagcompound.setBoolean("wasOnGround", this.bw);
+        nbttagcompound.setBoolean("Paper.canWander", this.canWander); // Paper
     }
 
     @Override
@@ -78,6 +87,11 @@ public class EntitySlime extends EntityInsentient implements IMonster {
         this.setSize(i + 1, false);
         super.loadData(nbttagcompound);
         this.bw = nbttagcompound.getBoolean("wasOnGround");
+        // Paper start - check exists before loading or this will be loaded as false
+        if (nbttagcompound.hasKey("Paper.canWander")) {
+            this.canWander = nbttagcompound.getBoolean("Paper.canWander");
+        }
+        // Paper end
     }
 
     public boolean eR() {
@@ -358,7 +372,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
 
         @Override
         public boolean a() {
-            return !this.a.isPassenger();
+            return !this.a.isPassenger() && this.a.canWander && new SlimeWanderEvent((Slime) this.a.getBukkitEntity()).callEvent(); // Paper
         }
 
         @Override
@@ -379,7 +393,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
 
         @Override
         public boolean a() {
-            return (this.a.isInWater() || this.a.aN()) && this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime;
+            return (this.a.isInWater() || this.a.aN()) && this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime && this.a.canWander && new SlimeSwimEvent((Slime) this.a.getBukkitEntity()).callEvent(); // Paper
         }
 
         @Override
@@ -405,14 +419,18 @@ public class EntitySlime extends EntityInsentient implements IMonster {
 
         @Override
         public boolean a() {
-            return this.a.getGoalTarget() == null && (this.a.onGround || this.a.isInWater() || this.a.aN() || this.a.hasEffect(MobEffects.LEVITATION)) && this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime;
+            return this.a.canWander && this.a.getGoalTarget() == null && (this.a.onGround || this.a.isInWater() || this.a.aN() || this.a.hasEffect(MobEffects.LEVITATION)) && this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime;
         }
 
         @Override
         public void e() {
             if (--this.c <= 0) {
                 this.c = 40 + this.a.getRandom().nextInt(60);
-                this.b = (float) this.a.getRandom().nextInt(360);
+                // Paper start
+                SlimeChangeDirectionEvent event = new SlimeChangeDirectionEvent((Slime) this.a.getBukkitEntity(), (float) this.a.getRandom().nextInt(360));
+                if (!this.a.canWander || !event.callEvent()) return;
+                this.b = event.getNewYaw();
+                // Paper end
             }
 
             ((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(this.b, false);
@@ -433,7 +451,15 @@ public class EntitySlime extends EntityInsentient implements IMonster {
         public boolean a() {
             EntityLiving entityliving = this.a.getGoalTarget();
 
-            return entityliving == null ? false : (!entityliving.isAlive() ? false : (entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.isInvulnerable ? false : this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime));
+            // Paper start
+            if (entityliving == null || !entityliving.isAlive()) {
+                return false;
+            }
+            if (entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.isInvulnerable) {
+                return false;
+            }
+            return this.a.getControllerMove() instanceof EntitySlime.ControllerMoveSlime && this.a.canWander && new SlimeTargetLivingEntityEvent((Slime) this.a.getBukkitEntity(), (LivingEntity) entityliving.getBukkitEntity()).callEvent();
+            // Paper end
         }
 
         @Override
@@ -446,7 +472,15 @@ public class EntitySlime extends EntityInsentient implements IMonster {
         public boolean b() {
             EntityLiving entityliving = this.a.getGoalTarget();
 
-            return entityliving == null ? false : (!entityliving.isAlive() ? false : (entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.isInvulnerable ? false : --this.b > 0));
+            // Paper start
+            if (entityliving == null || !entityliving.isAlive()) {
+                return false;
+            }
+            if (entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.isInvulnerable) {
+                return false;
+            }
+            return --this.b > 0 && this.a.canWander && new SlimeTargetLivingEntityEvent((Slime) this.a.getBukkitEntity(), (LivingEntity) entityliving.getBukkitEntity()).callEvent();
+            // Paper end
         }
 
         @Override
@@ -454,6 +488,13 @@ public class EntitySlime extends EntityInsentient implements IMonster {
             this.a.a((Entity) this.a.getGoalTarget(), 10.0F, 10.0F);
             ((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(this.a.yaw, this.a.eM());
         }
+
+        // Paper start - clear timer and target when goal resets
+        public void d() {
+            this.b = 0;
+            this.a.setGoalTarget(null);
+        }
+        // Paper end
     }
 
     static class ControllerMoveSlime extends ControllerMove {
@@ -512,4 +553,15 @@ public class EntitySlime extends EntityInsentient implements IMonster {
             }
         }
     }
+
+    // Paper start
+    private boolean canWander = true;
+    public boolean canWander() {
+        return canWander;
+    }
+
+    public void setWander(boolean canWander) {
+        this.canWander = canWander;
+    }
+    // Paper end
 }
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
index ce6ed6e890795ff2840c800a8fd56fdc618b383a..6e9f1b66dfc12491c945f87c51e81aa02424e885 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
@@ -35,4 +35,14 @@ public class CraftSlime extends CraftMob implements Slime {
     public EntityType getType() {
         return EntityType.SLIME;
     }
+
+    // Paper start
+    public boolean canWander() {
+        return getHandle().canWander();
+    }
+
+    public void setWander(boolean canWander) {
+        getHandle().setWander(canWander);
+    }
+    // Paper end
 }