1.13: Slime Patherfinder Events (#1246)
Replaces PR #1161 for 1.13 Resolves #930 Adds new slime pathfinder related events. All events can be cancelled. - `SlimePathfindEvent` is the base event of all added events. Cancelling this event will cancel all pathfinders. - `SlimeWanderEvent` is called when slimes wander around by either swimming or moving/jumping forward. Cancelling this event will prevent slimes from moving around and jumping, but they will still look around and target players. - `SlimeSwimEvent`is called when slimes are swimming in water/lava. Cancelling will prevent the slimes from moving/jumping in water/lava. - `SlimeChangeDirectionEvent` is called when a slime changes directions. It contains the new `yaw` position the slime wants to change to, and it can be set to another value. Cancelling this event will prevent slimes from changing directions (except for when targeting players). - `SlimeTargetLivingEntityEvent` is called when a slime targets a player. NMS uses EntityLiving here so it is named this. Contains the LivingEntity the slime has targeted. Cancelling this event will prevent the slime from targeting the entity and will make it lose current focus. Adds `Slime#canWander()` and `Slime#setWander(boolean)` for a more persistent control (does not persist server restarts) over all 4 pathfinder types without the spammy event having to be cancelled a bajillion times a second. Video demonstration: https://youtu.be/8hcLqazmO28 Test plugin: https://pastebin.com/cFgcgdWV
This commit is contained in:
parent
2d688cd95a
commit
56569f7812
2 changed files with 349 additions and 0 deletions
211
Spigot-API-Patches/0141-Slime-Pathfinder-Events.patch
Normal file
211
Spigot-API-Patches/0141-Slime-Pathfinder-Events.patch
Normal file
|
@ -0,0 +1,211 @@
|
||||||
|
From 8acf7e358366fd537cdb0c354d8dc8777f254195 Mon Sep 17 00:00:00 2001
|
||||||
|
From: BillyGalbreath <Blake.Galbreath@GMail.com>
|
||||||
|
Date: Fri, 24 Aug 2018 08:18:27 -0500
|
||||||
|
Subject: [PATCH] Slime Pathfinder Events
|
||||||
|
|
||||||
|
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..f5a3ca3b
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java
|
||||||
|
@@ -0,0 +1,37 @@
|
||||||
|
+package com.destroystokyo.paper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.Slime;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Fired when a Slime decides to change it's facing direction.
|
||||||
|
+ * <p>
|
||||||
|
+ * This event does not fire for the entity's actual movement. Only when it
|
||||||
|
+ * is choosing to change direction.
|
||||||
|
+ */
|
||||||
|
+public class SlimeChangeDirectionEvent extends SlimePathfindEvent implements Cancellable {
|
||||||
|
+ private float yaw;
|
||||||
|
+
|
||||||
|
+ public SlimeChangeDirectionEvent(Slime slime, float yaw) {
|
||||||
|
+ super(slime);
|
||||||
|
+ this.yaw = yaw;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the new chosen yaw
|
||||||
|
+ *
|
||||||
|
+ * @return Chosen yaw
|
||||||
|
+ */
|
||||||
|
+ public float getNewYaw() {
|
||||||
|
+ return yaw;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Set the new chosen yaw
|
||||||
|
+ *
|
||||||
|
+ * @param yaw Chosen yaw
|
||||||
|
+ */
|
||||||
|
+ public void setNewYaw(float yaw) {
|
||||||
|
+ this.yaw = yaw;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..356bcca8
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java
|
||||||
|
@@ -0,0 +1,49 @@
|
||||||
|
+package com.destroystokyo.paper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.Slime;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+import org.bukkit.event.HandlerList;
|
||||||
|
+import org.bukkit.event.entity.EntityEvent;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Fired when a Slime decides to start pathfinding.
|
||||||
|
+ * <p>
|
||||||
|
+ * This event does not fire for the entity's actual movement. Only when it
|
||||||
|
+ * is choosing to start moving.
|
||||||
|
+ */
|
||||||
|
+public class SlimePathfindEvent extends EntityEvent implements Cancellable {
|
||||||
|
+ public SlimePathfindEvent(Slime slime) {
|
||||||
|
+ super(slime);
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * The Slime that is pathfinding.
|
||||||
|
+ *
|
||||||
|
+ * @return The Slime that is pathfinding.
|
||||||
|
+ */
|
||||||
|
+ public Slime getEntity() {
|
||||||
|
+ return (Slime) entity;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ private static final HandlerList handlers = new HandlerList();
|
||||||
|
+
|
||||||
|
+ public HandlerList getHandlers() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ public static HandlerList getHandlerList() {
|
||||||
|
+ return handlers;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ private boolean cancelled = false;
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public boolean isCancelled() {
|
||||||
|
+ return cancelled;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ @Override
|
||||||
|
+ public void setCancelled(boolean cancel) {
|
||||||
|
+ cancelled = cancel;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..7c99fb53
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java
|
||||||
|
@@ -0,0 +1,16 @@
|
||||||
|
+package com.destroystokyo.paper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.Slime;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Fired when a Slime decides to start jumping while swimming in water/lava.
|
||||||
|
+ * <p>
|
||||||
|
+ * This event does not fire for the entity's actual movement. Only when it
|
||||||
|
+ * is choosing to start jumping.
|
||||||
|
+ */
|
||||||
|
+public class SlimeSwimEvent extends SlimeWanderEvent implements Cancellable {
|
||||||
|
+ public SlimeSwimEvent(Slime slime) {
|
||||||
|
+ super(slime);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..7c96e326
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java
|
||||||
|
@@ -0,0 +1,29 @@
|
||||||
|
+package com.destroystokyo.paper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.LivingEntity;
|
||||||
|
+import org.bukkit.entity.Slime;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Fired when a Slime decides to change direction to target a LivingEntity.
|
||||||
|
+ * <p>
|
||||||
|
+ * This event does not fire for the entity's actual movement. Only when it
|
||||||
|
+ * is choosing to start moving.
|
||||||
|
+ */
|
||||||
|
+public class SlimeTargetLivingEntityEvent extends SlimePathfindEvent implements Cancellable {
|
||||||
|
+ private final LivingEntity target;
|
||||||
|
+
|
||||||
|
+ public SlimeTargetLivingEntityEvent(Slime slime, LivingEntity target) {
|
||||||
|
+ super(slime);
|
||||||
|
+ this.target = target;
|
||||||
|
+ }
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Get the targeted entity
|
||||||
|
+ *
|
||||||
|
+ * @return Targeted entity
|
||||||
|
+ */
|
||||||
|
+ public LivingEntity getTarget() {
|
||||||
|
+ return target;
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java
|
||||||
|
new file mode 100644
|
||||||
|
index 00000000..e55d208c
|
||||||
|
--- /dev/null
|
||||||
|
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java
|
||||||
|
@@ -0,0 +1,16 @@
|
||||||
|
+package com.destroystokyo.paper.event.entity;
|
||||||
|
+
|
||||||
|
+import org.bukkit.entity.Slime;
|
||||||
|
+import org.bukkit.event.Cancellable;
|
||||||
|
+
|
||||||
|
+/**
|
||||||
|
+ * Fired when a Slime decides to start wandering.
|
||||||
|
+ * <p>
|
||||||
|
+ * This event does not fire for the entity's actual movement. Only when it
|
||||||
|
+ * is choosing to start moving.
|
||||||
|
+ */
|
||||||
|
+public class SlimeWanderEvent extends SlimePathfindEvent implements Cancellable {
|
||||||
|
+ public SlimeWanderEvent(Slime slime) {
|
||||||
|
+ super(slime);
|
||||||
|
+ }
|
||||||
|
+}
|
||||||
|
diff --git a/src/main/java/org/bukkit/entity/Slime.java b/src/main/java/org/bukkit/entity/Slime.java
|
||||||
|
index 46d03d29..8bd18406 100644
|
||||||
|
--- a/src/main/java/org/bukkit/entity/Slime.java
|
||||||
|
+++ b/src/main/java/org/bukkit/entity/Slime.java
|
||||||
|
@@ -14,4 +14,20 @@ public interface Slime extends Mob, com.destroystokyo.paper.entity.SentientNPC {
|
||||||
|
* @param sz The new size of the slime.
|
||||||
|
*/
|
||||||
|
public void setSize(int sz);
|
||||||
|
+
|
||||||
|
+ // Paper start
|
||||||
|
+ /**
|
||||||
|
+ * Get whether this slime can randomly wander/jump around on its own
|
||||||
|
+ *
|
||||||
|
+ * @return true if can wander
|
||||||
|
+ */
|
||||||
|
+ public boolean canWander();
|
||||||
|
+
|
||||||
|
+ /**
|
||||||
|
+ * Set whether this slime can randomly wander/jump around on its own
|
||||||
|
+ *
|
||||||
|
+ * @param canWander true if can wander
|
||||||
|
+ */
|
||||||
|
+ public void setWander(boolean canWander);
|
||||||
|
+ // Paper end
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.18.0
|
||||||
|
|
138
Spigot-Server-Patches/0350-Slime-Pathfinder-Events.patch
Normal file
138
Spigot-Server-Patches/0350-Slime-Pathfinder-Events.patch
Normal file
|
@ -0,0 +1,138 @@
|
||||||
|
From f61af69c38c8da6ea99150bcdb063c12cf6491e2 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 eeaf98e8..8752c62b 100644
|
||||||
|
--- a/src/main/java/net/minecraft/server/EntitySlime.java
|
||||||
|
+++ b/src/main/java/net/minecraft/server/EntitySlime.java
|
||||||
|
@@ -57,6 +57,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
||||||
|
super.b(nbttagcompound);
|
||||||
|
nbttagcompound.setInt("Size", this.getSize() - 1);
|
||||||
|
nbttagcompound.setBoolean("wasOnGround", this.bD);
|
||||||
|
+ nbttagcompound.setBoolean("Paper.canWander", this.canWander); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
public void a(NBTTagCompound nbttagcompound) {
|
||||||
|
@@ -69,6 +70,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
||||||
|
|
||||||
|
this.setSize(i + 1, false);
|
||||||
|
this.bD = nbttagcompound.getBoolean("wasOnGround");
|
||||||
|
+ this.canWander = nbttagcompound.getBoolean("Paper.canWander"); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean dz() {
|
||||||
|
@@ -308,7 +310,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean a() {
|
||||||
|
- return true;
|
||||||
|
+ return this.a.canWander && new com.destroystokyo.paper.event.entity.SlimeWanderEvent((org.bukkit.entity.Slime) this.a.getBukkitEntity()).callEvent(); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
public void e() {
|
||||||
|
@@ -327,7 +329,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean a() {
|
||||||
|
- return this.a.isInWater() || this.a.ax();
|
||||||
|
+ return (this.a.isInWater() || this.a.ax()) && this.a.canWander && new com.destroystokyo.paper.event.entity.SlimeSwimEvent((org.bukkit.entity.Slime) this.a.getBukkitEntity()).callEvent(); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
public void e() {
|
||||||
|
@@ -351,13 +353,17 @@ public class EntitySlime extends EntityInsentient implements IMonster {
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean a() {
|
||||||
|
- return this.a.getGoalTarget() == null && (this.a.onGround || this.a.isInWater() || this.a.ax() || this.a.hasEffect(MobEffects.LEVITATION));
|
||||||
|
+ return this.a.canWander && this.a.getGoalTarget() == null && (this.a.onGround || this.a.isInWater() || this.a.ax() || this.a.hasEffect(MobEffects.LEVITATION)); // Paper
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
+ com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent event = new com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent((org.bukkit.entity.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);
|
||||||
|
@@ -377,7 +383,16 @@ 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);
|
||||||
|
+ // Paper start
|
||||||
|
+ if (entityliving != null && entityliving.isAlive() && (!(entityliving instanceof EntityHuman) || !((EntityHuman) entityliving).abilities.isInvulnerable)) {
|
||||||
|
+ if (this.a.canWander && new com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.a.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent()) {
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ this.b = 0;
|
||||||
|
+ this.a.setGoalTarget(null);
|
||||||
|
+ }
|
||||||
|
+ return false;
|
||||||
|
+ // Paper end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void c() {
|
||||||
|
@@ -388,7 +403,16 @@ 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() && (!(entityliving instanceof EntityHuman) || !((EntityHuman) entityliving).abilities.isInvulnerable)) {
|
||||||
|
+ if (this.a.canWander && new com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.a.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent()) {
|
||||||
|
+ return true;
|
||||||
|
+ }
|
||||||
|
+ this.b = 0;
|
||||||
|
+ this.a.setGoalTarget(null);
|
||||||
|
+ }
|
||||||
|
+ return false;
|
||||||
|
+ // Paper end
|
||||||
|
}
|
||||||
|
|
||||||
|
public void e() {
|
||||||
|
@@ -452,4 +476,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 18e7ef80..8403c1e0 100644
|
||||||
|
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
|
||||||
|
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
|
||||||
|
@@ -33,4 +33,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
|
||||||
|
}
|
||||||
|
--
|
||||||
|
2.18.0
|
||||||
|
|
Loading…
Reference in a new issue