Class TaskTriggerer<E extends LivingEntity,M>

java.lang.Object
net.minecraft.entity.ai.brain.task.TaskTriggerer<E,M>
All Implemented Interfaces:
com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,M>
Direct Known Subclasses:
TaskTriggerer.QueryMemory, TaskTriggerer.Supply, TaskTriggerer.Trigger

public class TaskTriggerer<E extends LivingEntity,M> extends Object implements com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,M>
A lambda-based alternative to subclassing Task.

To use this,

  1. Make a static method with all configurable parameters (such as speed, range, etc).
  2. If there is a value that needs to be tracked between ticks (such as cooldown), declare a mutable variable (such as MutableInt).
  3. Return the result of task(java.util.function.Function<net.minecraft.entity.ai.brain.task.TaskTriggerer.TaskContext<E>, ? extends com.mojang.datafixers.kinds.App<net.minecraft.entity.ai.brain.task.TaskTriggerer.K1<E>, net.minecraft.entity.ai.brain.task.TaskRunnable<E>>>). This method creates a new SingleTickTask.

A lambda is passed to the task method. This takes a TaskTriggerer.TaskContext. You can either call TaskTriggerer.TaskContext.point(A) to set the actual task function, or declare a dependency on memory queries. The task function is a function that takes the server world, entity, and the current time, and returns a boolean indicating whether a task successfully ran.

Example of memory-independent task


 public static Task<LivingEntity> createHealTask() {
     return TaskTriggerer.task(context -> context.point((world, entity, time) -> {
         entity.heal(1.0f);
         return true;
     }));
 }
 

Memory-dependent task

Memory-dependent tasks (i.e. one that queries, remembers, or forgets a memory) first should call TaskContext.group with results of Context.queryMemory methods for all the dependent memories. Then, call apply with context and a lambda function taking the results of the query. This function returns the task function seen earlier.

If any of the query is not successful (e.g. because a value was not present), the task will not run. If all succeed, then the task runs, and the query result can be obtained via TaskTriggerer.TaskContext.getValue(net.minecraft.entity.ai.brain.MemoryQueryResult<com.mojang.datafixers.kinds.IdF.Mu, Value>).

There are three query types:

For example, the following code queries MemoryModuleType.MEETING_POINT and forgets it:


 public static Task<LivingEntity> createForgetMeetingPointTask() {
     return TaskTriggerer.task(context -> context.group(context.queryMemoryValue(MemoryModuleType.MEETING_POINT)).apply(context, meetingPoint -> (world, entity, time) -> {
         GlobalPos pos = (GlobalPos)context.getValue(meetingPoint);
         // Do something with meetingPoint or pos
         // For example, forget the meeting point:
         meetingPoint.forget();
         return true;
     }));
 }
 
Mappings:
Namespace Name
named net/minecraft/entity/ai/brain/task/TaskTriggerer
intermediary net/minecraft/class_7898
official cbl
  • Field Details

    • function

      private final TaskTriggerer.TaskFunction<E extends LivingEntity,M> function
      Mappings:
      Namespace Name Mixin selector
      named function Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;function:Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;
      intermediary field_40998 Lnet/minecraft/class_7898;field_40998:Lnet/minecraft/class_7898$class_7904;
      official a Lcbl;a:Lcbl$e;
  • Constructor Details

    • TaskTriggerer

      TaskTriggerer(TaskTriggerer.TaskFunction<E,M> function)
      Mappings:
      Namespace Name Mixin selector
      named <init> Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;<init>(Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;)V
      intermediary <init> Lnet/minecraft/class_7898;<init>(Lnet/minecraft/class_7898$class_7904;)V
      official <init> Lcbl;<init>(Lcbl$e;)V
  • Method Details

    • cast

      public static <E extends LivingEntity, M> TaskTriggerer<E,M> cast(com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,M> app)
      Mappings:
      Namespace Name Mixin selector
      named cast Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;cast(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;
      intermediary method_47220 Lnet/minecraft/class_7898;method_47220(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/class_7898;
      official a Lcbl;a(Lcom/mojang/datafixers/kinds/App;)Lcbl;
    • newContext

      public static <E extends LivingEntity> TaskTriggerer.TaskContext<E> newContext()
      Mappings:
      Namespace Name Mixin selector
      named newContext Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;newContext()Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskContext;
      intermediary method_47215 Lnet/minecraft/class_7898;method_47215()Lnet/minecraft/class_7898$class_7900;
      official a Lcbl;a()Lcbl$b;
    • task

      public static <E extends LivingEntity> SingleTickTask<E> task(Function<TaskTriggerer.TaskContext<E>,? extends com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,TaskRunnable<E>>> creator)
      Mappings:
      Namespace Name Mixin selector
      named task Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;task(Ljava/util/function/Function;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
      intermediary method_47224 Lnet/minecraft/class_7898;method_47224(Ljava/util/function/Function;)Lnet/minecraft/class_7894;
      official a Lcbl;a(Ljava/util/function/Function;)Lbzj;
    • runIf

      public static <E extends LivingEntity> SingleTickTask<E> runIf(TaskRunnable<? super E> predicate, TaskRunnable<? super E> task)
      Mappings:
      Namespace Name Mixin selector
      named runIf Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;runIf(Lnet/minecraft/entity/ai/brain/task/TaskRunnable;Lnet/minecraft/entity/ai/brain/task/TaskRunnable;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
      intermediary method_47217 Lnet/minecraft/class_7898;method_47217(Lnet/minecraft/class_7911;Lnet/minecraft/class_7911;)Lnet/minecraft/class_7894;
      official a Lcbl;a(Lcbo;Lcbo;)Lbzj;
    • runIf

      public static <E extends LivingEntity> SingleTickTask<E> runIf(Predicate<E> predicate, SingleTickTask<? super E> task)
      Mappings:
      Namespace Name Mixin selector
      named runIf Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;runIf(Ljava/util/function/Predicate;Lnet/minecraft/entity/ai/brain/task/SingleTickTask;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
      intermediary method_47227 Lnet/minecraft/class_7898;method_47227(Ljava/util/function/Predicate;Lnet/minecraft/class_7894;)Lnet/minecraft/class_7894;
      official a Lcbl;a(Ljava/util/function/Predicate;Lbzj;)Lbzj;
    • predicate

      public static <E extends LivingEntity> SingleTickTask<E> predicate(Predicate<E> predicate)
      Mappings:
      Namespace Name Mixin selector
      named predicate Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;predicate(Ljava/util/function/Predicate;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
      intermediary method_47225 Lnet/minecraft/class_7898;method_47225(Ljava/util/function/Predicate;)Lnet/minecraft/class_7894;
      official a Lcbl;a(Ljava/util/function/Predicate;)Lbzj;
    • predicate

      public static <E extends LivingEntity> SingleTickTask<E> predicate(BiPredicate<ServerWorld,E> predicate)
      Mappings:
      Namespace Name Mixin selector
      named predicate Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;predicate(Ljava/util/function/BiPredicate;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
      intermediary method_47221 Lnet/minecraft/class_7898;method_47221(Ljava/util/function/BiPredicate;)Lnet/minecraft/class_7894;
      official a Lcbl;a(Ljava/util/function/BiPredicate;)Lbzj;
    • getFunction

      static <E extends LivingEntity, M> TaskTriggerer.TaskFunction<E,M> getFunction(com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,M> app)
      Mappings:
      Namespace Name Mixin selector
      named getFunction Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;getFunction(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;
      intermediary method_47229 Lnet/minecraft/class_7898;method_47229(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/class_7898$class_7904;
      official b Lcbl;b(Lcom/mojang/datafixers/kinds/App;)Lcbl$e;
    • of

      static <E extends LivingEntity, M> TaskTriggerer<E,M> of(TaskTriggerer.TaskFunction<E,M> function)
      Mappings:
      Namespace Name Mixin selector
      named of Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;of(Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;)Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;
      intermediary method_47216 Lnet/minecraft/class_7898;method_47216(Lnet/minecraft/class_7898$class_7904;)Lnet/minecraft/class_7898;
      official a Lcbl;a(Lcbl$e;)Lcbl;