From 2af722672a33112fa554be7baf15540b1222eab1 Mon Sep 17 00:00:00 2001 From: BillyGalbreath Date: Sun, 7 Oct 2018 11:57:52 -0500 Subject: [PATCH] Fix timer in slime AI (#1548) Seems my original pull for this created an unseen bug where the target timer would never run out (the slime would not "forget" it's target over time). Went ahead and fixed that, and made the code more legible by adding the imports. --- .../Slime-Pathfinder-Events.patch | 64 +++++++++++++------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/Spigot-Server-Patches/Slime-Pathfinder-Events.patch b/Spigot-Server-Patches/Slime-Pathfinder-Events.patch index 5fe301b2b2..e1aa62c074 100644 --- a/Spigot-Server-Patches/Slime-Pathfinder-Events.patch +++ b/Spigot-Server-Patches/Slime-Pathfinder-Events.patch @@ -5,9 +5,24 @@ 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 238f3c7926..586b9a3a66 100644 +index 238f3c792..2737a7d69 100644 --- a/src/main/java/net/minecraft/server/EntitySlime.java +++ b/src/main/java/net/minecraft/server/EntitySlime.java +@@ -0,0 +0,0 @@ + package net.minecraft.server; + + 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 org.bukkit.event.entity.SlimeSplitEvent; + // CraftBukkit end @@ -0,0 +0,0 @@ public class EntitySlime extends EntityInsentient implements IMonster { super.b(nbttagcompound); nbttagcompound.setInt("Size", this.getSize() - 1); @@ -33,7 +48,7 @@ index 238f3c7926..586b9a3a66 100644 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 ++ return this.a.canWander && new SlimeWanderEvent((Slime) this.a.getBukkitEntity()).callEvent(); // Paper } public void e() { @@ -42,7 +57,7 @@ index 238f3c7926..586b9a3a66 100644 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 ++ return (this.a.isInWater() || this.a.ax()) && this.a.canWander && new SlimeSwimEvent((Slime) this.a.getBukkitEntity()).callEvent(); // Paper } public void e() { @@ -59,7 +74,7 @@ index 238f3c7926..586b9a3a66 100644 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)); ++ 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 @@ -72,14 +87,13 @@ index 238f3c7926..586b9a3a66 100644 - 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); ++ if (entityliving == null || !entityliving.isAlive()) { ++ return false; + } -+ return false; ++ if (entityliving instanceof EntityHuman && ((EntityHuman) entityliving).abilities.isInvulnerable) { ++ return false; ++ } ++ return this.a.canWander && new SlimeTargetLivingEntityEvent((Slime) this.a.getBukkitEntity(), (LivingEntity) entityliving.getBukkitEntity()).callEvent(); + // Paper end } @@ -90,18 +104,30 @@ index 238f3c7926..586b9a3a66 100644 - 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); ++ if (entityliving == null || !entityliving.isAlive()) { ++ return false; + } -+ 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 } public void e() { + this.a.a((Entity) this.a.getGoalTarget(), 10.0F, 10.0F); + ((EntitySlime.ControllerMoveSlime) this.a.getControllerMove()).a(this.a.yaw, this.a.dt()); + } ++ ++ // 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 { @@ -0,0 +0,0 @@ public class EntitySlime extends EntityInsentient implements IMonster { } } @@ -119,7 +145,7 @@ index 238f3c7926..586b9a3a66 100644 + // 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 18e7ef80ac..8403c1e01c 100644 +index 18e7ef80a..8403c1e01 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java @@ -0,0 +0,0 @@ public class CraftSlime extends CraftMob implements Slime {