WorldCoordinate.java

net.minecraft.commands.arguments.coordinates.WorldCoordinate

信息

  • 全限定名:net.minecraft.commands.arguments.coordinates.WorldCoordinate
  • 类型:public record
  • 包:net.minecraft.commands.arguments.coordinates
  • 源码路径:src/main/java/net/minecraft/commands/arguments/coordinates/WorldCoordinate.java
  • 起始行号:L8
  • 职责:

    TODO

字段/常量

  • PREFIX_RELATIVE

    • 类型: char
    • 修饰符: private static final
    • 源码定位: L9
    • 说明:

      TODO

  • ERROR_EXPECTED_DOUBLE

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

      TODO

  • ERROR_EXPECTED_INT

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

      TODO

内部类/嵌套类型

构造器

方法

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

public double get(double original) @ L13

  • 方法名:get
  • 源码定位:L13
  • 返回类型:double
  • 修饰符:public

参数:

  • original: double

说明:

TODO

public static WorldCoordinate parseDouble(StringReader reader, boolean center) @ L17

  • 方法名:parseDouble
  • 源码定位:L17
  • 返回类型:WorldCoordinate
  • 修饰符:public static

参数:

  • reader: StringReader
  • center: boolean

说明:

TODO

public static WorldCoordinate parseInt(StringReader reader) @ L39

  • 方法名:parseInt
  • 源码定位:L39
  • 返回类型:WorldCoordinate
  • 修饰符:public static

参数:

  • reader: StringReader

说明:

TODO

public static boolean isRelative(StringReader reader) @ L57

  • 方法名:isRelative
  • 源码定位:L57
  • 返回类型:boolean
  • 修饰符:public static

参数:

  • reader: StringReader

说明:

TODO

public boolean isRelative() @ L69

  • 方法名:isRelative
  • 源码定位:L69
  • 返回类型:boolean
  • 修饰符:public

参数:

说明:

TODO

代码

public record WorldCoordinate(boolean relative, double value) {
    private static final char PREFIX_RELATIVE = '~';
    public static final SimpleCommandExceptionType ERROR_EXPECTED_DOUBLE = new SimpleCommandExceptionType(Component.translatable("argument.pos.missing.double"));
    public static final SimpleCommandExceptionType ERROR_EXPECTED_INT = new SimpleCommandExceptionType(Component.translatable("argument.pos.missing.int"));
 
    public double get(double original) {
        return this.relative ? this.value + original : this.value;
    }
 
    public static WorldCoordinate parseDouble(StringReader reader, boolean center) throws CommandSyntaxException {
        if (reader.canRead() && reader.peek() == '^') {
            throw Vec3Argument.ERROR_MIXED_TYPE.createWithContext(reader);
        } else if (!reader.canRead()) {
            throw ERROR_EXPECTED_DOUBLE.createWithContext(reader);
        } else {
            boolean relative = isRelative(reader);
            int start = reader.getCursor();
            double value = reader.canRead() && reader.peek() != ' ' ? reader.readDouble() : 0.0;
            String number = reader.getString().substring(start, reader.getCursor());
            if (relative && number.isEmpty()) {
                return new WorldCoordinate(true, 0.0);
            } else {
                if (!number.contains(".") && !relative && center) {
                    value += 0.5;
                }
 
                return new WorldCoordinate(relative, value);
            }
        }
    }
 
    public static WorldCoordinate parseInt(StringReader reader) throws CommandSyntaxException {
        if (reader.canRead() && reader.peek() == '^') {
            throw Vec3Argument.ERROR_MIXED_TYPE.createWithContext(reader);
        } else if (!reader.canRead()) {
            throw ERROR_EXPECTED_INT.createWithContext(reader);
        } else {
            boolean relative = isRelative(reader);
            double value;
            if (reader.canRead() && reader.peek() != ' ') {
                value = relative ? reader.readDouble() : reader.readInt();
            } else {
                value = 0.0;
            }
 
            return new WorldCoordinate(relative, value);
        }
    }
 
    public static boolean isRelative(StringReader reader) {
        boolean relative;
        if (reader.peek() == '~') {
            relative = true;
            reader.skip();
        } else {
            relative = false;
        }
 
        return relative;
    }
 
    public boolean isRelative() {
        return this.relative;
    }
}

引用的其他类

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