Continued work on entity controllers

This commit is contained in:
Auxilor
2022-03-01 21:01:00 +00:00
parent 2c51a6900f
commit 957af5c5bf
13 changed files with 298 additions and 227 deletions

View File

@@ -5,7 +5,7 @@ import com.willfp.eco.core.config.wrapper.ConfigFactory;
import com.willfp.eco.core.data.ProfileHandler;
import com.willfp.eco.core.data.keys.KeyRegistry;
import com.willfp.eco.core.drops.DropQueueFactory;
import com.willfp.eco.core.entities.ai.ControlledEntity;
import com.willfp.eco.core.entities.ai.EntityController;
import com.willfp.eco.core.events.EventManager;
import com.willfp.eco.core.extensions.ExtensionLoader;
import com.willfp.eco.core.factory.MetadataValueFactory;
@@ -269,8 +269,9 @@ public interface Handler {
* Create controlled entity from a mob.
*
* @param mob The mob.
* @param <T> The mob type.
* @return The controlled entity.
*/
@NotNull
ControlledEntity createControlledEntity(@NotNull Mob mob);
<T extends Mob> EntityController<T> createEntityController(@NotNull T mob);
}

View File

@@ -1,49 +0,0 @@
package com.willfp.eco.core.entities.ai;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.entities.ai.goals.EntityGoal;
import com.willfp.eco.core.entities.ai.goals.TargetGoal;
import org.bukkit.entity.Mob;
import org.jetbrains.annotations.NotNull;
/**
* A controlled entity allows for adding targets and goals to entities.
*/
public interface ControlledEntity {
/**
* Add a target to the entity.
*
* @param priority The priority.
* @param goal The goal.
* @return The entity.
*/
ControlledEntity addTargetGoal(int priority,
@NotNull TargetGoal goal);
/**
* Add a goal to the entity.
*
* @param priority The priority.
* @param goal The goal.
* @return The entity.
*/
ControlledEntity addEntityGoal(int priority,
@NotNull EntityGoal goal);
/**
* Get the mob back from the controlled entity.
*
* @return The mob.
*/
Mob getEntity();
/**
* Wrap an entity into a controlled entity in order to modify targets and goals.
*
* @param entity The entity.
* @return The controlled entity.
*/
static ControlledEntity from(@NotNull final Mob entity) {
return Eco.getHandler().createControlledEntity(entity);
}
}

View File

@@ -0,0 +1,58 @@
package com.willfp.eco.core.entities.ai;
import com.willfp.eco.core.Eco;
import com.willfp.eco.core.entities.ai.goals.EntityGoal;
import com.willfp.eco.core.entities.ai.goals.TargetGoal;
import org.bukkit.entity.Mob;
import org.jetbrains.annotations.NotNull;
/**
* An entity controller allows for adding targets and goals to entities.
*
* @param <T> The wrapped mob.
*/
public interface EntityController<T extends Mob> {
/**
* Add a target to the entity.
* <p>
* Mutates the instance.
*
* @param priority The priority.
* @param goal The goal.
* @return The entity.
*/
EntityController<T> addTargetGoal(int priority,
@NotNull TargetGoal goal);
/**
* Add a goal to the entity.
* <p>
* Mutates the instance.
*
* @param priority The priority.
* @param goal The goal.
* @return The entity.
*/
EntityController<T> addEntityGoal(int priority,
@NotNull EntityGoal goal);
/**
* Get the mob back from the controlled entity.
* <p>
* Not required to apply changes, as the mob instance will be altered.
*
* @return The mob.
*/
T getEntity();
/**
* Create an entity controller for an entity in order to modify targets and goals.
*
* @param entity The entity.
* @param <T> The mob type.
* @return The entity controller.
*/
static <T extends Mob> EntityController<T> of(@NotNull final T entity) {
return Eco.getHandler().createEntityController(entity);
}
}

View File

@@ -0,0 +1,17 @@
package com.willfp.eco.core.entities.ai.goals;
import org.jetbrains.annotations.NotNull;
/**
* A prioritized goal is a goal that has been registered with an entity.
*
* @param goal The goal.
* @param priority The priority.
* @param <T> The type of goal.
*/
public record PrioritizedGoal<T>(
@NotNull T goal,
int priority
) {
}