Paper/Spigot-API-Patches/0140-Slime-Pathfinder-Events.patch

212 lines
6.3 KiB
Diff
Raw Normal View History

From 7384fc53c3bf6e6025a819fd016e540863824bd5 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 16:40:14 +02:00
From: BillyGalbreath <Blake.Galbreath@GMail.com>
Date: Fri, 24 Aug 2018 08:18:27 -0500
Subject: [PATCH] Slime Pathfinder Events
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java
new file mode 100644
index 00000000..f5a3ca3b
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 16:40:14 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeChangeDirectionEvent.java
@@ -0,0 +1,37 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Slime;
+import org.bukkit.event.Cancellable;
+
+/**
+ * Fired when a Slime decides to change it's facing direction.
+ * <p>
+ * This event does not fire for the entity's actual movement. Only when it
+ * is choosing to change direction.
+ */
+public class SlimeChangeDirectionEvent extends SlimePathfindEvent implements Cancellable {
+ private float yaw;
+
+ public SlimeChangeDirectionEvent(Slime slime, float yaw) {
+ super(slime);
+ this.yaw = yaw;
+ }
+
+ /**
+ * Get the new chosen yaw
+ *
+ * @return Chosen yaw
+ */
+ public float getNewYaw() {
+ return yaw;
+ }
+
+ /**
+ * Set the new chosen yaw
+ *
+ * @param yaw Chosen yaw
+ */
+ public void setNewYaw(float yaw) {
+ this.yaw = yaw;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java
new file mode 100644
index 00000000..356bcca8
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 16:40:14 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimePathfindEvent.java
@@ -0,0 +1,49 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Slime;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.entity.EntityEvent;
+
+/**
+ * Fired when a Slime decides to start pathfinding.
+ * <p>
+ * This event does not fire for the entity's actual movement. Only when it
+ * is choosing to start moving.
+ */
+public class SlimePathfindEvent extends EntityEvent implements Cancellable {
+ public SlimePathfindEvent(Slime slime) {
+ super(slime);
+ }
+
+ /**
+ * The Slime that is pathfinding.
+ *
+ * @return The Slime that is pathfinding.
+ */
+ public Slime getEntity() {
+ return (Slime) entity;
+ }
+
+ private static final HandlerList handlers = new HandlerList();
+
+ public HandlerList getHandlers() {
+ return handlers;
+ }
+
+ public static HandlerList getHandlerList() {
+ return handlers;
+ }
+
+ private boolean cancelled = false;
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ cancelled = cancel;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java
new file mode 100644
index 00000000..7c99fb53
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 16:40:14 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeSwimEvent.java
@@ -0,0 +1,16 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Slime;
+import org.bukkit.event.Cancellable;
+
+/**
+ * Fired when a Slime decides to start jumping while swimming in water/lava.
+ * <p>
+ * This event does not fire for the entity's actual movement. Only when it
+ * is choosing to start jumping.
+ */
+public class SlimeSwimEvent extends SlimeWanderEvent implements Cancellable {
+ public SlimeSwimEvent(Slime slime) {
+ super(slime);
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java
new file mode 100644
index 00000000..7c96e326
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 16:40:14 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeTargetLivingEntityEvent.java
@@ -0,0 +1,29 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Slime;
+import org.bukkit.event.Cancellable;
+
+/**
+ * Fired when a Slime decides to change direction to target a LivingEntity.
+ * <p>
+ * This event does not fire for the entity's actual movement. Only when it
+ * is choosing to start moving.
+ */
+public class SlimeTargetLivingEntityEvent extends SlimePathfindEvent implements Cancellable {
+ private final LivingEntity target;
+
+ public SlimeTargetLivingEntityEvent(Slime slime, LivingEntity target) {
+ super(slime);
+ this.target = target;
+ }
+
+ /**
+ * Get the targeted entity
+ *
+ * @return Targeted entity
+ */
+ public LivingEntity getTarget() {
+ return target;
+ }
+}
diff --git a/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java b/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java
new file mode 100644
index 00000000..e55d208c
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 16:40:14 +02:00
--- /dev/null
+++ b/src/main/java/com/destroystokyo/paper/event/entity/SlimeWanderEvent.java
@@ -0,0 +1,16 @@
+package com.destroystokyo.paper.event.entity;
+
+import org.bukkit.entity.Slime;
+import org.bukkit.event.Cancellable;
+
+/**
+ * Fired when a Slime decides to start wandering.
+ * <p>
+ * This event does not fire for the entity's actual movement. Only when it
+ * is choosing to start moving.
+ */
+public class SlimeWanderEvent extends SlimePathfindEvent implements Cancellable {
+ public SlimeWanderEvent(Slime slime) {
+ super(slime);
+ }
+}
diff --git a/src/main/java/org/bukkit/entity/Slime.java b/src/main/java/org/bukkit/entity/Slime.java
index 1119e26e..c4791f95 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 16:40:14 +02:00
--- a/src/main/java/org/bukkit/entity/Slime.java
+++ b/src/main/java/org/bukkit/entity/Slime.java
@@ -14,4 +14,20 @@ public interface Slime extends Mob {
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 16:40:14 +02:00
* @param sz The new size of the slime.
*/
public void setSize(int sz);
+
+ // Paper start
+ /**
+ * Get whether this slime can randomly wander/jump around on its own
+ *
+ * @return true if can wander
+ */
+ public boolean canWander();
+
+ /**
+ * Set whether this slime can randomly wander/jump around on its own
+ *
+ * @param canWander true if can wander
+ */
+ public void setWander(boolean canWander);
+ // Paper end
}
--
Updated Upstream (Bukkit/CraftBukkit/Spigot) Upstream has released updates that appears to apply and compile correctly. This update has not been tested by PaperMC and as with ANY update, please do your own testing Warning: this commit contains more mapping changes from upstream, As always, ensure that you have working backups and test this build before deployment; Developers working on paper will, yet again, need to delete their work/Minecraft/1.13.2 folder Bukkit Changes: 7fca5fd4 SPIGOT-4558: Preserve user order in the face of copied defaults in configurations 15c9b1eb Ignore spurious slot IDs sent by client, e.g. in enchanting tables 5d2a10c5 SPIGOT-3747: Add API for force loaded chunks d6dd2bb3 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent 771db4aa SPIGOT-794: Call EntityPlaceEvent for Minecart placement 55462509 Add InventoryView#getSlotType 2f3ce5b6 Remove EntityTransformEvent and CustomItemTagContainer from draft API f04ad7b6 Make ProjectileLaunchEvent extend EntitySpawnEvent ccb85808 Define EntitySpawnEvent b8cc3ebe Add PlayerItemDamageEvent 184a495d Ease ClassLoader Deadlocks Where Possible 11ac4728 Expand Boolean Prompt Values in Conversation API aae62d51 Added getAllSessionData() to the Conversation API. 9290ff91 Add InventoryView#getInventory API 995e530f Add API to get / set base arrow damage CraftBukkit Changes: c4a67eed SPIGOT-4556: Fix plugins closing inventory during drop events 5be2ddcb Replace version constants with methods to prevent compiler inlining a5b9c7b3 Use API method to create offset command completions 2bc7d1df SPIGOT-3747: Add API for force loaded chunks a408f375 SPIGOT-3538: Add getHitBlockFace for ProjectileHitEvent b54b9409 SPIGOT-2864: Make Arrow / Item setTicksLived behave like FallingBlock 79ded7a8 SPIGOT-1811: Death message not shown on respawn screen b4a4f15d SPIGOT-943: InventoryCloseEvent called on death regardless of open inventory 0afed592 SPIGOT-794: Call EntityPlaceEvent for Minecart placement 2b2d084a Add InventoryView#getSlotType 01a9959a Do not use deprecated ItemSpawnEvent constructor 9642498d SPIGOT-4547: Call EntitySpawnEvent as general spawn fallback event 963f4a5f Add PlayerItemDamageEvent 63db0445 Add API to get / set base arrow damage 531c25d7 Add CraftMagicNumbers.MAPPINGS_VERSION for use by NMS plugins d05c8b14 Mappings Update bd36e200 SPIGOT-4551: Ignore invalid attribute modifier slots Spigot Changes: 518206a1 Remove redundant trove depend 1959ad21 MC-11211,SPIGOT-4552: Fix placing double slabs at y = 255 29ab5e43 SPIGOT-3661: Allow arguments in restart-script 7cc46316 SPIGOT-852: Growth modifiers for beetroots, potatoes, carrots 82e117e1 Squelch "fatal: Resolve operation not in progress" message 0a1a68e7 Mappings Update & Patch Rebuild
2019-01-01 04:15:55 +01:00
2.20.1
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 16:40:14 +02:00