ParticleArgument.java
net.minecraft.commands.arguments.ParticleArgument
信息
- 全限定名:net.minecraft.commands.arguments.ParticleArgument
- 类型:public class
- 包:net.minecraft.commands.arguments
- 源码路径:src/main/java/net/minecraft/commands/arguments/ParticleArgument.java
- 起始行号:L27
- 实现:ArgumentType
- 职责:
TODO
字段/常量
-
EXAMPLES- 类型:
Collection<String> - 修饰符:
private static final - 源码定位:
L28 - 说明:
TODO
- 类型:
-
ERROR_UNKNOWN_PARTICLE- 类型:
DynamicCommandExceptionType - 修饰符:
public static final - 源码定位:
L29 - 说明:
TODO
- 类型:
-
ERROR_INVALID_OPTIONS- 类型:
DynamicCommandExceptionType - 修饰符:
public static final - 源码定位:
L32 - 说明:
TODO
- 类型:
-
registries- 类型:
HolderLookup.Provider - 修饰符:
private final - 源码定位:
L35 - 说明:
TODO
- 类型:
-
VALUE_PARSER- 类型:
TagParser<?> - 修饰符:
private static final - 源码定位:
L36 - 说明:
TODO
- 类型:
内部类/嵌套类型
- 无
构造器
public ParticleArgument(CommandBuildContext context) @ L38
- 构造器名:ParticleArgument
- 源码定位:L38
- 修饰符:public
参数:
- context: CommandBuildContext
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static ParticleArgument particle(CommandBuildContext context) @ L42
- 方法名:particle
- 源码定位:L42
- 返回类型:ParticleArgument
- 修饰符:public static
参数:
- context: CommandBuildContext
说明:
TODO
public static ParticleOptions getParticle(CommandContext<CommandSourceStack> context, String name) @ L46
- 方法名:getParticle
- 源码定位:L46
- 返回类型:ParticleOptions
- 修饰符:public static
参数:
- context: CommandContext
- name: String
说明:
TODO
public ParticleOptions parse(StringReader reader) @ L50
- 方法名:parse
- 源码定位:L50
- 返回类型:ParticleOptions
- 修饰符:public
参数:
- reader: StringReader
说明:
TODO
public Collection<String> getExamples() @ L54
- 方法名:getExamples
- 源码定位:L54
- 返回类型:Collection
- 修饰符:public
参数:
- 无
说明:
TODO
public static ParticleOptions readParticle(StringReader reader, HolderLookup.Provider registries) @ L59
- 方法名:readParticle
- 源码定位:L59
- 返回类型:ParticleOptions
- 修饰符:public static
参数:
- reader: StringReader
- registries: HolderLookup.Provider
说明:
TODO
private static ParticleType<?> readParticleType(StringReader reader, HolderLookup<ParticleType<?>> particles) @ L64
- 方法名:readParticleType
- 源码定位:L64
- 返回类型:ParticleType<?>
- 修饰符:private static
参数:
- reader: StringReader
- particles: HolderLookup<ParticleType<?>>
说明:
TODO
private static <T extends ParticleOptions,O> T readParticle(TagParser<O> parser, StringReader reader, ParticleType<T> type, HolderLookup.Provider registries) @ L70
- 方法名:readParticle
- 源码定位:L70
- 返回类型:<T extends ParticleOptions,O> T
- 修饰符:private static
参数:
- parser: TagParser
- reader: StringReader
- type: ParticleType
- registries: HolderLookup.Provider
说明:
TODO
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) @ L84
- 方法名:listSuggestions
- 源码定位:L84
- 返回类型:
CompletableFuture - 修饰符:public
参数:
- context: CommandContext
- builder: SuggestionsBuilder
说明:
TODO
代码
public class ParticleArgument implements ArgumentType<ParticleOptions> {
private static final Collection<String> EXAMPLES = Arrays.asList("foo", "foo:bar", "particle{foo:bar}");
public static final DynamicCommandExceptionType ERROR_UNKNOWN_PARTICLE = new DynamicCommandExceptionType(
value -> Component.translatableEscape("particle.notFound", value)
);
public static final DynamicCommandExceptionType ERROR_INVALID_OPTIONS = new DynamicCommandExceptionType(
message -> Component.translatableEscape("particle.invalidOptions", message)
);
private final HolderLookup.Provider registries;
private static final TagParser<?> VALUE_PARSER = TagParser.create(NbtOps.INSTANCE);
public ParticleArgument(CommandBuildContext context) {
this.registries = context;
}
public static ParticleArgument particle(CommandBuildContext context) {
return new ParticleArgument(context);
}
public static ParticleOptions getParticle(CommandContext<CommandSourceStack> context, String name) {
return context.getArgument(name, ParticleOptions.class);
}
public ParticleOptions parse(StringReader reader) throws CommandSyntaxException {
return readParticle(reader, this.registries);
}
@Override
public Collection<String> getExamples() {
return EXAMPLES;
}
public static ParticleOptions readParticle(StringReader reader, HolderLookup.Provider registries) throws CommandSyntaxException {
ParticleType<?> type = readParticleType(reader, registries.lookupOrThrow(Registries.PARTICLE_TYPE));
return readParticle(VALUE_PARSER, reader, (ParticleType<ParticleOptions>)type, registries);
}
private static ParticleType<?> readParticleType(StringReader reader, HolderLookup<ParticleType<?>> particles) throws CommandSyntaxException {
Identifier id = Identifier.read(reader);
ResourceKey<ParticleType<?>> key = ResourceKey.create(Registries.PARTICLE_TYPE, id);
return particles.get(key).orElseThrow(() -> ERROR_UNKNOWN_PARTICLE.createWithContext(reader, id)).value();
}
private static <T extends ParticleOptions, O> T readParticle(
TagParser<O> parser, StringReader reader, ParticleType<T> type, HolderLookup.Provider registries
) throws CommandSyntaxException {
RegistryOps<O> ops = registries.createSerializationContext(parser.getOps());
O extraData;
if (reader.canRead() && reader.peek() == '{') {
extraData = parser.parseAsArgument(reader);
} else {
extraData = ops.emptyMap();
}
return type.codec().codec().parse(ops, extraData).getOrThrow(ERROR_INVALID_OPTIONS::create);
}
@Override
public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
HolderLookup.RegistryLookup<ParticleType<?>> particles = this.registries.lookupOrThrow(Registries.PARTICLE_TYPE);
return SharedSuggestionProvider.suggestResource(particles.listElementIds().map(ResourceKey::identifier), builder);
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
SharedSuggestionProvider.suggestResource()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
实现/返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数/字段/方法调用 - 关联成员:
TagParser.create()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.translatableEscape()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.read()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ResourceKey.create()
- 引用位置: