FunctionArgument.java
net.minecraft.commands.arguments.item.FunctionArgument
信息
- 全限定名:net.minecraft.commands.arguments.item.FunctionArgument
- 类型:public class
- 包:net.minecraft.commands.arguments.item
- 源码路径:src/main/java/net/minecraft/commands/arguments/item/FunctionArgument.java
- 起始行号:L19
- 实现:ArgumentType<FunctionArgument.Result>
- 职责:
TODO
字段/常量
-
EXAMPLES- 类型:
Collection<String> - 修饰符:
private static final - 源码定位:
L20 - 说明:
TODO
- 类型:
-
ERROR_UNKNOWN_TAG- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L21 - 说明:
TODO
- 类型:
-
ERROR_UNKNOWN_FUNCTION- 类型:
DynamicCommandExceptionType - 修饰符:
private static final - 源码定位:
L24 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.commands.arguments.item.FunctionArgument.Result- 类型:
interface - 修饰符:
public - 源码定位:
L119 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static FunctionArgument functions() @ L28
- 方法名:functions
- 源码定位:L28
- 返回类型:FunctionArgument
- 修饰符:public static
参数:
- 无
说明:
TODO
public FunctionArgument.Result parse(StringReader reader) @ L32
- 方法名:parse
- 源码定位:L32
- 返回类型:FunctionArgument.Result
- 修饰符:public
参数:
- reader: StringReader
说明:
TODO
private static CommandFunction<CommandSourceStack> getFunction(CommandContext<CommandSourceStack> c, Identifier id) @ L85
- 方法名:getFunction
- 源码定位:L85
- 返回类型:CommandFunction
- 修饰符:private static
参数:
- c: CommandContext
- id: Identifier
说明:
TODO
private static Collection<CommandFunction<CommandSourceStack>> getFunctionTag(CommandContext<CommandSourceStack> c, Identifier id) @ L89
- 方法名:getFunctionTag
- 源码定位:L89
- 返回类型:Collection<CommandFunction
> - 修饰符:private static
参数:
- c: CommandContext
- id: Identifier
说明:
TODO
public static Collection<CommandFunction<CommandSourceStack>> getFunctions(CommandContext<CommandSourceStack> context, String name) @ L98
- 方法名:getFunctions
- 源码定位:L98
- 返回类型:Collection<CommandFunction
> - 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public static Pair<Identifier,Either<CommandFunction<CommandSourceStack>,Collection<CommandFunction<CommandSourceStack>>>> getFunctionOrTag(CommandContext<CommandSourceStack> context, String name) @ L102
- 方法名:getFunctionOrTag
- 源码定位:L102
- 返回类型:Pair<Identifier,Either<CommandFunction
,Collection<CommandFunction >>> - 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public static Pair<Identifier,Collection<CommandFunction<CommandSourceStack>>> getFunctionCollection(CommandContext<CommandSourceStack> context, String name) @ L108
- 方法名:getFunctionCollection
- 源码定位:L108
- 返回类型:Pair<Identifier,Collection<CommandFunction
>> - 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public Collection<String> getExamples() @ L114
- 方法名:getExamples
- 源码定位:L114
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public class FunctionArgument implements ArgumentType<FunctionArgument.Result> {
private static final Collection<String> EXAMPLES = Arrays.asList("foo", "foo:bar", "#foo");
private static final DynamicCommandExceptionType ERROR_UNKNOWN_TAG = new DynamicCommandExceptionType(
tag -> Component.translatableEscape("arguments.function.tag.unknown", tag)
);
private static final DynamicCommandExceptionType ERROR_UNKNOWN_FUNCTION = new DynamicCommandExceptionType(
value -> Component.translatableEscape("arguments.function.unknown", value)
);
public static FunctionArgument functions() {
return new FunctionArgument();
}
public FunctionArgument.Result parse(StringReader reader) throws CommandSyntaxException {
if (reader.canRead() && reader.peek() == '#') {
reader.skip();
final Identifier id = Identifier.read(reader);
return new FunctionArgument.Result() {
{
Objects.requireNonNull(FunctionArgument.this);
}
@Override
public Collection<CommandFunction<CommandSourceStack>> create(CommandContext<CommandSourceStack> c) throws CommandSyntaxException {
return FunctionArgument.getFunctionTag(c, id);
}
@Override
public Pair<Identifier, Either<CommandFunction<CommandSourceStack>, Collection<CommandFunction<CommandSourceStack>>>> unwrap(
CommandContext<CommandSourceStack> context
) throws CommandSyntaxException {
return Pair.of(id, Either.right(FunctionArgument.getFunctionTag(context, id)));
}
@Override
public Pair<Identifier, Collection<CommandFunction<CommandSourceStack>>> unwrapToCollection(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
return Pair.of(id, FunctionArgument.getFunctionTag(context, id));
}
};
} else {
final Identifier id = Identifier.read(reader);
return new FunctionArgument.Result() {
{
Objects.requireNonNull(FunctionArgument.this);
}
@Override
public Collection<CommandFunction<CommandSourceStack>> create(CommandContext<CommandSourceStack> c) throws CommandSyntaxException {
return Collections.singleton(FunctionArgument.getFunction(c, id));
}
@Override
public Pair<Identifier, Either<CommandFunction<CommandSourceStack>, Collection<CommandFunction<CommandSourceStack>>>> unwrap(
CommandContext<CommandSourceStack> context
) throws CommandSyntaxException {
return Pair.of(id, Either.left(FunctionArgument.getFunction(context, id)));
}
@Override
public Pair<Identifier, Collection<CommandFunction<CommandSourceStack>>> unwrapToCollection(CommandContext<CommandSourceStack> context) throws CommandSyntaxException {
return Pair.of(id, Collections.singleton(FunctionArgument.getFunction(context, id)));
}
};
}
}
private static CommandFunction<CommandSourceStack> getFunction(CommandContext<CommandSourceStack> c, Identifier id) throws CommandSyntaxException {
return c.getSource().getServer().getFunctions().get(id).orElseThrow(() -> ERROR_UNKNOWN_FUNCTION.create(id.toString()));
}
private static Collection<CommandFunction<CommandSourceStack>> getFunctionTag(CommandContext<CommandSourceStack> c, Identifier id) throws CommandSyntaxException {
Collection<CommandFunction<CommandSourceStack>> tag = c.getSource().getServer().getFunctions().getTag(id);
if (tag == null) {
throw ERROR_UNKNOWN_TAG.create(id.toString());
} else {
return tag;
}
}
public static Collection<CommandFunction<CommandSourceStack>> getFunctions(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
return context.getArgument(name, FunctionArgument.Result.class).create(context);
}
public static Pair<Identifier, Either<CommandFunction<CommandSourceStack>, Collection<CommandFunction<CommandSourceStack>>>> getFunctionOrTag(
CommandContext<CommandSourceStack> context, String name
) throws CommandSyntaxException {
return context.getArgument(name, FunctionArgument.Result.class).unwrap(context);
}
public static Pair<Identifier, Collection<CommandFunction<CommandSourceStack>>> getFunctionCollection(
CommandContext<CommandSourceStack> context, String name
) throws CommandSyntaxException {
return context.getArgument(name, FunctionArgument.Result.class).unwrapToCollection(context);
}
@Override
public Collection<String> getExamples() {
return EXAMPLES;
}
public interface Result {
Collection<CommandFunction<CommandSourceStack>> create(CommandContext<CommandSourceStack> context) throws CommandSyntaxException;
Pair<Identifier, Either<CommandFunction<CommandSourceStack>, Collection<CommandFunction<CommandSourceStack>>>> unwrap(
CommandContext<CommandSourceStack> context
) throws CommandSyntaxException;
Pair<Identifier, Collection<CommandFunction<CommandSourceStack>>> unwrapToCollection(CommandContext<CommandSourceStack> context) throws CommandSyntaxException;
}
}引用的其他类
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatableEscape()
- 引用位置:
-
- 引用位置:
参数/方法调用/返回值 - 关联成员:
Identifier.read()
- 引用位置: