From 56fb9b40b903830fcd769abc4e24e04dbcf573ec Mon Sep 17 00:00:00 2001 From: Auxilor Date: Wed, 2 Mar 2022 20:17:06 +0000 Subject: [PATCH] Added Goal, which EntityGoal and TargetGoal extend from, giving them a shared parent class --- .../eco/core/entities/ai/EntityGoal.java | 10 ++------ .../com/willfp/eco/core/entities/ai/Goal.java | 24 +++++++++++++++++++ .../eco/core/entities/ai/TargetGoal.java | 10 ++------ 3 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 eco-api/src/main/java/com/willfp/eco/core/entities/ai/Goal.java diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoal.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoal.java index cc840334..bd0d67f2 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoal.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/EntityGoal.java @@ -8,14 +8,8 @@ import org.jetbrains.annotations.NotNull; * * @param The type of mob that the goal can be applied to. */ -public interface EntityGoal { - /** - * Add the entity goal to an entity. - * - * @param entity The entity. - * @param priority The priority. - * @return The entity, modified. - */ +public interface EntityGoal extends Goal { + @Override default T addToEntity(@NotNull T entity, int priority) { return EntityController.getFor(entity) .addEntityGoal(priority, this) diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/Goal.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/Goal.java new file mode 100644 index 00000000..e67875ce --- /dev/null +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/Goal.java @@ -0,0 +1,24 @@ +package com.willfp.eco.core.entities.ai; + +import org.bukkit.entity.Mob; +import org.jetbrains.annotations.NotNull; + +/** + * A generic goal for entity AI. + * + * @param The type of mob that the goal can be applied to. + */ +public interface Goal { + /** + * Add the entity goal to an entity. + *

+ * The lower the priority, the higher up the execution order; so + * priority 0 will execute first. Lower priority (higher number) goals + * will only execute if all higher priority goals are stopped. + * + * @param entity The entity. + * @param priority The priority. + * @return The entity, modified. + */ + T addToEntity(@NotNull T entity, int priority); +} diff --git a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoal.java b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoal.java index cdcc5110..244928f2 100644 --- a/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoal.java +++ b/eco-api/src/main/java/com/willfp/eco/core/entities/ai/TargetGoal.java @@ -8,14 +8,8 @@ import org.jetbrains.annotations.NotNull; * * @param The type of mob that the goal can be applied to. */ -public interface TargetGoal { - /** - * Add the target goal to an entity. - * - * @param entity The entity. - * @param priority The priority. - * @return The entity, modified. - */ +public interface TargetGoal extends Goal { + @Override default T addToEntity(@NotNull T entity, int priority) { return EntityController.getFor(entity) .addTargetGoal(priority, this)