PaperMC/patches/server/0242-Slime-Pathfinder-Events.patch
Nassim Jahnke c0936a71bd
Updated Upstream (Bukkit/CraftBukkit/Spigot) (#9440)
Upstream has released updates that appear to apply and compile correctly.
This update has not been tested by PaperMC and as with ANY update, please do your own testing

Bukkit Changes:
01aa02eb PR-858: Add LivingEntity#playHurtAnimation()
9421320f PR-884: Refinements to new ban API for improved compatibility and correctness
37a60b45 SPIGOT-6455, SPIGOT-7030, PR-750: Improve ban API
4eeb174b All smithing inventories are now the new smithing inventory
f2bb168e PR-880: Add methods to get/set FallingBlock CancelDrop
e7a807fa PR-879: Add Player#sendHealthUpdate()
692b8e96 SPIGOT-7370: Remove float value conversion in plugin.yml
2d033390 SPIGOT-7403: Add direct API for waxed signs
16a08373 PR-876: Add missing Raider API and 'no action ticks'

CraftBukkit Changes:
b60a95c8c PR-1189: Add LivingEntity#playHurtAnimation()
95c335c63 PR-1226: Fix VehicleEnterEvent not being called for certain entities
0a0fc3bee PR-1227: Refinements to new ban API for improved compatibility and correctness
0d0b1e5dc Revert bad change to PathfinderGoalSit causing all cats to sit
648196070 SPIGOT-6455, SPIGOT-7030, PR-1054: Improve ban API
31fe848d6 All smithing inventories are now the new smithing inventory
9a919a143 SPIGOT-7416: SmithItemEvent not firing in Smithing Table
9f64f0d22 PR-1221: Add methods to get/set FallingBlock CancelDrop
3be9ac171 PR-1220: Add Player#sendHealthUpdate()
c1279f775 PR-1209: Clean up various patches
c432e4397 Fix Raider#setCelebrating() implementation
504d96665 SPIGOT-7403: Add direct API for waxed signs
c68c1f1b3 PR-1216: Add missing Raider API and 'no action ticks'
85b89c3dd Increase outdated build delay

Spigot Changes:
9ebce8af Rebuild patches
64b565e6 Rebuild patches
2023-07-04 10:22:56 +02:00

167 lines
7.5 KiB
Diff

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/world/entity/monster/Slime.java b/src/main/java/net/minecraft/world/entity/monster/Slime.java
index 476a9b2db5deac803f1cb3c2cbe88b69cc3da8e5..30779b817db6f8e392036b4ec66e1c5cf50cd0f5 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Slime.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Slime.java
@@ -41,6 +41,12 @@ import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.phys.Vec3;
+// 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;
+// Paper end
// CraftBukkit start
import java.util.ArrayList;
import java.util.List;
@@ -107,6 +113,7 @@ public class Slime extends Mob implements Enemy {
@Override
public void addAdditionalSaveData(CompoundTag nbt) {
super.addAdditionalSaveData(nbt);
+ nbt.putBoolean("Paper.canWander", this.canWander); // Paper
nbt.putInt("Size", this.getSize() - 1);
nbt.putBoolean("wasOnGround", this.wasOnGround);
}
@@ -115,6 +122,11 @@ public class Slime extends Mob implements Enemy {
public void readAdditionalSaveData(CompoundTag nbt) {
this.setSize(nbt.getInt("Size") + 1, false);
super.readAdditionalSaveData(nbt);
+ // Paper start - check exists before loading or this will be loaded as false
+ if (nbt.contains("Paper.canWander")) {
+ this.canWander = nbt.getBoolean("Paper.canWander");
+ }
+ // Paper end
this.wasOnGround = nbt.getBoolean("wasOnGround");
}
@@ -450,7 +462,7 @@ public class Slime extends Mob implements Enemy {
@Override
public boolean canUse() {
- return (this.slime.isInWater() || this.slime.isInLava()) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl;
+ return (this.slime.isInWater() || this.slime.isInLava()) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander && new SlimeSwimEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper
}
@Override
@@ -489,7 +501,15 @@ public class Slime extends Mob implements Enemy {
public boolean canUse() {
LivingEntity entityliving = this.slime.getTarget();
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : this.slime.getMoveControl() instanceof Slime.SlimeMoveControl);
+ // Paper start
+ if (entityliving == null || !entityliving.isAlive()) {
+ return false;
+ }
+ if (!this.slime.canAttack(entityliving)) {
+ return false;
+ }
+ return this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander && new SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent();
+ // Paper end
}
@Override
@@ -502,7 +522,15 @@ public class Slime extends Mob implements Enemy {
public boolean canContinueToUse() {
LivingEntity entityliving = this.slime.getTarget();
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : --this.growTiredTimer > 0);
+ // Paper start
+ if (entityliving == null || !entityliving.isAlive()) {
+ return false;
+ }
+ if (!this.slime.canAttack(entityliving)) {
+ return false;
+ }
+ return --this.growTiredTimer > 0 && this.slime.canWander && new SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent();
+ // Paper end
}
@Override
@@ -527,6 +555,13 @@ public class Slime extends Mob implements Enemy {
}
}
+
+ // Paper start - clear timer and target when goal resets
+ public void stop() {
+ this.growTiredTimer = 0;
+ this.slime.setTarget(null);
+ }
+ // Paper end
}
private static class SlimeRandomDirectionGoal extends Goal {
@@ -542,7 +577,7 @@ public class Slime extends Mob implements Enemy {
@Override
public boolean canUse() {
- return this.slime.getTarget() == null && (this.slime.onGround() || this.slime.isInWater() || this.slime.isInLava() || this.slime.hasEffect(MobEffects.LEVITATION)) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl;
+ return this.slime.getTarget() == null && (this.slime.onGround() || this.slime.isInWater() || this.slime.isInLava() || this.slime.hasEffect(MobEffects.LEVITATION)) && this.slime.getMoveControl() instanceof Slime.SlimeMoveControl && this.slime.canWander; // Paper - add canWander
}
@Override
@@ -550,6 +585,11 @@ public class Slime extends Mob implements Enemy {
if (--this.nextRandomizeTime <= 0) {
this.nextRandomizeTime = this.adjustedTickDelay(40 + this.slime.getRandom().nextInt(60));
this.chosenDegrees = (float) this.slime.getRandom().nextInt(360);
+ // Paper start
+ SlimeChangeDirectionEvent event = new SlimeChangeDirectionEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), this.chosenDegrees);
+ if (!this.slime.canWander || !event.callEvent()) return;
+ this.chosenDegrees = event.getNewYaw();
+ // Paper end
}
MoveControl controllermove = this.slime.getMoveControl();
@@ -574,7 +614,7 @@ public class Slime extends Mob implements Enemy {
@Override
public boolean canUse() {
- return !this.slime.isPassenger();
+ return !this.slime.isPassenger() && this.slime.canWander && new SlimeWanderEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper
}
@Override
@@ -589,4 +629,15 @@ public class Slime extends Mob implements Enemy {
}
}
+
+ // 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 a5b3b08bbac2149e5de8e2933efaad65c4f13b12..743af3b71f2d007290fa4e4da85973b491d95135 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
@@ -34,4 +34,16 @@ public class CraftSlime extends CraftMob implements Slime, CraftEnemy {
public EntityType getType() {
return EntityType.SLIME;
}
+
+ // Paper start
+ @Override
+ public boolean canWander() {
+ return getHandle().canWander();
+ }
+
+ @Override
+ public void setWander(boolean canWander) {
+ getHandle().setWander(canWander);
+ }
+ // Paper end
}