Added Goal<T>, which EntityGoal<T> and TargetGoal<T> extend from, giving them a shared parent class

This commit is contained in:
Auxilor
2022-03-02 20:17:06 +00:00
parent fbc7bb6f07
commit 56fb9b40b9
3 changed files with 28 additions and 16 deletions

View File

@@ -8,14 +8,8 @@ import org.jetbrains.annotations.NotNull;
*
* @param <T> The type of mob that the goal can be applied to.
*/
public interface EntityGoal<T extends Mob> {
/**
* Add the entity goal to an entity.
*
* @param entity The entity.
* @param priority The priority.
* @return The entity, modified.
*/
public interface EntityGoal<T extends Mob> extends Goal<T> {
@Override
default T addToEntity(@NotNull T entity, int priority) {
return EntityController.getFor(entity)
.addEntityGoal(priority, this)

View File

@@ -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 <T> The type of mob that the goal can be applied to.
*/
public interface Goal<T extends Mob> {
/**
* Add the entity goal to an entity.
* <p>
* 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);
}

View File

@@ -8,14 +8,8 @@ import org.jetbrains.annotations.NotNull;
*
* @param <T> The type of mob that the goal can be applied to.
*/
public interface TargetGoal<T extends Mob> {
/**
* Add the target goal to an entity.
*
* @param entity The entity.
* @param priority The priority.
* @return The entity, modified.
*/
public interface TargetGoal<T extends Mob> extends Goal<T> {
@Override
default T addToEntity(@NotNull T entity, int priority) {
return EntityController.getFor(entity)
.addTargetGoal(priority, this)