Direction.java
net.minecraft.core.Direction
信息
- 全限定名:net.minecraft.core.Direction
- 类型:public enum
- 包:net.minecraft.core
- 源码路径:src/main/java/net/minecraft/core/Direction.java
- 起始行号:L32
- 实现:StringRepresentable
- 职责:
TODO
字段/常量
-
Vec3i, Vec3i, Vec3i, Vec3i, Vec3i, Vec3i- 类型:
DOWN(,,,,Direction.AxisDirection.NEGATIVE,Direction.Axis.Y,new - 修饰符:
package-private - 源码定位:
L33 - 说明:
TODO
- 类型:
-
CODEC- 类型:
StringRepresentable.EnumCodec<Direction> - 修饰符:
public static final - 源码定位:
L40 - 说明:
TODO
- 类型:
-
VERTICAL_CODEC- 类型:
Codec<Direction> - 修饰符:
public static final - 源码定位:
L41 - 说明:
TODO
- 类型:
-
BY_ID- 类型:
IntFunction<Direction> - 修饰符:
public static final - 源码定位:
L42 - 说明:
TODO
- 类型:
-
STREAM_CODEC- 类型:
StreamCodec<ByteBuf,Direction> - 修饰符:
public static final - 源码定位:
L43 - 说明:
TODO
- 类型:
-
LEGACY_ID_CODEC- 类型:
Codec<Direction> - 修饰符:
public static final - 源码定位:
L44 - 说明:
TODO
- 类型:
-
LEGACY_ID_CODEC_2D- 类型:
Codec<Direction> - 修饰符:
public static final - 源码定位:
L46 - 说明:
TODO
- 类型:
-
YXZ_AXIS_ORDER- 类型:
ImmutableList<Direction.Axis> - 修饰符:
private static final - 源码定位:
L48 - 说明:
TODO
- 类型:
-
YZX_AXIS_ORDER- 类型:
ImmutableList<Direction.Axis> - 修饰符:
private static final - 源码定位:
L49 - 说明:
TODO
- 类型:
-
data3d- 类型:
int - 修饰符:
private final - 源码定位:
L50 - 说明:
TODO
- 类型:
-
oppositeIndex- 类型:
int - 修饰符:
private final - 源码定位:
L51 - 说明:
TODO
- 类型:
-
data2d- 类型:
int - 修饰符:
private final - 源码定位:
L52 - 说明:
TODO
- 类型:
-
name- 类型:
String - 修饰符:
private final - 源码定位:
L53 - 说明:
TODO
- 类型:
-
axis- 类型:
Direction.Axis - 修饰符:
private final - 源码定位:
L54 - 说明:
TODO
- 类型:
-
axisDirection- 类型:
Direction.AxisDirection - 修饰符:
private final - 源码定位:
L55 - 说明:
TODO
- 类型:
-
normal- 类型:
Vec3i - 修饰符:
private final - 源码定位:
L56 - 说明:
TODO
- 类型:
-
normalVec3- 类型:
Vec3 - 修饰符:
private final - 源码定位:
L57 - 说明:
TODO
- 类型:
-
normalVec3f- 类型:
Vector3fc - 修饰符:
private final - 源码定位:
L58 - 说明:
TODO
- 类型:
-
VALUES- 类型:
Direction[] - 修饰符:
private static final - 源码定位:
L59 - 说明:
TODO
- 类型:
-
BY_3D_DATA- 类型:
Direction[] - 修饰符:
private static final - 源码定位:
L60 - 说明:
TODO
- 类型:
-
BY_2D_DATA- 类型:
Direction[] - 修饰符:
private static final - 源码定位:
L61 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.core.Direction.Axis- 类型:
enum - 修饰符:
public static - 源码定位:
L394 - 说明:
TODO
- 类型:
-
net.minecraft.core.Direction.AxisDirection- 类型:
enum - 修饰符:
public static - 源码定位:
L538 - 说明:
TODO
- 类型:
-
net.minecraft.core.Direction.Plane- 类型:
enum - 修饰符:
public static - 源码定位:
L568 - 说明:
TODO
- 类型:
构造器
private Direction(int data3d, int oppositeIndex, int data2d, String name, Direction.AxisDirection axisDirection, Direction.Axis axis, Vec3i normal) @ L66
- 构造器名:Direction
- 源码定位:L66
- 修饰符:private
参数:
- data3d: int
- oppositeIndex: int
- data2d: int
- name: String
- axisDirection: Direction.AxisDirection
- axis: Direction.Axis
- normal: Vec3i
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static Direction[] orderedByNearest(Entity entity) @ L78
- 方法名:orderedByNearest
- 源码定位:L78
- 返回类型:Direction[]
- 修饰符:public static
参数:
- entity: Entity
说明:
TODO
private static Direction[] makeDirectionArray(Direction axis1, Direction axis2, Direction axis3) @ L109
- 方法名:makeDirectionArray
- 源码定位:L109
- 返回类型:Direction[]
- 修饰符:private static
参数:
- axis1: Direction
- axis2: Direction
- axis3: Direction
说明:
TODO
public static Direction rotate(Matrix4fc matrix, Direction facing) @ L113
- 方法名:rotate
- 源码定位:L113
- 返回类型:Direction
- 修饰符:public static
参数:
- matrix: Matrix4fc
- facing: Direction
说明:
TODO
public static Collection<Direction> allShuffled(RandomSource random) @ L118
- 方法名:allShuffled
- 源码定位:L118
- 返回类型:Collection
- 修饰符:public static
参数:
- random: RandomSource
说明:
TODO
public static Stream<Direction> stream() @ L122
- 方法名:stream
- 源码定位:L122
- 返回类型:Stream
- 修饰符:public static
参数:
- 无
说明:
TODO
public static float getYRot(Direction direction) @ L126
- 方法名:getYRot
- 源码定位:L126
- 返回类型:float
- 修饰符:public static
参数:
- direction: Direction
说明:
TODO
public Quaternionf getRotation() @ L136
- 方法名:getRotation
- 源码定位:L136
- 返回类型:Quaternionf
- 修饰符:public
参数:
- 无
说明:
TODO
public int get3DDataValue() @ L147
- 方法名:get3DDataValue
- 源码定位:L147
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int get2DDataValue() @ L151
- 方法名:get2DDataValue
- 源码定位:L151
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public Direction.AxisDirection getAxisDirection() @ L155
- 方法名:getAxisDirection
- 源码定位:L155
- 返回类型:Direction.AxisDirection
- 修饰符:public
参数:
- 无
说明:
TODO
public static Direction getFacingAxis(Entity entity, Direction.Axis axis) @ L159
- 方法名:getFacingAxis
- 源码定位:L159
- 返回类型:Direction
- 修饰符:public static
参数:
- entity: Entity
- axis: Direction.Axis
说明:
TODO
public Direction getOpposite() @ L167
- 方法名:getOpposite
- 源码定位:L167
- 返回类型:Direction
- 修饰符:public
参数:
- 无
说明:
TODO
public Direction getClockWise(Direction.Axis axis) @ L171
- 方法名:getClockWise
- 源码定位:L171
- 返回类型:Direction
- 修饰符:public
参数:
- axis: Direction.Axis
说明:
TODO
public Direction getCounterClockWise(Direction.Axis axis) @ L179
- 方法名:getCounterClockWise
- 源码定位:L179
- 返回类型:Direction
- 修饰符:public
参数:
- axis: Direction.Axis
说明:
TODO
public Direction getClockWise() @ L187
- 方法名:getClockWise
- 源码定位:L187
- 返回类型:Direction
- 修饰符:public
参数:
- 无
说明:
TODO
private Direction getClockWiseX() @ L197
- 方法名:getClockWiseX
- 源码定位:L197
- 返回类型:Direction
- 修饰符:private
参数:
- 无
说明:
TODO
private Direction getCounterClockWiseX() @ L207
- 方法名:getCounterClockWiseX
- 源码定位:L207
- 返回类型:Direction
- 修饰符:private
参数:
- 无
说明:
TODO
private Direction getClockWiseZ() @ L217
- 方法名:getClockWiseZ
- 源码定位:L217
- 返回类型:Direction
- 修饰符:private
参数:
- 无
说明:
TODO
private Direction getCounterClockWiseZ() @ L227
- 方法名:getCounterClockWiseZ
- 源码定位:L227
- 返回类型:Direction
- 修饰符:private
参数:
- 无
说明:
TODO
public Direction getCounterClockWise() @ L237
- 方法名:getCounterClockWise
- 源码定位:L237
- 返回类型:Direction
- 修饰符:public
参数:
- 无
说明:
TODO
public int getStepX() @ L247
- 方法名:getStepX
- 源码定位:L247
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getStepY() @ L251
- 方法名:getStepY
- 源码定位:L251
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public int getStepZ() @ L255
- 方法名:getStepZ
- 源码定位:L255
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public Vector3f step() @ L259
- 方法名:step
- 源码定位:L259
- 返回类型:Vector3f
- 修饰符:public
参数:
- 无
说明:
TODO
public String getName() @ L263
- 方法名:getName
- 源码定位:L263
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public Direction.Axis getAxis() @ L267
- 方法名:getAxis
- 源码定位:L267
- 返回类型:Direction.Axis
- 修饰符:public
参数:
- 无
说明:
TODO
public static Direction byName(String name) @ L271
- 方法名:byName
- 源码定位:L271
- 返回类型:Direction
- 修饰符:public static
参数:
- name: String
说明:
TODO
public static Direction from3DDataValue(int data) @ L275
- 方法名:from3DDataValue
- 源码定位:L275
- 返回类型:Direction
- 修饰符:public static
参数:
- data: int
说明:
TODO
public static Direction from2DDataValue(int data) @ L279
- 方法名:from2DDataValue
- 源码定位:L279
- 返回类型:Direction
- 修饰符:public static
参数:
- data: int
说明:
TODO
public static Direction fromYRot(double yRot) @ L283
- 方法名:fromYRot
- 源码定位:L283
- 返回类型:Direction
- 修饰符:public static
参数:
- yRot: double
说明:
TODO
public static Direction fromAxisAndDirection(Direction.Axis axis, Direction.AxisDirection direction) @ L287
- 方法名:fromAxisAndDirection
- 源码定位:L287
- 返回类型:Direction
- 修饰符:public static
参数:
- axis: Direction.Axis
- direction: Direction.AxisDirection
说明:
TODO
public float toYRot() @ L295
- 方法名:toYRot
- 源码定位:L295
- 返回类型:float
- 修饰符:public
参数:
- 无
说明:
TODO
public static Direction getRandom(RandomSource random) @ L299
- 方法名:getRandom
- 源码定位:L299
- 返回类型:Direction
- 修饰符:public static
参数:
- random: RandomSource
说明:
TODO
public static Direction getApproximateNearest(double dx, double dy, double dz) @ L303
- 方法名:getApproximateNearest
- 源码定位:L303
- 返回类型:Direction
- 修饰符:public static
参数:
- dx: double
- dy: double
- dz: double
说明:
TODO
public static Direction getApproximateNearest(float dx, float dy, float dz) @ L307
- 方法名:getApproximateNearest
- 源码定位:L307
- 返回类型:Direction
- 修饰符:public static
参数:
- dx: float
- dy: float
- dz: float
说明:
TODO
public static Direction getApproximateNearest(Vec3 vec) @ L322
- 方法名:getApproximateNearest
- 源码定位:L322
- 返回类型:Direction
- 修饰符:public static
参数:
- vec: Vec3
说明:
TODO
public static Direction getNearest(int x, int y, int z, Direction orElse) @ L326
- 方法名:getNearest
- 源码定位:L326
- 返回类型:Direction
- 修饰符:public static
参数:
- x: int
- y: int
- z: int
- orElse: Direction
说明:
TODO
public static Direction getNearest(Vec3i vec, Direction orElse) @ L342
- 方法名:getNearest
- 源码定位:L342
- 返回类型:Direction
- 修饰符:public static
参数:
- vec: Vec3i
- orElse: Direction
说明:
TODO
public String toString() @ L347
- 方法名:toString
- 源码定位:L347
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public String getSerializedName() @ L352
- 方法名:getSerializedName
- 源码定位:L352
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
private static DataResult<Direction> verifyVertical(Direction v) @ L357
- 方法名:verifyVertical
- 源码定位:L357
- 返回类型:DataResult
- 修饰符:private static
参数:
- v: Direction
说明:
TODO
public static Direction get(Direction.AxisDirection axisDirection, Direction.Axis axis) @ L361
- 方法名:get
- 源码定位:L361
- 返回类型:Direction
- 修饰符:public static
参数:
- axisDirection: Direction.AxisDirection
- axis: Direction.Axis
说明:
TODO
public static ImmutableList<Direction.Axis> axisStepOrder(Vec3 movement) @ L371
- 方法名:axisStepOrder
- 源码定位:L371
- 返回类型:ImmutableList<Direction.Axis>
- 修饰符:public static
参数:
- movement: Vec3
说明:
TODO
public Vec3i getUnitVec3i() @ L375
- 方法名:getUnitVec3i
- 源码定位:L375
- 返回类型:Vec3i
- 修饰符:public
参数:
- 无
说明:
TODO
public Vec3 getUnitVec3() @ L379
- 方法名:getUnitVec3
- 源码定位:L379
- 返回类型:Vec3
- 修饰符:public
参数:
- 无
说明:
TODO
public Vector3fc getUnitVec3f() @ L383
- 方法名:getUnitVec3f
- 源码定位:L383
- 返回类型:Vector3fc
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean isFacingAngle(float yAngle) @ L387
- 方法名:isFacingAngle
- 源码定位:L387
- 返回类型:boolean
- 修饰符:public
参数:
- yAngle: float
说明:
TODO
代码
public enum Direction implements StringRepresentable {
DOWN(0, 1, -1, "down", Direction.AxisDirection.NEGATIVE, Direction.Axis.Y, new Vec3i(0, -1, 0)),
UP(1, 0, -1, "up", Direction.AxisDirection.POSITIVE, Direction.Axis.Y, new Vec3i(0, 1, 0)),
NORTH(2, 3, 2, "north", Direction.AxisDirection.NEGATIVE, Direction.Axis.Z, new Vec3i(0, 0, -1)),
SOUTH(3, 2, 0, "south", Direction.AxisDirection.POSITIVE, Direction.Axis.Z, new Vec3i(0, 0, 1)),
WEST(4, 5, 1, "west", Direction.AxisDirection.NEGATIVE, Direction.Axis.X, new Vec3i(-1, 0, 0)),
EAST(5, 4, 3, "east", Direction.AxisDirection.POSITIVE, Direction.Axis.X, new Vec3i(1, 0, 0));
public static final StringRepresentable.EnumCodec<Direction> CODEC = StringRepresentable.fromEnum(Direction::values);
public static final Codec<Direction> VERTICAL_CODEC = CODEC.validate(Direction::verifyVertical);
public static final IntFunction<Direction> BY_ID = ByIdMap.continuous(Direction::get3DDataValue, values(), ByIdMap.OutOfBoundsStrategy.WRAP);
public static final StreamCodec<ByteBuf, Direction> STREAM_CODEC = ByteBufCodecs.idMapper(BY_ID, Direction::get3DDataValue);
@Deprecated
public static final Codec<Direction> LEGACY_ID_CODEC = Codec.BYTE.xmap(Direction::from3DDataValue, d -> (byte)d.get3DDataValue());
@Deprecated
public static final Codec<Direction> LEGACY_ID_CODEC_2D = Codec.BYTE.xmap(Direction::from2DDataValue, d -> (byte)d.get2DDataValue());
private static final ImmutableList<Direction.Axis> YXZ_AXIS_ORDER = ImmutableList.of(Direction.Axis.Y, Direction.Axis.X, Direction.Axis.Z);
private static final ImmutableList<Direction.Axis> YZX_AXIS_ORDER = ImmutableList.of(Direction.Axis.Y, Direction.Axis.Z, Direction.Axis.X);
private final int data3d;
private final int oppositeIndex;
private final int data2d;
private final String name;
private final Direction.Axis axis;
private final Direction.AxisDirection axisDirection;
private final Vec3i normal;
private final Vec3 normalVec3;
private final Vector3fc normalVec3f;
private static final Direction[] VALUES = values();
private static final Direction[] BY_3D_DATA = Arrays.stream(VALUES).sorted(Comparator.comparingInt(d -> d.data3d)).toArray(Direction[]::new);
private static final Direction[] BY_2D_DATA = Arrays.stream(VALUES)
.filter(d -> d.getAxis().isHorizontal())
.sorted(Comparator.comparingInt(d -> d.data2d))
.toArray(Direction[]::new);
private Direction(int data3d, int oppositeIndex, int data2d, String name, Direction.AxisDirection axisDirection, Direction.Axis axis, Vec3i normal) {
this.data3d = data3d;
this.data2d = data2d;
this.oppositeIndex = oppositeIndex;
this.name = name;
this.axis = axis;
this.axisDirection = axisDirection;
this.normal = normal;
this.normalVec3 = Vec3.atLowerCornerOf(normal);
this.normalVec3f = new Vector3f(normal.getX(), normal.getY(), normal.getZ());
}
public static Direction[] orderedByNearest(Entity entity) {
float pitch = entity.getViewXRot(1.0F) * (float) (Math.PI / 180.0);
float yaw = -entity.getViewYRot(1.0F) * (float) (Math.PI / 180.0);
float pitchSin = Mth.sin(pitch);
float pitchCos = Mth.cos(pitch);
float yawSin = Mth.sin(yaw);
float yawCos = Mth.cos(yaw);
boolean xPos = yawSin > 0.0F;
boolean yPos = pitchSin < 0.0F;
boolean zPos = yawCos > 0.0F;
float xYaw = xPos ? yawSin : -yawSin;
float yMag = yPos ? -pitchSin : pitchSin;
float zYaw = zPos ? yawCos : -yawCos;
float xMag = xYaw * pitchCos;
float zMag = zYaw * pitchCos;
Direction axisX = xPos ? EAST : WEST;
Direction axisY = yPos ? UP : DOWN;
Direction axisZ = zPos ? SOUTH : NORTH;
if (xYaw > zYaw) {
if (yMag > xMag) {
return makeDirectionArray(axisY, axisX, axisZ);
} else {
return zMag > yMag ? makeDirectionArray(axisX, axisZ, axisY) : makeDirectionArray(axisX, axisY, axisZ);
}
} else if (yMag > zMag) {
return makeDirectionArray(axisY, axisZ, axisX);
} else {
return xMag > yMag ? makeDirectionArray(axisZ, axisX, axisY) : makeDirectionArray(axisZ, axisY, axisX);
}
}
private static Direction[] makeDirectionArray(Direction axis1, Direction axis2, Direction axis3) {
return new Direction[]{axis1, axis2, axis3, axis3.getOpposite(), axis2.getOpposite(), axis1.getOpposite()};
}
public static Direction rotate(Matrix4fc matrix, Direction facing) {
Vector3f vec = matrix.transformDirection(facing.normalVec3f, new Vector3f());
return getApproximateNearest(vec.x(), vec.y(), vec.z());
}
public static Collection<Direction> allShuffled(RandomSource random) {
return Util.shuffledCopy(values(), random);
}
public static Stream<Direction> stream() {
return Stream.of(VALUES);
}
public static float getYRot(Direction direction) {
return switch (direction) {
case NORTH -> 180.0F;
case SOUTH -> 0.0F;
case WEST -> 90.0F;
case EAST -> -90.0F;
default -> throw new IllegalStateException("No y-Rot for vertical axis: " + direction);
};
}
public Quaternionf getRotation() {
return switch (this) {
case DOWN -> new Quaternionf().rotationX((float) Math.PI);
case UP -> new Quaternionf();
case NORTH -> new Quaternionf().rotationXYZ((float) (Math.PI / 2), 0.0F, (float) Math.PI);
case SOUTH -> new Quaternionf().rotationX((float) (Math.PI / 2));
case WEST -> new Quaternionf().rotationXYZ((float) (Math.PI / 2), 0.0F, (float) (Math.PI / 2));
case EAST -> new Quaternionf().rotationXYZ((float) (Math.PI / 2), 0.0F, (float) (-Math.PI / 2));
};
}
public int get3DDataValue() {
return this.data3d;
}
public int get2DDataValue() {
return this.data2d;
}
public Direction.AxisDirection getAxisDirection() {
return this.axisDirection;
}
public static Direction getFacingAxis(Entity entity, Direction.Axis axis) {
return switch (axis) {
case X -> EAST.isFacingAngle(entity.getViewYRot(1.0F)) ? EAST : WEST;
case Y -> entity.getViewXRot(1.0F) < 0.0F ? UP : DOWN;
case Z -> SOUTH.isFacingAngle(entity.getViewYRot(1.0F)) ? SOUTH : NORTH;
};
}
public Direction getOpposite() {
return from3DDataValue(this.oppositeIndex);
}
public Direction getClockWise(Direction.Axis axis) {
return switch (axis) {
case X -> this != WEST && this != EAST ? this.getClockWiseX() : this;
case Y -> this != UP && this != DOWN ? this.getClockWise() : this;
case Z -> this != NORTH && this != SOUTH ? this.getClockWiseZ() : this;
};
}
public Direction getCounterClockWise(Direction.Axis axis) {
return switch (axis) {
case X -> this != WEST && this != EAST ? this.getCounterClockWiseX() : this;
case Y -> this != UP && this != DOWN ? this.getCounterClockWise() : this;
case Z -> this != NORTH && this != SOUTH ? this.getCounterClockWiseZ() : this;
};
}
public Direction getClockWise() {
return switch (this) {
case NORTH -> EAST;
case SOUTH -> WEST;
case WEST -> NORTH;
case EAST -> SOUTH;
default -> throw new IllegalStateException("Unable to get Y-rotated facing of " + this);
};
}
private Direction getClockWiseX() {
return switch (this) {
case DOWN -> SOUTH;
case UP -> NORTH;
case NORTH -> DOWN;
case SOUTH -> UP;
default -> throw new IllegalStateException("Unable to get X-rotated facing of " + this);
};
}
private Direction getCounterClockWiseX() {
return switch (this) {
case DOWN -> NORTH;
case UP -> SOUTH;
case NORTH -> UP;
case SOUTH -> DOWN;
default -> throw new IllegalStateException("Unable to get X-rotated facing of " + this);
};
}
private Direction getClockWiseZ() {
return switch (this) {
case DOWN -> WEST;
case UP -> EAST;
default -> throw new IllegalStateException("Unable to get Z-rotated facing of " + this);
case WEST -> UP;
case EAST -> DOWN;
};
}
private Direction getCounterClockWiseZ() {
return switch (this) {
case DOWN -> EAST;
case UP -> WEST;
default -> throw new IllegalStateException("Unable to get Z-rotated facing of " + this);
case WEST -> DOWN;
case EAST -> UP;
};
}
public Direction getCounterClockWise() {
return switch (this) {
case NORTH -> WEST;
case SOUTH -> EAST;
case WEST -> SOUTH;
case EAST -> NORTH;
default -> throw new IllegalStateException("Unable to get CCW facing of " + this);
};
}
public int getStepX() {
return this.normal.getX();
}
public int getStepY() {
return this.normal.getY();
}
public int getStepZ() {
return this.normal.getZ();
}
public Vector3f step() {
return new Vector3f(this.normalVec3f);
}
public String getName() {
return this.name;
}
public Direction.Axis getAxis() {
return this.axis;
}
public static @Nullable Direction byName(String name) {
return CODEC.byName(name);
}
public static Direction from3DDataValue(int data) {
return BY_3D_DATA[Mth.abs(data % BY_3D_DATA.length)];
}
public static Direction from2DDataValue(int data) {
return BY_2D_DATA[Mth.abs(data % BY_2D_DATA.length)];
}
public static Direction fromYRot(double yRot) {
return from2DDataValue(Mth.floor(yRot / 90.0 + 0.5) & 3);
}
public static Direction fromAxisAndDirection(Direction.Axis axis, Direction.AxisDirection direction) {
return switch (axis) {
case X -> direction == Direction.AxisDirection.POSITIVE ? EAST : WEST;
case Y -> direction == Direction.AxisDirection.POSITIVE ? UP : DOWN;
case Z -> direction == Direction.AxisDirection.POSITIVE ? SOUTH : NORTH;
};
}
public float toYRot() {
return (this.data2d & 3) * 90;
}
public static Direction getRandom(RandomSource random) {
return Util.getRandom(VALUES, random);
}
public static Direction getApproximateNearest(double dx, double dy, double dz) {
return getApproximateNearest((float)dx, (float)dy, (float)dz);
}
public static Direction getApproximateNearest(float dx, float dy, float dz) {
Direction result = NORTH;
float highestDot = Float.MIN_VALUE;
for (Direction direction : VALUES) {
float dot = dx * direction.normal.getX() + dy * direction.normal.getY() + dz * direction.normal.getZ();
if (dot > highestDot) {
highestDot = dot;
result = direction;
}
}
return result;
}
public static Direction getApproximateNearest(Vec3 vec) {
return getApproximateNearest(vec.x, vec.y, vec.z);
}
@Contract("_,_,_,!null->!null;_,_,_,_->_")
public static @Nullable Direction getNearest(int x, int y, int z, @Nullable Direction orElse) {
int absX = Math.abs(x);
int absY = Math.abs(y);
int absZ = Math.abs(z);
if (absX > absZ && absX > absY) {
return x < 0 ? WEST : EAST;
} else if (absZ > absX && absZ > absY) {
return z < 0 ? NORTH : SOUTH;
} else if (absY > absX && absY > absZ) {
return y < 0 ? DOWN : UP;
} else {
return orElse;
}
}
@Contract("_,!null->!null;_,_->_")
public static @Nullable Direction getNearest(Vec3i vec, @Nullable Direction orElse) {
return getNearest(vec.getX(), vec.getY(), vec.getZ(), orElse);
}
@Override
public String toString() {
return this.name;
}
@Override
public String getSerializedName() {
return this.name;
}
private static DataResult<Direction> verifyVertical(Direction v) {
return v.getAxis().isVertical() ? DataResult.success(v) : DataResult.error(() -> "Expected a vertical direction");
}
public static Direction get(Direction.AxisDirection axisDirection, Direction.Axis axis) {
for (Direction direction : VALUES) {
if (direction.getAxisDirection() == axisDirection && direction.getAxis() == axis) {
return direction;
}
}
throw new IllegalArgumentException("No such direction: " + axisDirection + " " + axis);
}
public static ImmutableList<Direction.Axis> axisStepOrder(Vec3 movement) {
return Math.abs(movement.x) < Math.abs(movement.z) ? YZX_AXIS_ORDER : YXZ_AXIS_ORDER;
}
public Vec3i getUnitVec3i() {
return this.normal;
}
public Vec3 getUnitVec3() {
return this.normalVec3;
}
public Vector3fc getUnitVec3f() {
return this.normalVec3f;
}
public boolean isFacingAngle(float yAngle) {
float radians = yAngle * (float) (Math.PI / 180.0);
float dx = -Mth.sin(radians);
float dz = Mth.cos(radians);
return this.normal.getX() * dx + this.normal.getZ() * dz > 0.0F;
}
public static enum Axis implements Predicate<Direction>, StringRepresentable {
X("x") {
@Override
public int choose(int x, int y, int z) {
return x;
}
@Override
public boolean choose(boolean x, boolean y, boolean z) {
return x;
}
@Override
public double choose(double x, double y, double z) {
return x;
}
@Override
public Direction getPositive() {
return Direction.EAST;
}
@Override
public Direction getNegative() {
return Direction.WEST;
}
},
Y("y") {
@Override
public int choose(int x, int y, int z) {
return y;
}
@Override
public double choose(double x, double y, double z) {
return y;
}
@Override
public boolean choose(boolean x, boolean y, boolean z) {
return y;
}
@Override
public Direction getPositive() {
return Direction.UP;
}
@Override
public Direction getNegative() {
return Direction.DOWN;
}
},
Z("z") {
@Override
public int choose(int x, int y, int z) {
return z;
}
@Override
public double choose(double x, double y, double z) {
return z;
}
@Override
public boolean choose(boolean x, boolean y, boolean z) {
return z;
}
@Override
public Direction getPositive() {
return Direction.SOUTH;
}
@Override
public Direction getNegative() {
return Direction.NORTH;
}
};
public static final Direction.Axis[] VALUES = values();
public static final StringRepresentable.EnumCodec<Direction.Axis> CODEC = StringRepresentable.fromEnum(Direction.Axis::values);
private final String name;
private Axis(String name) {
this.name = name;
}
public static Direction.@Nullable Axis byName(String name) {
return CODEC.byName(name);
}
public String getName() {
return this.name;
}
public boolean isVertical() {
return this == Y;
}
public boolean isHorizontal() {
return this == X || this == Z;
}
public abstract Direction getPositive();
public abstract Direction getNegative();
public Direction[] getDirections() {
return new Direction[]{this.getPositive(), this.getNegative()};
}
@Override
public String toString() {
return this.name;
}
public static Direction.Axis getRandom(RandomSource random) {
return Util.getRandom(VALUES, random);
}
public boolean test(@Nullable Direction input) {
return input != null && input.getAxis() == this;
}
public Direction.Plane getPlane() {
return switch (this) {
case X, Z -> Direction.Plane.HORIZONTAL;
case Y -> Direction.Plane.VERTICAL;
};
}
@Override
public String getSerializedName() {
return this.name;
}
public abstract int choose(final int x, final int y, final int z);
public abstract double choose(final double x, final double y, final double z);
public abstract boolean choose(final boolean x, final boolean y, final boolean z);
}
public static enum AxisDirection {
POSITIVE(1, "Towards positive"),
NEGATIVE(-1, "Towards negative");
private final int step;
private final String name;
private AxisDirection(int step, String name) {
this.step = step;
this.name = name;
}
public int getStep() {
return this.step;
}
public String getName() {
return this.name;
}
@Override
public String toString() {
return this.name;
}
public Direction.AxisDirection opposite() {
return this == POSITIVE ? NEGATIVE : POSITIVE;
}
}
public static enum Plane implements Predicate<Direction>, Iterable<Direction> {
HORIZONTAL(new Direction[]{Direction.NORTH, Direction.EAST, Direction.SOUTH, Direction.WEST}, new Direction.Axis[]{Direction.Axis.X, Direction.Axis.Z}),
VERTICAL(new Direction[]{Direction.UP, Direction.DOWN}, new Direction.Axis[]{Direction.Axis.Y});
private final Direction[] faces;
private final Direction.Axis[] axis;
private Plane(Direction[] faces, Direction.Axis[] axis) {
this.faces = faces;
this.axis = axis;
}
public Direction getRandomDirection(RandomSource random) {
return Util.getRandom(this.faces, random);
}
public Direction.Axis getRandomAxis(RandomSource random) {
return Util.getRandom(this.axis, random);
}
public boolean test(@Nullable Direction input) {
return input != null && input.getAxis().getPlane() == this;
}
@Override
public Iterator<Direction> iterator() {
return Iterators.forArray(this.faces);
}
public Stream<Direction> stream() {
return Arrays.stream(this.faces);
}
public List<Direction> shuffledCopy(RandomSource random) {
return Util.shuffledCopy(this.faces, random);
}
public int length() {
return this.faces.length;
}
}
}引用的其他类
-
- 引用位置:
参数/字段/构造调用/返回值 - 关联成员:
Vec3i()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByteBufCodecs.idMapper()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByIdMap.continuous()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Mth.abs(), Mth.cos(), Mth.floor(), Mth.sin()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
字段/实现/方法调用 - 关联成员:
StringRepresentable.fromEnum()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.getRandom(), Util.shuffledCopy()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段/方法调用/返回值 - 关联成员:
Vec3.atLowerCornerOf()
- 引用位置: