BlockPosArgument.java

net.minecraft.commands.arguments.coordinates.BlockPosArgument

信息

  • 全限定名:net.minecraft.commands.arguments.coordinates.BlockPosArgument
  • 类型:public class
  • 包:net.minecraft.commands.arguments.coordinates
  • 源码路径:src/main/java/net/minecraft/commands/arguments/coordinates/BlockPosArgument.java
  • 起始行号:L22
  • 实现:ArgumentType
  • 职责:

    TODO

字段/常量

  • EXAMPLES

    • 类型: Collection<String>
    • 修饰符: private static final
    • 源码定位: L23
    • 说明:

      TODO

  • ERROR_NOT_LOADED

    • 类型: SimpleCommandExceptionType
    • 修饰符: public static final
    • 源码定位: L24
    • 说明:

      TODO

  • ERROR_OUT_OF_WORLD

    • 类型: SimpleCommandExceptionType
    • 修饰符: public static final
    • 源码定位: L25
    • 说明:

      TODO

  • ERROR_OUT_OF_BOUNDS

    • 类型: SimpleCommandExceptionType
    • 修饰符: public static final
    • 源码定位: L26
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public static BlockPosArgument blockPos() @ L28

  • 方法名:blockPos
  • 源码定位:L28
  • 返回类型:BlockPosArgument
  • 修饰符:public static

参数:

说明:

TODO

public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, String name) @ L32

  • 方法名:getLoadedBlockPos
  • 源码定位:L32
  • 返回类型:BlockPos
  • 修饰符:public static

参数:

  • context: CommandContext
  • name: String

说明:

TODO

public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, ServerLevel level, String name) @ L37

  • 方法名:getLoadedBlockPos
  • 源码定位:L37
  • 返回类型:BlockPos
  • 修饰符:public static

参数:

  • context: CommandContext
  • level: ServerLevel
  • name: String

说明:

TODO

public static BlockPos getBlockPos(CommandContext<CommandSourceStack> context, String name) @ L48

  • 方法名:getBlockPos
  • 源码定位:L48
  • 返回类型:BlockPos
  • 修饰符:public static

参数:

  • context: CommandContext
  • name: String

说明:

TODO

public static BlockPos getSpawnablePos(CommandContext<CommandSourceStack> context, String name) @ L52

  • 方法名:getSpawnablePos
  • 源码定位:L52
  • 返回类型:BlockPos
  • 修饰符:public static

参数:

  • context: CommandContext
  • name: String

说明:

TODO

public Coordinates parse(StringReader reader) @ L61

  • 方法名:parse
  • 源码定位:L61
  • 返回类型:Coordinates
  • 修饰符:public

参数:

  • reader: StringReader

说明:

TODO

public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) @ L65

  • 方法名:listSuggestions
  • 源码定位:L65
  • 返回类型: CompletableFuture
  • 修饰符:public

参数:

  • context: CommandContext
  • builder: SuggestionsBuilder

说明:

TODO

public Collection<String> getExamples() @ L82

  • 方法名:getExamples
  • 源码定位:L82
  • 返回类型:Collection
  • 修饰符:public

参数:

说明:

TODO

代码

public class BlockPosArgument implements ArgumentType<Coordinates> {
    private static final Collection<String> EXAMPLES = Arrays.asList("0 0 0", "~ ~ ~", "^ ^ ^", "^1 ^ ^-5", "~0.5 ~1 ~-5");
    public static final SimpleCommandExceptionType ERROR_NOT_LOADED = new SimpleCommandExceptionType(Component.translatable("argument.pos.unloaded"));
    public static final SimpleCommandExceptionType ERROR_OUT_OF_WORLD = new SimpleCommandExceptionType(Component.translatable("argument.pos.outofworld"));
    public static final SimpleCommandExceptionType ERROR_OUT_OF_BOUNDS = new SimpleCommandExceptionType(Component.translatable("argument.pos.outofbounds"));
 
    public static BlockPosArgument blockPos() {
        return new BlockPosArgument();
    }
 
    public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
        ServerLevel level = context.getSource().getLevel();
        return getLoadedBlockPos(context, level, name);
    }
 
    public static BlockPos getLoadedBlockPos(CommandContext<CommandSourceStack> context, ServerLevel level, String name) throws CommandSyntaxException {
        BlockPos pos = getBlockPos(context, name);
        if (!level.hasChunkAt(pos)) {
            throw ERROR_NOT_LOADED.create();
        } else if (!level.isInWorldBounds(pos)) {
            throw ERROR_OUT_OF_WORLD.create();
        } else {
            return pos;
        }
    }
 
    public static BlockPos getBlockPos(CommandContext<CommandSourceStack> context, String name) {
        return context.getArgument(name, Coordinates.class).getBlockPos(context.getSource());
    }
 
    public static BlockPos getSpawnablePos(CommandContext<CommandSourceStack> context, String name) throws CommandSyntaxException {
        BlockPos pos = getBlockPos(context, name);
        if (!Level.isInSpawnableBounds(pos)) {
            throw ERROR_OUT_OF_BOUNDS.create();
        } else {
            return pos;
        }
    }
 
    public Coordinates parse(StringReader reader) throws CommandSyntaxException {
        return (Coordinates)(reader.canRead() && reader.peek() == '^' ? LocalCoordinates.parse(reader) : WorldCoordinates.parseInt(reader));
    }
 
    @Override
    public <S> CompletableFuture<Suggestions> listSuggestions(CommandContext<S> context, SuggestionsBuilder builder) {
        if (!(context.getSource() instanceof SharedSuggestionProvider)) {
            return Suggestions.empty();
        } else {
            String remainder = builder.getRemaining();
            Collection<SharedSuggestionProvider.TextCoordinates> suggestedCoordinates;
            if (!remainder.isEmpty() && remainder.charAt(0) == '^') {
                suggestedCoordinates = Collections.singleton(SharedSuggestionProvider.TextCoordinates.DEFAULT_LOCAL);
            } else {
                suggestedCoordinates = ((SharedSuggestionProvider)context.getSource()).getRelevantCoordinates();
            }
 
            return SharedSuggestionProvider.suggestCoordinates(remainder, suggestedCoordinates, builder, Commands.createValidator(this::parse));
        }
    }
 
    @Override
    public Collection<String> getExamples() {
        return EXAMPLES;
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

    • 引用位置: 方法调用
    • 关联成员: Commands.createValidator()
  • SharedSuggestionProvider

    • 引用位置: 方法调用
    • 关联成员: SharedSuggestionProvider.suggestCoordinates()
  • Coordinates

    • 引用位置: 实现/返回值
  • LocalCoordinates

    • 引用位置: 方法调用
    • 关联成员: LocalCoordinates.parse()
  • WorldCoordinates

    • 引用位置: 方法调用
    • 关联成员: WorldCoordinates.parseInt()
  • BlockPos

    • 引用位置: 返回值
  • Component

    • 引用位置: 方法调用
    • 关联成员: Component.translatable()
  • ServerLevel

    • 引用位置: 参数
  • Level

    • 引用位置: 方法调用
    • 关联成员: Level.isInSpawnableBounds()