Paper/Spigot-Server-Patches/0339-Slime-Pathfinder-Events.patch

143 lines
6.4 KiB
Diff
Raw Normal View History

From 94377d65907b8bb20d19f0a357e1d37b851b68f6 Mon Sep 17 00:00:00 2001
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
2018-08-24 14:40:14 +00:00
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 238f3c792..586b9a3a6 100644
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
2018-08-24 14:40:14 +00:00
--- 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,11 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
this.setSize(i + 1, false);
this.bD = nbttagcompound.getBoolean("wasOnGround");
+ // Paper start - check exists before loading or this will be loaded as false
+ if (nbttagcompound.hasKey("Paper.canWander")) {
+ this.canWander = nbttagcompound.getBoolean("Paper.canWander");
+ }
+ // Paper end
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
2018-08-24 14:40:14 +00:00
}
public boolean dy() {
@@ -308,7 +314,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
}
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 +333,7 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
}
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 +357,17 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
}
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 +387,16 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
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 +407,16 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
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 +480,15 @@ public class EntitySlime extends EntityInsentient implements IMonster {
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
2018-08-24 14:40:14 +00:00
}
}
}
+
+ // 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 18e7ef80a..8403c1e01 100644
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
2018-08-24 14:40:14 +00:00
--- 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.19.0
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
2018-08-24 14:40:14 +00:00