CommandFunction.java

net.minecraft.commands.functions.CommandFunction

信息

  • 全限定名:net.minecraft.commands.functions.CommandFunction
  • 类型:public interface
  • 包:net.minecraft.commands.functions
  • 源码路径:src/main/java/net/minecraft/commands/functions/CommandFunction.java
  • 起始行号:L19
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

下面的方法块按源码顺序生成。

Identifier id() @ L20

  • 方法名:id
  • 源码定位:L20
  • 返回类型:Identifier
  • 修饰符:package-private

参数:

说明:

TODO

InstantiatedFunction<T> instantiate(CompoundTag arguments, CommandDispatcher<T> dispatcher) @ L22

  • 方法名:instantiate
  • 源码定位:L22
  • 返回类型:InstantiatedFunction
  • 修饰符:package-private

参数:

  • arguments: CompoundTag
  • dispatcher: CommandDispatcher

说明:

TODO

private static boolean shouldConcatenateNextLine(CharSequence line) @ L24

  • 方法名:shouldConcatenateNextLine
  • 源码定位:L24
  • 返回类型:boolean
  • 修饰符:private static

参数:

  • line: CharSequence

说明:

TODO

static <T extends ExecutionCommandSource<T>> CommandFunction<T> fromLines(Identifier id, CommandDispatcher<T> dispatcher, T compilationContext, List<String> lines) @ L29

  • 方法名:fromLines
  • 源码定位:L29
  • 返回类型:<T extends ExecutionCommandSource> CommandFunction
  • 修饰符:static

参数:

  • id: Identifier
  • dispatcher: CommandDispatcher
  • compilationContext: T
  • lines: List

说明:

TODO

static void checkCommandLineLength(CharSequence line) @ L95

  • 方法名:checkCommandLineLength
  • 源码定位:L95
  • 返回类型:void
  • 修饰符:static

参数:

  • line: CharSequence

说明:

TODO

static <T extends ExecutionCommandSource<T>> UnboundEntryAction<T> parseCommand(CommandDispatcher<T> dispatcher, T compilationContext, StringReader input) @ L102

  • 方法名:parseCommand
  • 源码定位:L102
  • 返回类型:<T extends ExecutionCommandSource> UnboundEntryAction
  • 修饰符:static

参数:

  • dispatcher: CommandDispatcher
  • compilationContext: T
  • input: StringReader

说明:

TODO

代码

public interface CommandFunction<T> {
    Identifier id();
 
    InstantiatedFunction<T> instantiate(@Nullable CompoundTag arguments, CommandDispatcher<T> dispatcher) throws FunctionInstantiationException;
 
    private static boolean shouldConcatenateNextLine(CharSequence line) {
        int length = line.length();
        return length > 0 && line.charAt(length - 1) == '\\';
    }
 
    static <T extends ExecutionCommandSource<T>> CommandFunction<T> fromLines(
        Identifier id, CommandDispatcher<T> dispatcher, T compilationContext, List<String> lines
    ) {
        FunctionBuilder<T> functionBuilder = new FunctionBuilder<>();
 
        for (int i = 0; i < lines.size(); i++) {
            int lineNumber = i + 1;
            String inputLine = lines.get(i).trim();
            String line;
            if (shouldConcatenateNextLine(inputLine)) {
                StringBuilder builder = new StringBuilder(inputLine);
 
                do {
                    if (++i == lines.size()) {
                        throw new IllegalArgumentException("Line continuation at end of file");
                    }
 
                    builder.deleteCharAt(builder.length() - 1);
                    String innerLine = lines.get(i).trim();
                    builder.append(innerLine);
                    checkCommandLineLength(builder);
                } while (shouldConcatenateNextLine(builder));
 
                line = builder.toString();
            } else {
                line = inputLine;
            }
 
            checkCommandLineLength(line);
            StringReader input = new StringReader(line);
            if (input.canRead() && input.peek() != '#') {
                if (input.peek() == '/') {
                    input.skip();
                    if (input.peek() == '/') {
                        throw new IllegalArgumentException(
                            "Unknown or invalid command '" + line + "' on line " + lineNumber + " (if you intended to make a comment, use '#' not '//')"
                        );
                    }
 
                    String name = input.readUnquotedString();
                    throw new IllegalArgumentException(
                        "Unknown or invalid command '"
                            + line
                            + "' on line "
                            + lineNumber
                            + " (did you mean '"
                            + name
                            + "'? Do not use a preceding forwards slash.)"
                    );
                }
 
                if (input.peek() == '$') {
                    functionBuilder.addMacro(line.substring(1), lineNumber, compilationContext);
                } else {
                    try {
                        functionBuilder.addCommand(parseCommand(dispatcher, compilationContext, input));
                    } catch (CommandSyntaxException var11) {
                        throw new IllegalArgumentException("Whilst parsing command on line " + lineNumber + ": " + var11.getMessage());
                    }
                }
            }
        }
 
        return functionBuilder.build(id);
    }
 
    static void checkCommandLineLength(CharSequence line) {
        if (line.length() > 2000000) {
            CharSequence truncated = line.subSequence(0, Math.min(512, 2000000));
            throw new IllegalStateException("Command too long: " + line.length() + " characters, contents: " + truncated + "...");
        }
    }
 
    static <T extends ExecutionCommandSource<T>> UnboundEntryAction<T> parseCommand(CommandDispatcher<T> dispatcher, T compilationContext, StringReader input) throws CommandSyntaxException {
        ParseResults<T> parse = dispatcher.parse(input, compilationContext);
        Commands.validateParseResults(parse);
        Optional<ContextChain<T>> commandChain = ContextChain.tryFlatten(parse.getContext().build(input.getString()));
        if (commandChain.isEmpty()) {
            throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownCommand().createWithContext(parse.getReader());
        } else {
            return new BuildContexts.Unbound<>(input.getString(), commandChain.get());
        }
    }
}

引用的其他类