Class TaskTriggerer<E extends LivingEntity,M>
- All Implemented Interfaces:
com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>,
M>
- Direct Known Subclasses:
TaskTriggerer.QueryMemory
,TaskTriggerer.Supply
,TaskTriggerer.Trigger
Task
.
To use this,
- Make a static method with all configurable parameters (such as speed, range, etc).
- If there is a value that needs to be tracked between ticks (such as cooldown),
declare a mutable variable (such as
MutableInt
). - 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 newSingleTickTask
.
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:
TaskTriggerer.TaskContext.queryMemoryAbsent(net.minecraft.entity.ai.brain.MemoryModuleType<Value>)
that succeeds if a value is not present in the memory.TaskTriggerer.TaskContext.queryMemoryValue(net.minecraft.entity.ai.brain.MemoryModuleType<Value>)
that succeeds if a value is present in the memory. The result is the queried value.TaskTriggerer.TaskContext.queryMemoryOptional(net.minecraft.entity.ai.brain.MemoryModuleType<Value>)
that always succeeds. The value is an optional that contains the value if it is present in the memory.
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 official blb
intermediary net/minecraft/class_7898
named net/minecraft/entity/ai/brain/task/TaskTriggerer
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
TaskTriggerer.K1<E extends LivingEntity>
private static final class
TaskTriggerer.QueryMemory<E extends LivingEntity,
F extends com.mojang.datafixers.kinds.K1, Value> private static final class
TaskTriggerer.Supply<E extends LivingEntity,
A> static final class
TaskTriggerer.TaskContext<E extends LivingEntity>
private static interface
TaskTriggerer.TaskFunction<E extends LivingEntity,
R> private static final class
TaskTriggerer.Trigger<E extends LivingEntity>
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic <E extends LivingEntity,
M>
TaskTriggerer<E,M> cast
(com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>, M> app) (package private) static <E extends LivingEntity,
M>
TaskTriggerer.TaskFunction<E,M> getFunction
(com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>, M> app) static <E extends LivingEntity>
TaskTriggerer.TaskContext<E>(package private) static <E extends LivingEntity,
M>
TaskTriggerer<E,M> of
(TaskTriggerer.TaskFunction<E, M> function) static <E extends LivingEntity>
SingleTickTask<E>predicate
(BiPredicate<ServerWorld, E> predicate) static <E extends LivingEntity>
SingleTickTask<E>static <E extends LivingEntity>
SingleTickTask<E>runIf
(Predicate<E> predicate, SingleTickTask<? super E> task) static <E extends LivingEntity>
SingleTickTask<E>runIf
(TaskRunnable<? super E> predicate, TaskRunnable<? super E> task) static <E extends LivingEntity>
SingleTickTask<E>task
(Function<TaskTriggerer.TaskContext<E>, ? extends com.mojang.datafixers.kinds.App<TaskTriggerer.K1<E>, TaskRunnable<E>>> creator)
-
Field Details
-
function
- Mappings:
Namespace Name Mixin selector official a
Lblb;a:Lblb$e;
intermediary field_40998
Lnet/minecraft/class_7898;field_40998:Lnet/minecraft/class_7898$class_7904;
named function
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;function:Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;
-
-
Constructor Details
-
TaskTriggerer
TaskTriggerer(TaskTriggerer.TaskFunction<E, M> function) - Mappings:
Namespace Name Mixin selector official <init>
Lblb;<init>(Lblb$e;)V
intermediary <init>
Lnet/minecraft/class_7898;<init>(Lnet/minecraft/class_7898$class_7904;)V
named <init>
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;<init>(Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;)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 official a
Lblb;a(Lcom/mojang/datafixers/kinds/App;)Lblb;
intermediary method_47220
Lnet/minecraft/class_7898;method_47220(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/class_7898;
named cast
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;cast(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;
-
newContext
- Mappings:
Namespace Name Mixin selector official a
Lblb;a()Lblb$b;
intermediary method_47215
Lnet/minecraft/class_7898;method_47215()Lnet/minecraft/class_7898$class_7900;
named newContext
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;newContext()Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskContext;
-
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 official a
Lblb;a(Ljava/util/function/Function;)Lbiz;
intermediary method_47224
Lnet/minecraft/class_7898;method_47224(Ljava/util/function/Function;)Lnet/minecraft/class_7894;
named task
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;task(Ljava/util/function/Function;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
-
runIf
public static <E extends LivingEntity> SingleTickTask<E> runIf(TaskRunnable<? super E> predicate, TaskRunnable<? super E> task) - Mappings:
Namespace Name Mixin selector official a
Lblb;a(Lble;Lble;)Lbiz;
intermediary method_47217
Lnet/minecraft/class_7898;method_47217(Lnet/minecraft/class_7911;Lnet/minecraft/class_7911;)Lnet/minecraft/class_7894;
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;
-
runIf
public static <E extends LivingEntity> SingleTickTask<E> runIf(Predicate<E> predicate, SingleTickTask<? super E> task) - Mappings:
Namespace Name Mixin selector official a
Lblb;a(Ljava/util/function/Predicate;Lbiz;)Lbiz;
intermediary method_47227
Lnet/minecraft/class_7898;method_47227(Ljava/util/function/Predicate;Lnet/minecraft/class_7894;)Lnet/minecraft/class_7894;
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;
-
predicate
- Mappings:
Namespace Name Mixin selector official a
Lblb;a(Ljava/util/function/Predicate;)Lbiz;
intermediary method_47225
Lnet/minecraft/class_7898;method_47225(Ljava/util/function/Predicate;)Lnet/minecraft/class_7894;
named predicate
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;predicate(Ljava/util/function/Predicate;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
-
predicate
public static <E extends LivingEntity> SingleTickTask<E> predicate(BiPredicate<ServerWorld, E> predicate) - Mappings:
Namespace Name Mixin selector official a
Lblb;a(Ljava/util/function/BiPredicate;)Lbiz;
intermediary method_47221
Lnet/minecraft/class_7898;method_47221(Ljava/util/function/BiPredicate;)Lnet/minecraft/class_7894;
named predicate
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;predicate(Ljava/util/function/BiPredicate;)Lnet/minecraft/entity/ai/brain/task/SingleTickTask;
-
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 official b
Lblb;b(Lcom/mojang/datafixers/kinds/App;)Lblb$e;
intermediary method_47229
Lnet/minecraft/class_7898;method_47229(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/class_7898$class_7904;
named getFunction
Lnet/minecraft/entity/ai/brain/task/TaskTriggerer;getFunction(Lcom/mojang/datafixers/kinds/App;)Lnet/minecraft/entity/ai/brain/task/TaskTriggerer$TaskFunction;
-
of
- Mappings:
Namespace Name Mixin selector official a
Lblb;a(Lblb$e;)Lblb;
intermediary method_47216
Lnet/minecraft/class_7898;method_47216(Lnet/minecraft/class_7898$class_7904;)Lnet/minecraft/class_7898;
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;
-