2021-06-11 14:02:28 +02:00
|
|
|
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
2021-11-27 09:11:43 +01:00
|
|
|
From: MiniDigger <admin@benndorf.dev>
|
2021-06-11 14:02:28 +02:00
|
|
|
Date: Fri, 3 Jan 2020 16:24:46 +0100
|
|
|
|
Subject: [PATCH] Add Mob Goal API
|
|
|
|
|
|
|
|
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/Goal.java b/src/main/java/com/destroystokyo/paper/entity/ai/Goal.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..c57c5416c88e2070a082403ab0dda9d7f08d2a57
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/Goal.java
|
|
|
|
@@ -0,0 +1,66 @@
|
|
|
|
+package com.destroystokyo.paper.entity.ai;
|
|
|
|
+
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+import java.util.EnumSet;
|
|
|
|
+
|
|
|
|
+import org.bukkit.entity.Mob;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Represents an AI goal of an entity
|
|
|
|
+ */
|
|
|
|
+public interface Goal<T extends Mob> {
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Checks if this goal should be activated
|
|
|
|
+ *
|
|
|
|
+ * @return if this goal should be activated
|
|
|
|
+ */
|
|
|
|
+ boolean shouldActivate();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Checks if this goal should stay active, defaults to {@link Goal#shouldActivate()}
|
|
|
|
+ *
|
|
|
|
+ * @return if this goal should stay active
|
|
|
|
+ */
|
|
|
|
+ default boolean shouldStayActive() {
|
|
|
|
+ return shouldActivate();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Called when this goal gets activated
|
|
|
|
+ */
|
|
|
|
+ default void start() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Called when this goal gets stopped
|
|
|
|
+ */
|
|
|
|
+ default void stop() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Called each tick the goal is activated
|
|
|
|
+ */
|
|
|
|
+ default void tick() {
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * A unique key that identifies this type of goal. Plugins should use their own namespace, not the minecraft
|
|
|
|
+ * namespace. Additionally, this key also specifies to what mobs this goal can be applied to
|
|
|
|
+ *
|
|
|
|
+ * @return the goal key
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ GoalKey<T> getKey();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns a list of all applicable flags for this goal.<br>
|
|
|
|
+ *
|
|
|
|
+ * This method is only called on construction.
|
|
|
|
+ *
|
|
|
|
+ * @return the subtypes.
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ EnumSet<GoalType> getTypes();
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java b/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..9cd98c6fcfa3eb439d9013ef76ef4661175a0e5a
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/GoalKey.java
|
|
|
|
@@ -0,0 +1,64 @@
|
|
|
|
+package com.destroystokyo.paper.entity.ai;
|
|
|
|
+
|
|
|
|
+import com.google.common.base.Objects;
|
|
|
|
+
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+
|
|
|
|
+import java.util.StringJoiner;
|
|
|
|
+
|
|
|
|
+import org.bukkit.NamespacedKey;
|
|
|
|
+import org.bukkit.entity.Mob;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ *
|
|
|
|
+ * Used to identify a Goal. Consists of a {@link NamespacedKey} and the type of mob the goal can be applied to
|
|
|
|
+ *
|
|
|
|
+ * @param <T> the type of mob the goal can be applied to
|
|
|
|
+ */
|
|
|
|
+public class GoalKey<T extends Mob> {
|
|
|
|
+
|
|
|
|
+ private final Class<T> entityClass;
|
|
|
|
+ private final NamespacedKey namespacedKey;
|
|
|
|
+
|
|
|
|
+ private GoalKey(@NotNull Class<T> entityClass, @NotNull NamespacedKey namespacedKey) {
|
|
|
|
+ this.entityClass = entityClass;
|
|
|
|
+ this.namespacedKey = namespacedKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public Class<T> getEntityClass() {
|
|
|
|
+ return entityClass;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public NamespacedKey getNamespacedKey() {
|
|
|
|
+ return namespacedKey;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public boolean equals(Object o) {
|
|
|
|
+ if (this == o) return true;
|
|
|
|
+ if (o == null || getClass() != o.getClass()) return false;
|
|
|
|
+ GoalKey<?> goalKey = (GoalKey<?>) o;
|
|
|
|
+ return Objects.equal(entityClass, goalKey.entityClass) &&
|
|
|
|
+ Objects.equal(namespacedKey, goalKey.namespacedKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public int hashCode() {
|
|
|
|
+ return Objects.hashCode(entityClass, namespacedKey);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String toString() {
|
|
|
|
+ return new StringJoiner(", ", GoalKey.class.getSimpleName() + "[", "]")
|
|
|
|
+ .add("entityClass=" + entityClass)
|
|
|
|
+ .add("namespacedKey=" + namespacedKey)
|
|
|
|
+ .toString();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ public static <A extends Mob> GoalKey<A> of(@NotNull Class<A> entityClass, @NotNull NamespacedKey namespacedKey) {
|
|
|
|
+ return new GoalKey<>(entityClass, namespacedKey);
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/GoalType.java b/src/main/java/com/destroystokyo/paper/entity/ai/GoalType.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..7024c8f484d2460abf3abfe65a29771d814105ec
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/GoalType.java
|
|
|
|
@@ -0,0 +1,17 @@
|
|
|
|
+package com.destroystokyo.paper.entity.ai;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Represents the subtype of a goal. Used by minecraft to disable certain types of goals if needed.
|
|
|
|
+ */
|
|
|
|
+public enum GoalType {
|
|
|
|
+
|
|
|
|
+ MOVE,
|
|
|
|
+ LOOK,
|
|
|
|
+ JUMP,
|
|
|
|
+ TARGET,
|
|
|
|
+ /**
|
|
|
|
+ * Used to map vanilla goals, that are a behavior goal but don't have a type set...
|
|
|
|
+ */
|
|
|
|
+ UNKNOWN_BEHAVIOR,
|
|
|
|
+
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/com/destroystokyo/paper/entity/ai/MobGoals.java b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoals.java
|
|
|
|
new file mode 100644
|
|
|
|
index 0000000000000000000000000000000000000000..e21f7574763dd4f13794f91bbef192ef66a8f5e9
|
|
|
|
--- /dev/null
|
|
|
|
+++ b/src/main/java/com/destroystokyo/paper/entity/ai/MobGoals.java
|
|
|
|
@@ -0,0 +1,50 @@
|
|
|
|
+package com.destroystokyo.paper.entity.ai;
|
|
|
|
+
|
|
|
|
+import org.jetbrains.annotations.NotNull;
|
|
|
|
+import org.jetbrains.annotations.Nullable;
|
|
|
|
+
|
|
|
|
+import java.util.Collection;
|
|
|
|
+
|
|
|
|
+import org.bukkit.entity.Mob;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * Represents a part of the "brain" of a mob. It tracks all tasks (running or not), allows adding and removing goals
|
|
|
|
+ */
|
|
|
|
+public interface MobGoals {
|
|
|
|
+
|
|
|
|
+ <T extends Mob> void addGoal(@NotNull T mob, int priority, @NotNull Goal<T> goal);
|
|
|
|
+
|
|
|
|
+ <T extends Mob> void removeGoal(@NotNull T mob, @NotNull Goal<T> goal);
|
|
|
|
+
|
|
|
|
+ <T extends Mob> void removeAllGoals(@NotNull T mob);
|
|
|
|
+
|
|
|
|
+ <T extends Mob> void removeAllGoals(@NotNull T mob, @NotNull GoalType type);
|
|
|
|
+
|
|
|
|
+ <T extends Mob> void removeGoal(@NotNull T mob, @NotNull GoalKey<T> key);
|
|
|
|
+
|
|
|
|
+ <T extends Mob> boolean hasGoal(@NotNull T mob, @NotNull GoalKey<T> key);
|
|
|
|
+
|
|
|
|
+ @Nullable
|
|
|
|
+ <T extends Mob> Goal<T> getGoal(@NotNull T mob, @NotNull GoalKey<T> key);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getGoals(@NotNull T mob, @NotNull GoalKey<T> key);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getAllGoals(@NotNull T mob);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getAllGoals(@NotNull T mob, @NotNull GoalType type);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getAllGoalsWithout(@NotNull T mob, @NotNull GoalType type);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(@NotNull T mob);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getRunningGoals(@NotNull T mob, @NotNull GoalType type);
|
|
|
|
+
|
|
|
|
+ @NotNull
|
|
|
|
+ <T extends Mob> Collection<Goal<T>> getRunningGoalsWithout(@NotNull T mob, @NotNull GoalType type);
|
|
|
|
+}
|
|
|
|
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
|
2024-01-15 20:36:10 +01:00
|
|
|
index 29cf7359334144d6e718fed560771be35f580b16..5c508045a53d9f6efe6358648daa47c0096ad55e 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Bukkit.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Bukkit.java
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -2493,6 +2493,16 @@ public final class Bukkit {
|
2021-06-11 14:02:28 +02:00
|
|
|
public static boolean isStopping() {
|
|
|
|
return server.isStopping();
|
|
|
|
}
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the {@link com.destroystokyo.paper.entity.ai.MobGoals} manager
|
|
|
|
+ *
|
|
|
|
+ * @return the mob goals manager
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ public static com.destroystokyo.paper.entity.ai.MobGoals getMobGoals() {
|
|
|
|
+ return server.getMobGoals();
|
|
|
|
+ }
|
|
|
|
// Paper end
|
|
|
|
|
|
|
|
@NotNull
|
|
|
|
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
|
2024-01-15 20:36:10 +01:00
|
|
|
index d97200a8816dbbbce07734b5547a942f8f3f0fdc..aec7814485efb0b827ccfde92372a436d47ed2f5 100644
|
2021-06-11 14:02:28 +02:00
|
|
|
--- a/src/main/java/org/bukkit/Server.java
|
|
|
|
+++ b/src/main/java/org/bukkit/Server.java
|
Updated Upstream (Bukkit/CraftBukkit) (#10034)
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:
f29cb801 Separate checkstyle-suppressions file is not required
86f99bbe SPIGOT-7540, PR-946: Add ServerTickManager API
d4119585 SPIGOT-6903, PR-945: Add BlockData#getMapColor
b7a2ed41 SPIGOT-7530, PR-947: Add Player#removeResourcePack
9dd56255 SPIGOT-7527, PR-944: Add WindCharge#explode()
994a6163 Attempt upgrade of resolver libraries
CraftBukkit Changes:
b3b43a6ad Add Checkstyle check for unused imports
13fb3358e SPIGOT-7544: Scoreboard#getEntries() doesn't get entries but class names
3dda99c06 SPIGOT-7540, PR-1312: Add ServerTickManager API
2ab4508c0 SPIGOT-6903, PR-1311: Add BlockData#getMapColor
1dbdbbed4 PR-1238: Remove unnecessary sign ticking
659728d2a MC-264285, SPIGOT-7439, PR-1237: Fix unbreakable flint and steel is completely consumed while igniting creeper
e37e29ce0 Increase outdated build delay
c00438b39 SPIGOT-7530, PR-1313: Add Player#removeResourcePack
492dd80ce SPIGOT-7527, PR-1310: Add WindCharge#explode()
e11fbb9d7 Upgrade MySQL driver
9f3a0bd2a Attempt upgrade of resolver libraries
60d16d7ca PR-1306: Centralize Bukkit and Minecraft entity conversion
Spigot Changes:
06d602e7 Rebuild patches
2023-12-17 03:09:28 +01:00
|
|
|
@@ -2172,5 +2172,13 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
|
2021-06-11 14:02:28 +02:00
|
|
|
* @return true if server is in the process of being shutdown
|
|
|
|
*/
|
|
|
|
boolean isStopping();
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * Returns the {@link com.destroystokyo.paper.entity.ai.MobGoals} manager
|
|
|
|
+ *
|
|
|
|
+ * @return the mob goals manager
|
|
|
|
+ */
|
|
|
|
+ @NotNull
|
|
|
|
+ com.destroystokyo.paper.entity.ai.MobGoals getMobGoals();
|
|
|
|
// Paper end
|
|
|
|
}
|