diff --git a/paper-server/patches/sources/net/minecraft/world/entity/monster/Slime.java.patch b/paper-server/patches/sources/net/minecraft/world/entity/monster/Slime.java.patch index 07e8b608d3..aec78f1edd 100644 --- a/paper-server/patches/sources/net/minecraft/world/entity/monster/Slime.java.patch +++ b/paper-server/patches/sources/net/minecraft/world/entity/monster/Slime.java.patch @@ -15,7 +15,27 @@ public class Slime extends Mob implements Enemy { -@@ -197,11 +205,18 @@ +@@ -111,6 +119,7 @@ + @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); + } +@@ -119,6 +128,11 @@ + public void readAdditionalSaveData(CompoundTag nbt) { + this.setSize(nbt.getInt("Size") + 1, false); + super.readAdditionalSaveData(nbt); ++ // Paper start ++ if (nbt.contains("Paper.canWander")) { ++ this.canWander = nbt.getBoolean("Paper.canWander"); ++ } ++ // Paper end + this.wasOnGround = nbt.getBoolean("wasOnGround"); + } + +@@ -197,11 +211,18 @@ @Override public EntityType getType() { @@ -35,11 +55,10 @@ int i = this.getSize(); if (!this.level().isClientSide && i > 1 && this.isDeadOrDying()) { -@@ -210,19 +225,46 @@ - int j = i / 2; +@@ -211,18 +232,45 @@ int k = 2 + this.random.nextInt(3); PlayerTeam scoreboardteam = this.getTeam(); -+ + + // CraftBukkit start + SlimeSplitEvent event = new SlimeSplitEvent((org.bukkit.entity.Slime) this.getBukkitEntity(), k); + this.level().getCraftServer().getPluginManager().callEvent(event); @@ -52,7 +71,7 @@ + } + List slimes = new ArrayList<>(j); + // CraftBukkit end - ++ for (int l = 0; l < k; ++l) { float f2 = ((float) (l % 2) - 0.5F) * f1; float f3 = ((float) (l / 2) - 0.5F) * f1; @@ -68,12 +87,12 @@ + slimes.add(converted); + } + // CraftBukkit end -+ } + } + // CraftBukkit start + if (CraftEventFactory.callEntityTransformEvent(this, slimes, EntityTransformEvent.TransformReason.SPLIT).isCancelled()) { + super.remove(entity_removalreason, cause); // CraftBukkit - add Bukkit remove cause + return; - } ++ } + for (LivingEntity living : slimes) { + this.level().addFreshEntity(living, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.SLIME_SPLIT); // CraftBukkit - SpawnReason + } @@ -85,7 +104,7 @@ } @Override -@@ -300,7 +342,7 @@ +@@ -300,7 +348,7 @@ } ChunkPos chunkcoordintpair = new ChunkPos(pos); @@ -94,3 +113,106 @@ if (random.nextInt(10) == 0 && flag && pos.getY() < 40) { return checkMobSpawnRules(type, world, spawnReason, pos, random); +@@ -432,7 +480,7 @@ + + @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 com.destroystokyo.paper.event.entity.SlimeSwimEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper - Slime pathfinder events + } + + @Override +@@ -469,7 +517,15 @@ + 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 - Slime pathfinder events ++ 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 com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent(); ++ // Paper end - Slime pathfinder events + } + + @Override +@@ -482,7 +538,15 @@ + public boolean canContinueToUse() { + LivingEntity entityliving = this.slime.getTarget(); + +- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : --this.growTiredTimer > 0); ++ // Paper start - Slime pathfinder events ++ if (entityliving == null || !entityliving.isAlive()) { ++ return false; ++ } ++ if (!this.slime.canAttack(entityliving)) { ++ return false; ++ } ++ return --this.growTiredTimer > 0 && this.slime.canWander && new com.destroystokyo.paper.event.entity.SlimeTargetLivingEntityEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), (org.bukkit.entity.LivingEntity) entityliving.getBukkitEntity()).callEvent(); ++ // Paper end - Slime pathfinder events + } + + @Override +@@ -505,6 +569,13 @@ + } + + } ++ ++ // Paper start - Slime pathfinder events; clear timer and target when goal resets ++ public void stop() { ++ this.growTiredTimer = 0; ++ this.slime.setTarget(null); ++ } ++ // Paper end - Slime pathfinder events + } + + private static class SlimeRandomDirectionGoal extends Goal { +@@ -520,7 +591,7 @@ + + @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 - Slime pathfinder events + } + + @Override +@@ -528,6 +599,11 @@ + if (--this.nextRandomizeTime <= 0) { + this.nextRandomizeTime = this.adjustedTickDelay(40 + this.slime.getRandom().nextInt(60)); + this.chosenDegrees = (float) this.slime.getRandom().nextInt(360); ++ // Paper start - Slime pathfinder events ++ com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent event = new com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), this.chosenDegrees); ++ if (!this.slime.canWander || !event.callEvent()) return; ++ this.chosenDegrees = event.getNewYaw(); ++ // Paper end - Slime pathfinder events + } + + MoveControl controllermove = this.slime.getMoveControl(); +@@ -550,7 +626,7 @@ + + @Override + public boolean canUse() { +- return !this.slime.isPassenger(); ++ return !this.slime.isPassenger() && this.slime.canWander && new com.destroystokyo.paper.event.entity.SlimeWanderEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper - Slime pathfinder events + } + + @Override +@@ -563,4 +639,15 @@ + + } + } ++ ++ // Paper start - Slime pathfinder events ++ private boolean canWander = true; ++ public boolean canWander() { ++ return canWander; ++ } ++ ++ public void setWander(boolean canWander) { ++ this.canWander = canWander; ++ } ++ // Paper end - Slime pathfinder events + } diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java index 3d991d9d93..3d9b7c0e12 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java @@ -28,4 +28,16 @@ public class CraftSlime extends CraftMob implements Slime, CraftEnemy { public String toString() { return "CraftSlime"; } + + // Paper start + @Override + public boolean canWander() { + return getHandle().canWander(); + } + + @Override + public void setWander(boolean canWander) { + getHandle().setWander(canWander); + } + // Paper end }