| 1 | package net.minecraft.commands.execution.tasks;
|
| 2 |
|
| 3 | import java.util.List;
|
| 4 | import net.minecraft.commands.CommandResultCallback;
|
| 5 | import net.minecraft.commands.ExecutionCommandSource;
|
| 6 | import net.minecraft.commands.execution.CommandQueueEntry;
|
| 7 | import net.minecraft.commands.execution.ExecutionContext;
|
| 8 | import net.minecraft.commands.execution.Frame;
|
| 9 | import net.minecraft.commands.execution.TraceCallbacks;
|
| 10 | import net.minecraft.commands.execution.UnboundEntryAction;
|
| 11 | import net.minecraft.commands.functions.InstantiatedFunction;
|
| 12 |
|
| 13 | public class CallFunction<T extends ExecutionCommandSource<T>> implements UnboundEntryAction<T> {
|
| 14 | private final InstantiatedFunction<T> function;
|
| 15 | private final CommandResultCallback resultCallback;
|
| 16 | private final boolean returnParentFrame;
|
| 17 |
|
| 18 | public CallFunction(final InstantiatedFunction<T> function, final CommandResultCallback resultCallback, final boolean returnParentFrame) {
|
| 19 | this.function = function;
|
| 20 | this.resultCallback = resultCallback;
|
| 21 | this.returnParentFrame = returnParentFrame;
|
| 22 | }
|
| 23 |
|
| 24 | public void execute(final T sender, final ExecutionContext<T> context, final Frame frame) {
|
| 25 | context.incrementCost();
|
| 26 | List<UnboundEntryAction<T>> contents = this.function.entries();
|
| 27 | TraceCallbacks tracer = context.tracer();
|
| 28 | if (tracer != null) {
|
| 29 | tracer.onCall(frame.depth(), this.function.id(), this.function.entries().size());
|
| 30 | }
|
| 31 |
|
| 32 | int newDepth = frame.depth() + 1;
|
| 33 | Frame.FrameControl frameControl = this.returnParentFrame ? frame.frameControl() : context.frameControlForDepth(newDepth);
|
| 34 | Frame newFrame = new Frame(newDepth, this.resultCallback, frameControl);
|
| 35 | ContinuationTask.schedule(context, newFrame, contents, (frame1, entryAction) -> new CommandQueueEntry<>(frame1, entryAction.bind(sender)));
|
| 36 | }
|
| 37 | }
|
| 38 |
|