PaperMC/patches/server/Slime-Pathfinder-Events.patch

155 lines
7.3 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/monster/Slime.java
+++ b/src/main/java/net/minecraft/world/entity/monster/Slime.java
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
@Override
2021-06-13 01:45:00 +02:00
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);
2021-06-11 14:02:28 +02:00
}
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
2021-06-13 01:45:00 +02:00
public void readAdditionalSaveData(CompoundTag nbt) {
this.setSize(nbt.getInt("Size") + 1, false);
super.readAdditionalSaveData(nbt);
+ // Paper start
2021-06-13 01:45:00 +02:00
+ if (nbt.contains("Paper.canWander")) {
+ this.canWander = nbt.getBoolean("Paper.canWander");
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
2021-06-13 01:45:00 +02:00
this.wasOnGround = nbt.getBoolean("wasOnGround");
2021-06-11 14:02:28 +02:00
}
@@ -0,0 +0,0 @@ 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 com.destroystokyo.paper.event.entity.SlimeSwimEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity()).callEvent(); // Paper - Slime pathfinder events
2021-06-11 14:02:28 +02:00
}
@Override
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
public boolean canUse() {
2021-06-13 01:45:00 +02:00
LivingEntity entityliving = this.slime.getTarget();
2021-06-11 14:02:28 +02:00
2021-06-13 01:45:00 +02:00
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : this.slime.getMoveControl() instanceof Slime.SlimeMoveControl);
+ // Paper start - Slime pathfinder events
2021-06-11 14:02:28 +02:00
+ if (entityliving == null || !entityliving.isAlive()) {
+ return false;
+ }
2021-06-13 01:45:00 +02:00
+ if (!this.slime.canAttack(entityliving)) {
2021-06-11 14:02:28 +02:00
+ return false;
+ }
2023-09-22 00:01:00 +02:00
+ 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
2021-06-11 14:02:28 +02:00
}
@Override
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
public boolean canContinueToUse() {
2021-06-13 01:45:00 +02:00
LivingEntity entityliving = this.slime.getTarget();
2021-06-11 14:02:28 +02:00
2021-06-13 01:45:00 +02:00
- return entityliving == null ? false : (!this.slime.canAttack(entityliving) ? false : --this.growTiredTimer > 0);
+ // Paper start - Slime pathfinder events
2021-06-11 14:02:28 +02:00
+ if (entityliving == null || !entityliving.isAlive()) {
+ return false;
+ }
2021-06-13 01:45:00 +02:00
+ if (!this.slime.canAttack(entityliving)) {
2021-06-11 14:02:28 +02:00
+ return false;
+ }
2023-09-22 00:01:00 +02:00
+ 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
2021-06-11 14:02:28 +02:00
}
@Override
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
2023-03-14 19:59:51 +01:00
}
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start - Slime pathfinder events; clear timer and target when goal resets
2021-06-11 14:02:28 +02:00
+ public void stop() {
+ this.growTiredTimer = 0;
+ this.slime.setTarget(null);
+ }
+ // Paper end - Slime pathfinder events
2021-06-11 14:02:28 +02:00
}
2021-06-13 01:45:00 +02:00
private static class SlimeRandomDirectionGoal extends Goal {
2021-06-11 14:02:28 +02:00
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
2021-06-13 01:45:00 +02:00
@Override
public boolean canUse() {
2023-06-07 22:19:14 +02:00
- 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
2021-06-13 01:45:00 +02:00
}
@Override
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
2021-06-13 01:45:00 +02:00
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
2023-09-22 00:01:00 +02:00
+ com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent event = new com.destroystokyo.paper.event.entity.SlimeChangeDirectionEvent((org.bukkit.entity.Slime) this.slime.getBukkitEntity(), this.chosenDegrees);
2021-06-13 01:45:00 +02:00
+ if (!this.slime.canWander || !event.callEvent()) return;
+ this.chosenDegrees = event.getNewYaw();
+ // Paper end - Slime pathfinder events
2021-06-11 14:02:28 +02:00
}
2021-06-13 01:45:00 +02:00
2023-03-14 19:59:51 +01:00
MoveControl controllermove = this.slime.getMoveControl();
2021-06-13 01:45:00 +02:00
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
@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
2021-06-13 01:45:00 +02:00
}
@Override
@@ -0,0 +0,0 @@ public class Slime extends Mob implements Enemy {
2023-03-14 19:59:51 +01:00
2021-06-11 14:02:28 +02:00
}
}
+
+ // Paper start - Slime pathfinder events
2021-06-11 14:02:28 +02:00
+ private boolean canWander = true;
+ public boolean canWander() {
+ return canWander;
+ }
+
+ public void setWander(boolean canWander) {
+ this.canWander = canWander;
+ }
+ // Paper end - Slime pathfinder events
2021-06-11 14:02:28 +02:00
}
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftSlime.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 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, CraftEnemy {
public String toString() {
return "CraftSlime";
2021-06-11 14:02:28 +02:00
}
+
+ // Paper start
2021-06-13 01:45:00 +02:00
+ @Override
2021-06-11 14:02:28 +02:00
+ public boolean canWander() {
+ return getHandle().canWander();
+ }
+
2021-06-13 01:45:00 +02:00
+ @Override
2021-06-11 14:02:28 +02:00
+ public void setWander(boolean canWander) {
+ getHandle().setWander(canWander);
+ }
+ // Paper end
}