Vec3i.java

net.minecraft.core.Vec3i

信息

  • 全限定名:net.minecraft.core.Vec3i
  • 类型:public class
  • 包:net.minecraft.core
  • 源码路径:src/main/java/net/minecraft/core/Vec3i.java
  • 起始行号:L16
  • 实现:Comparable
  • 职责:

    TODO

字段/常量

  • CODEC

    • 类型: Codec<Vec3i>
    • 修饰符: public static final
    • 源码定位: L17
    • 说明:

      TODO

  • STREAM_CODEC

    • 类型: StreamCodec<ByteBuf,Vec3i>
    • 修饰符: public static final
    • 源码定位: L21
    • 说明:

      TODO

  • ZERO

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

      TODO

  • x

    • 类型: int
    • 修饰符: private
    • 源码定位: L25
    • 说明:

      TODO

  • y

    • 类型: int
    • 修饰符: private
    • 源码定位: L26
    • 说明:

      TODO

  • z

    • 类型: int
    • 修饰符: private
    • 源码定位: L27
    • 说明:

      TODO

内部类/嵌套类型

构造器

public Vec3i(int x, int y, int z) @ L37

  • 构造器名:Vec3i
  • 源码定位:L37
  • 修饰符:public

参数:

  • x: int
  • y: int
  • z: int

说明:

TODO

方法

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

public static Codec<Vec3i> offsetCodec(int maxOffsetPerAxis) @ L29

  • 方法名:offsetCodec
  • 源码定位:L29
  • 返回类型:Codec
  • 修饰符:public static

参数:

  • maxOffsetPerAxis: int

说明:

TODO

public boolean equals(Object o) @ L43

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

参数:

  • o: Object

说明:

TODO

public int hashCode() @ L52

  • 方法名:hashCode
  • 源码定位:L52
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

public int compareTo(Vec3i pos) @ L57

  • 方法名:compareTo
  • 源码定位:L57
  • 返回类型:int
  • 修饰符:public

参数:

  • pos: Vec3i

说明:

TODO

public int getX() @ L65

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

参数:

说明:

TODO

public int getY() @ L69

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

参数:

说明:

TODO

public int getZ() @ L73

  • 方法名:getZ
  • 源码定位:L73
  • 返回类型:int
  • 修饰符:public

参数:

说明:

TODO

protected Vec3i setX(int x) @ L77

  • 方法名:setX
  • 源码定位:L77
  • 返回类型:Vec3i
  • 修饰符:protected

参数:

  • x: int

说明:

TODO

protected Vec3i setY(int y) @ L82

  • 方法名:setY
  • 源码定位:L82
  • 返回类型:Vec3i
  • 修饰符:protected

参数:

  • y: int

说明:

TODO

protected Vec3i setZ(int z) @ L87

  • 方法名:setZ
  • 源码定位:L87
  • 返回类型:Vec3i
  • 修饰符:protected

参数:

  • z: int

说明:

TODO

public Vec3i offset(int x, int y, int z) @ L92

  • 方法名:offset
  • 源码定位:L92
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • x: int
  • y: int
  • z: int

说明:

TODO

public Vec3i offset(Vec3i vec) @ L96

  • 方法名:offset
  • 源码定位:L96
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • vec: Vec3i

说明:

TODO

public Vec3i subtract(Vec3i vec) @ L100

  • 方法名:subtract
  • 源码定位:L100
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • vec: Vec3i

说明:

TODO

public Vec3i multiply(int scale) @ L104

  • 方法名:multiply
  • 源码定位:L104
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • scale: int

说明:

TODO

public Vec3i multiply(int xScale, int yScale, int zScale) @ L112

  • 方法名:multiply
  • 源码定位:L112
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • xScale: int
  • yScale: int
  • zScale: int

说明:

TODO

public Vec3i above() @ L116

  • 方法名:above
  • 源码定位:L116
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i above(int steps) @ L120

  • 方法名:above
  • 源码定位:L120
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i below() @ L124

  • 方法名:below
  • 源码定位:L124
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i below(int steps) @ L128

  • 方法名:below
  • 源码定位:L128
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i north() @ L132

  • 方法名:north
  • 源码定位:L132
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i north(int steps) @ L136

  • 方法名:north
  • 源码定位:L136
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i south() @ L140

  • 方法名:south
  • 源码定位:L140
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i south(int steps) @ L144

  • 方法名:south
  • 源码定位:L144
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i west() @ L148

  • 方法名:west
  • 源码定位:L148
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i west(int steps) @ L152

  • 方法名:west
  • 源码定位:L152
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i east() @ L156

  • 方法名:east
  • 源码定位:L156
  • 返回类型:Vec3i
  • 修饰符:public

参数:

说明:

TODO

public Vec3i east(int steps) @ L160

  • 方法名:east
  • 源码定位:L160
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • steps: int

说明:

TODO

public Vec3i relative(Direction direction) @ L164

  • 方法名:relative
  • 源码定位:L164
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • direction: Direction

说明:

TODO

public Vec3i relative(Direction direction, int steps) @ L168

  • 方法名:relative
  • 源码定位:L168
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • direction: Direction
  • steps: int

说明:

TODO

public Vec3i relative(Direction.Axis axis, int steps) @ L174

  • 方法名:relative
  • 源码定位:L174
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • axis: Direction.Axis
  • steps: int

说明:

TODO

public Vec3i cross(Vec3i upVector) @ L185

  • 方法名:cross
  • 源码定位:L185
  • 返回类型:Vec3i
  • 修饰符:public

参数:

  • upVector: Vec3i

说明:

TODO

public boolean closerThan(Vec3i pos, double distance) @ L193

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

参数:

  • pos: Vec3i
  • distance: double

说明:

TODO

public boolean closerToCenterThan(Position pos, double distance) @ L197

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

参数:

  • pos: Position
  • distance: double

说明:

TODO

public double distSqr(Vec3i pos) @ L201

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

参数:

  • pos: Vec3i

说明:

TODO

public double distToCenterSqr(Position pos) @ L205

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

参数:

  • pos: Position

说明:

TODO

public double distToCenterSqr(double x, double y, double z) @ L209

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

参数:

  • x: double
  • y: double
  • z: double

说明:

TODO

public double distToLowCornerSqr(double x, double y, double z) @ L216

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

参数:

  • x: double
  • y: double
  • z: double

说明:

TODO

public int distManhattan(Vec3i pos) @ L223

  • 方法名:distManhattan
  • 源码定位:L223
  • 返回类型:int
  • 修饰符:public

参数:

  • pos: Vec3i

说明:

TODO

public int distChessboard(Vec3i pos) @ L230

  • 方法名:distChessboard
  • 源码定位:L230
  • 返回类型:int
  • 修饰符:public

参数:

  • pos: Vec3i

说明:

TODO

public int get(Direction.Axis axis) @ L237

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

参数:

  • axis: Direction.Axis

说明:

TODO

public Vector3i toMutable() @ L241

  • 方法名:toMutable
  • 源码定位:L241
  • 返回类型:Vector3i
  • 修饰符:public

参数:

说明:

TODO

public String toString() @ L245

  • 方法名:toString
  • 源码定位:L245
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

public String toShortString() @ L250

  • 方法名:toShortString
  • 源码定位:L250
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

代码

@Immutable
public class Vec3i implements Comparable<Vec3i> {
    public static final Codec<Vec3i> CODEC = Codec.INT_STREAM
        .comapFlatMap(
            input -> Util.fixedSize(input, 3).map(ints -> new Vec3i(ints[0], ints[1], ints[2])), pos -> IntStream.of(pos.getX(), pos.getY(), pos.getZ())
        );
    public static final StreamCodec<ByteBuf, Vec3i> STREAM_CODEC = StreamCodec.composite(
        ByteBufCodecs.VAR_INT, Vec3i::getX, ByteBufCodecs.VAR_INT, Vec3i::getY, ByteBufCodecs.VAR_INT, Vec3i::getZ, Vec3i::new
    );
    public static final Vec3i ZERO = new Vec3i(0, 0, 0);
    private int x;
    private int y;
    private int z;
 
    public static Codec<Vec3i> offsetCodec(int maxOffsetPerAxis) {
        return CODEC.validate(
            value -> Math.abs(value.getX()) < maxOffsetPerAxis && Math.abs(value.getY()) < maxOffsetPerAxis && Math.abs(value.getZ()) < maxOffsetPerAxis
                ? DataResult.success(value)
                : DataResult.error(() -> "Position out of range, expected at most " + maxOffsetPerAxis + ": " + value)
        );
    }
 
    public Vec3i(int x, int y, int z) {
        this.x = x;
        this.y = y;
        this.z = z;
    }
 
    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else {
            return !(o instanceof Vec3i vec3i) ? false : this.getX() == vec3i.getX() && this.getY() == vec3i.getY() && this.getZ() == vec3i.getZ();
        }
    }
 
    @Override
    public int hashCode() {
        return (this.getY() + this.getZ() * 31) * 31 + this.getX();
    }
 
    public int compareTo(Vec3i pos) {
        if (this.getY() == pos.getY()) {
            return this.getZ() == pos.getZ() ? this.getX() - pos.getX() : this.getZ() - pos.getZ();
        } else {
            return this.getY() - pos.getY();
        }
    }
 
    public int getX() {
        return this.x;
    }
 
    public int getY() {
        return this.y;
    }
 
    public int getZ() {
        return this.z;
    }
 
    protected Vec3i setX(int x) {
        this.x = x;
        return this;
    }
 
    protected Vec3i setY(int y) {
        this.y = y;
        return this;
    }
 
    protected Vec3i setZ(int z) {
        this.z = z;
        return this;
    }
 
    public Vec3i offset(int x, int y, int z) {
        return x == 0 && y == 0 && z == 0 ? this : new Vec3i(this.getX() + x, this.getY() + y, this.getZ() + z);
    }
 
    public Vec3i offset(Vec3i vec) {
        return this.offset(vec.getX(), vec.getY(), vec.getZ());
    }
 
    public Vec3i subtract(Vec3i vec) {
        return this.offset(-vec.getX(), -vec.getY(), -vec.getZ());
    }
 
    public Vec3i multiply(int scale) {
        if (scale == 1) {
            return this;
        } else {
            return scale == 0 ? ZERO : new Vec3i(this.getX() * scale, this.getY() * scale, this.getZ() * scale);
        }
    }
 
    public Vec3i multiply(int xScale, int yScale, int zScale) {
        return new Vec3i(this.getX() * xScale, this.getY() * yScale, this.getZ() * zScale);
    }
 
    public Vec3i above() {
        return this.above(1);
    }
 
    public Vec3i above(int steps) {
        return this.relative(Direction.UP, steps);
    }
 
    public Vec3i below() {
        return this.below(1);
    }
 
    public Vec3i below(int steps) {
        return this.relative(Direction.DOWN, steps);
    }
 
    public Vec3i north() {
        return this.north(1);
    }
 
    public Vec3i north(int steps) {
        return this.relative(Direction.NORTH, steps);
    }
 
    public Vec3i south() {
        return this.south(1);
    }
 
    public Vec3i south(int steps) {
        return this.relative(Direction.SOUTH, steps);
    }
 
    public Vec3i west() {
        return this.west(1);
    }
 
    public Vec3i west(int steps) {
        return this.relative(Direction.WEST, steps);
    }
 
    public Vec3i east() {
        return this.east(1);
    }
 
    public Vec3i east(int steps) {
        return this.relative(Direction.EAST, steps);
    }
 
    public Vec3i relative(Direction direction) {
        return this.relative(direction, 1);
    }
 
    public Vec3i relative(Direction direction, int steps) {
        return steps == 0
            ? this
            : new Vec3i(this.getX() + direction.getStepX() * steps, this.getY() + direction.getStepY() * steps, this.getZ() + direction.getStepZ() * steps);
    }
 
    public Vec3i relative(Direction.Axis axis, int steps) {
        if (steps == 0) {
            return this;
        } else {
            int xStep = axis == Direction.Axis.X ? steps : 0;
            int yStep = axis == Direction.Axis.Y ? steps : 0;
            int zStep = axis == Direction.Axis.Z ? steps : 0;
            return new Vec3i(this.getX() + xStep, this.getY() + yStep, this.getZ() + zStep);
        }
    }
 
    public Vec3i cross(Vec3i upVector) {
        return new Vec3i(
            this.getY() * upVector.getZ() - this.getZ() * upVector.getY(),
            this.getZ() * upVector.getX() - this.getX() * upVector.getZ(),
            this.getX() * upVector.getY() - this.getY() * upVector.getX()
        );
    }
 
    public boolean closerThan(Vec3i pos, double distance) {
        return this.distSqr(pos) < Mth.square(distance);
    }
 
    public boolean closerToCenterThan(Position pos, double distance) {
        return this.distToCenterSqr(pos) < Mth.square(distance);
    }
 
    public double distSqr(Vec3i pos) {
        return this.distToLowCornerSqr(pos.getX(), pos.getY(), pos.getZ());
    }
 
    public double distToCenterSqr(Position pos) {
        return this.distToCenterSqr(pos.x(), pos.y(), pos.z());
    }
 
    public double distToCenterSqr(double x, double y, double z) {
        double dx = this.getX() + 0.5 - x;
        double dy = this.getY() + 0.5 - y;
        double dz = this.getZ() + 0.5 - z;
        return dx * dx + dy * dy + dz * dz;
    }
 
    public double distToLowCornerSqr(double x, double y, double z) {
        double dx = this.getX() - x;
        double dy = this.getY() - y;
        double dz = this.getZ() - z;
        return dx * dx + dy * dy + dz * dz;
    }
 
    public int distManhattan(Vec3i pos) {
        float xd = Math.abs(pos.getX() - this.getX());
        float yd = Math.abs(pos.getY() - this.getY());
        float zd = Math.abs(pos.getZ() - this.getZ());
        return (int)(xd + yd + zd);
    }
 
    public int distChessboard(Vec3i pos) {
        int xd = Math.abs(this.getX() - pos.getX());
        int yd = Math.abs(this.getY() - pos.getY());
        int zd = Math.abs(this.getZ() - pos.getZ());
        return Math.max(Math.max(xd, yd), zd);
    }
 
    public int get(Direction.Axis axis) {
        return axis.choose(this.x, this.y, this.z);
    }
 
    public Vector3i toMutable() {
        return new Vector3i(this.x, this.y, this.z);
    }
 
    @Override
    public String toString() {
        return MoreObjects.toStringHelper(this).add("x", this.getX()).add("y", this.getY()).add("z", this.getZ()).toString();
    }
 
    public String toShortString() {
        return this.getX() + ", " + this.getY() + ", " + this.getZ();
    }
}

引用的其他类

  • Direction

    • 引用位置: 参数
  • Position

    • 引用位置: 参数
  • StreamCodec

    • 引用位置: 字段/方法调用
    • 关联成员: StreamCodec.composite()
  • Mth

    • 引用位置: 方法调用
    • 关联成员: Mth.square()
  • Util

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