BuildContexts.java
net.minecraft.commands.execution.tasks.BuildContexts
信息
- 全限定名:net.minecraft.commands.execution.tasks.BuildContexts
- 类型:public class
- 包:net.minecraft.commands.execution.tasks
- 源码路径:src/main/java/net/minecraft/commands/execution/tasks/BuildContexts.java
- 起始行号:L27
- 职责:
TODO
字段/常量
-
ERROR_FORK_LIMIT_REACHED- 类型:
DynamicCommandExceptionType - 修饰符:
public static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
commandInput- 类型:
String - 修饰符:
private final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
command- 类型:
ContextChain<T> - 修饰符:
private final - 源码定位:
L33 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.commands.execution.tasks.BuildContexts.Continuation- 类型:
class - 修饰符:
public static - 源码定位:
L130 - 说明:
TODO
- 类型:
-
net.minecraft.commands.execution.tasks.BuildContexts.TopLevel- 类型:
class - 修饰符:
public static - 源码定位:
L148 - 说明:
TODO
- 类型:
-
net.minecraft.commands.execution.tasks.BuildContexts.Unbound- 类型:
class - 修饰符:
public static - 源码定位:
L163 - 说明:
TODO
- 类型:
构造器
public BuildContexts(String commandInput, ContextChain<T> command) @ L35
- 构造器名:BuildContexts
- 源码定位:L35
- 修饰符:public
参数:
- commandInput: String
- command: ContextChain
说明:
TODO
方法
下面的方法块按源码顺序生成。
protected void execute(T originalSource, List<T> initialSources, ExecutionContext<T> context, Frame frame, ChainModifiers initialModifiers) @ L40
- 方法名:execute
- 源码定位:L40
- 返回类型:void
- 修饰符:protected
参数:
- originalSource: T
- initialSources: List
- context: ExecutionContext
- frame: Frame
- initialModifiers: ChainModifiers
说明:
TODO
protected void traceCommandStart(ExecutionContext<T> context, Frame frame) @ L118
- 方法名:traceCommandStart
- 源码定位:L118
- 返回类型:void
- 修饰符:protected
参数:
- context: ExecutionContext
- frame: Frame
说明:
TODO
public String toString() @ L125
- 方法名:toString
- 源码定位:L125
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class BuildContexts<T extends ExecutionCommandSource<T>> {
@VisibleForTesting
public static final DynamicCommandExceptionType ERROR_FORK_LIMIT_REACHED = new DynamicCommandExceptionType(
limit -> Component.translatableEscape("command.forkLimit", limit)
);
private final String commandInput;
private final ContextChain<T> command;
public BuildContexts(String commandInput, ContextChain<T> command) {
this.commandInput = commandInput;
this.command = command;
}
protected void execute(T originalSource, List<T> initialSources, ExecutionContext<T> context, Frame frame, ChainModifiers initialModifiers) {
ContextChain<T> currentStage = this.command;
ChainModifiers modifiers = initialModifiers;
List<T> currentSources = initialSources;
if (currentStage.getStage() != Stage.EXECUTE) {
context.profiler().push(() -> "prepare " + this.commandInput);
try {
for (int forkLimit = context.forkLimit(); currentStage.getStage() != Stage.EXECUTE; currentStage = currentStage.nextStage()) {
CommandContext<T> contextToRun = currentStage.getTopContext();
if (contextToRun.isForked()) {
modifiers = modifiers.setForked();
}
RedirectModifier<T> modifier = contextToRun.getRedirectModifier();
if (modifier instanceof CustomModifierExecutor<?>) {
CustomModifierExecutor<T> customModifierExecutor = (CustomModifierExecutor<T>) modifier;
customModifierExecutor.apply(originalSource, currentSources, currentStage, modifiers, ExecutionControl.create(context, frame));
return;
}
if (modifier != null) {
context.incrementCost();
boolean forkedMode = modifiers.isForked();
List<T> nextSources = new ObjectArrayList<>();
for (T source : currentSources) {
try {
Collection<T> newSources = ContextChain.runModifier(contextToRun, source, (c, s, r) -> {}, forkedMode);
if (nextSources.size() + newSources.size() >= forkLimit) {
originalSource.handleError(ERROR_FORK_LIMIT_REACHED.create(forkLimit), forkedMode, context.tracer());
return;
}
nextSources.addAll(newSources);
} catch (CommandSyntaxException var20) {
source.handleError(var20, forkedMode, context.tracer());
if (!forkedMode) {
return;
}
}
}
currentSources = nextSources;
}
}
} finally {
context.profiler().pop();
}
}
if (currentSources.isEmpty()) {
if (modifiers.isReturn()) {
context.queueNext(new CommandQueueEntry<T>(frame, FallthroughTask.instance()));
}
} else {
CommandContext<T> executeContext = currentStage.getTopContext();
com.mojang.brigadier.Command<T> command = executeContext.getCommand();
if (command instanceof CustomCommandExecutor<?>) {
CustomCommandExecutor<T> customCommandExecutor = (CustomCommandExecutor<T>) command;
ExecutionControl<T> executionControl = ExecutionControl.create(context, frame);
for (T executionSource : currentSources) {
customCommandExecutor.run(executionSource, currentStage, modifiers, executionControl);
}
} else {
if (modifiers.isReturn()) {
T returningSource = currentSources.get(0);
returningSource = returningSource.withCallback(CommandResultCallback.chain(returningSource.callback(), frame.returnValueConsumer()));
currentSources = List.of(returningSource);
}
ExecuteCommand<T> action = new ExecuteCommand<>(this.commandInput, modifiers, executeContext);
ContinuationTask.schedule(context, frame, currentSources, (frame1, entrySource) -> new CommandQueueEntry<>(frame1, action.bind(entrySource)));
}
}
}
protected void traceCommandStart(ExecutionContext<T> context, Frame frame) {
TraceCallbacks tracer = context.tracer();
if (tracer != null) {
tracer.onCommand(frame.depth(), this.commandInput);
}
}
@Override
public String toString() {
return this.commandInput;
}
public static class Continuation<T extends ExecutionCommandSource<T>> extends BuildContexts<T> implements EntryAction<T> {
private final ChainModifiers modifiers;
private final T originalSource;
private final List<T> sources;
public Continuation(String commandInput, ContextChain<T> command, ChainModifiers modifiers, T originalSource, List<T> sources) {
super(commandInput, command);
this.originalSource = originalSource;
this.sources = sources;
this.modifiers = modifiers;
}
@Override
public void execute(ExecutionContext<T> context, Frame frame) {
this.execute(this.originalSource, this.sources, context, frame, this.modifiers);
}
}
public static class TopLevel<T extends ExecutionCommandSource<T>> extends BuildContexts<T> implements EntryAction<T> {
private final T source;
public TopLevel(String commandInput, ContextChain<T> command, T source) {
super(commandInput, command);
this.source = source;
}
@Override
public void execute(ExecutionContext<T> context, Frame frame) {
this.traceCommandStart(context, frame);
this.execute(this.source, List.of(this.source), context, frame, ChainModifiers.DEFAULT);
}
}
public static class Unbound<T extends ExecutionCommandSource<T>> extends BuildContexts<T> implements UnboundEntryAction<T> {
public Unbound(String commandInput, ContextChain<T> command) {
super(commandInput, command);
}
public void execute(T sender, ExecutionContext<T> context, Frame frame) {
this.traceCommandStart(context, frame);
this.execute(sender, List.of(sender), context, frame, ChainModifiers.DEFAULT);
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
CommandResultCallback.chain()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ExecutionControl.create()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ContinuationTask.schedule()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FallthroughTask.instance()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatableEscape()
- 引用位置: