Vec2Argument.java

net.minecraft.commands.arguments.coordinates.Vec2Argument

信息

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

    TODO

字段/常量

  • EXAMPLES

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

      TODO

  • ERROR_NOT_COMPLETE

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

      TODO

  • centerCorrect

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L24
    • 说明:

      TODO

内部类/嵌套类型

构造器

public Vec2Argument(boolean centerCorrect) @ L26

  • 构造器名:Vec2Argument
  • 源码定位:L26
  • 修饰符:public

参数:

  • centerCorrect: boolean

说明:

TODO

方法

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

public static Vec2Argument vec2() @ L30

  • 方法名:vec2
  • 源码定位:L30
  • 返回类型:Vec2Argument
  • 修饰符:public static

参数:

说明:

TODO

public static Vec2Argument vec2(boolean centerCorrect) @ L34

  • 方法名:vec2
  • 源码定位:L34
  • 返回类型:Vec2Argument
  • 修饰符:public static

参数:

  • centerCorrect: boolean

说明:

TODO

public static Vec2 getVec2(CommandContext<CommandSourceStack> context, String name) @ L38

  • 方法名:getVec2
  • 源码定位:L38
  • 返回类型:Vec2
  • 修饰符:public static

参数:

  • context: CommandContext
  • name: String

说明:

TODO

public Coordinates parse(StringReader reader) @ L43

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

参数:

  • reader: StringReader

说明:

TODO

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

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

参数:

  • context: CommandContext
  • builder: SuggestionsBuilder

说明:

TODO

public Collection<String> getExamples() @ L77

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

参数:

说明:

TODO

代码

public class Vec2Argument implements ArgumentType<Coordinates> {
    private static final Collection<String> EXAMPLES = Arrays.asList("0 0", "~ ~", "0.1 -0.5", "~1 ~-2");
    public static final SimpleCommandExceptionType ERROR_NOT_COMPLETE = new SimpleCommandExceptionType(Component.translatable("argument.pos2d.incomplete"));
    private final boolean centerCorrect;
 
    public Vec2Argument(boolean centerCorrect) {
        this.centerCorrect = centerCorrect;
    }
 
    public static Vec2Argument vec2() {
        return new Vec2Argument(true);
    }
 
    public static Vec2Argument vec2(boolean centerCorrect) {
        return new Vec2Argument(centerCorrect);
    }
 
    public static Vec2 getVec2(CommandContext<CommandSourceStack> context, String name) {
        Vec3 vec3 = context.getArgument(name, Coordinates.class).getPosition(context.getSource());
        return new Vec2((float)vec3.x, (float)vec3.z);
    }
 
    public Coordinates parse(StringReader reader) throws CommandSyntaxException {
        int start = reader.getCursor();
        if (!reader.canRead()) {
            throw ERROR_NOT_COMPLETE.createWithContext(reader);
        } else {
            WorldCoordinate x = WorldCoordinate.parseDouble(reader, this.centerCorrect);
            if (reader.canRead() && reader.peek() == ' ') {
                reader.skip();
                WorldCoordinate z = WorldCoordinate.parseDouble(reader, this.centerCorrect);
                return new WorldCoordinates(x, new WorldCoordinate(true, 0.0), z);
            } else {
                reader.setCursor(start);
                throw ERROR_NOT_COMPLETE.createWithContext(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()).getAbsoluteCoordinates();
            }
 
            return SharedSuggestionProvider.suggest2DCoordinates(remainder, suggestedCoordinates, builder, Commands.createValidator(this::parse));
        }
    }
 
    @Override
    public Collection<String> getExamples() {
        return EXAMPLES;
    }
}

引用的其他类

  • CommandSourceStack

    • 引用位置: 参数
  • Commands

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

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

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

    • 引用位置: 方法调用/构造调用
    • 关联成员: WorldCoordinate(), WorldCoordinate.parseDouble()
  • WorldCoordinates

    • 引用位置: 构造调用
    • 关联成员: WorldCoordinates()
  • Component

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

    • 引用位置: 构造调用/返回值
    • 关联成员: Vec2()