BlockMath.java

net.minecraft.core.BlockMath

信息

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

    TODO

字段/常量

  • VANILLA_UV_TRANSFORM_LOCAL_TO_GLOBAL

    • 类型: Map<Direction,Transformation>
    • 修饰符: private static final
    • 源码定位: L13
    • 说明:

      TODO

  • VANILLA_UV_TRANSFORM_GLOBAL_TO_LOCAL

    • 类型: Map<Direction,Transformation>
    • 修饰符: private static final
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

构造器

方法

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

public static Transformation blockCenterToCorner(Transformation transform) @ L33

  • 方法名:blockCenterToCorner
  • 源码定位:L33
  • 返回类型:Transformation
  • 修饰符:public static

参数:

  • transform: Transformation

说明:

TODO

public static Transformation blockCornerToCenter(Transformation transform) @ L40

  • 方法名:blockCornerToCenter
  • 源码定位:L40
  • 返回类型:Transformation
  • 修饰符:public static

参数:

  • transform: Transformation

说明:

TODO

public static Transformation getFaceTransformation(Transformation transformation, Direction originalSide) @ L47

  • 方法名:getFaceTransformation
  • 源码定位:L47
  • 返回类型:Transformation
  • 修饰符:public static

参数:

  • transformation: Transformation
  • originalSide: Direction

说明:

TODO

代码

public class BlockMath {
    private static final Map<Direction, Transformation> VANILLA_UV_TRANSFORM_LOCAL_TO_GLOBAL = Maps.newEnumMap(
        Map.of(
            Direction.SOUTH,
            Transformation.IDENTITY,
            Direction.EAST,
            new Transformation(null, new Quaternionf().rotateY((float) (Math.PI / 2)), null, null),
            Direction.WEST,
            new Transformation(null, new Quaternionf().rotateY((float) (-Math.PI / 2)), null, null),
            Direction.NORTH,
            new Transformation(null, new Quaternionf().rotateY((float) Math.PI), null, null),
            Direction.UP,
            new Transformation(null, new Quaternionf().rotateX((float) (-Math.PI / 2)), null, null),
            Direction.DOWN,
            new Transformation(null, new Quaternionf().rotateX((float) (Math.PI / 2)), null, null)
        )
    );
    private static final Map<Direction, Transformation> VANILLA_UV_TRANSFORM_GLOBAL_TO_LOCAL = Maps.newEnumMap(
        Util.mapValues(VANILLA_UV_TRANSFORM_LOCAL_TO_GLOBAL, Transformation::inverse)
    );
 
    public static Transformation blockCenterToCorner(Transformation transform) {
        Matrix4f ret = new Matrix4f().translation(0.5F, 0.5F, 0.5F);
        ret.mul(transform.getMatrix());
        ret.translate(-0.5F, -0.5F, -0.5F);
        return new Transformation(ret);
    }
 
    public static Transformation blockCornerToCenter(Transformation transform) {
        Matrix4f ret = new Matrix4f().translation(-0.5F, -0.5F, -0.5F);
        ret.mul(transform.getMatrix());
        ret.translate(0.5F, 0.5F, 0.5F);
        return new Transformation(ret);
    }
 
    public static Transformation getFaceTransformation(Transformation transformation, Direction originalSide) {
        if (MatrixUtil.isIdentity(transformation.getMatrix())) {
            return transformation;
        } else {
            Transformation faceAction = VANILLA_UV_TRANSFORM_LOCAL_TO_GLOBAL.get(originalSide);
            faceAction = transformation.compose(faceAction);
            Vector3f transformedNormal = faceAction.getMatrix().transformDirection(new Vector3f(0.0F, 0.0F, 1.0F));
            Direction newSide = Direction.getApproximateNearest(transformedNormal.x, transformedNormal.y, transformedNormal.z);
            return VANILLA_UV_TRANSFORM_GLOBAL_TO_LOCAL.get(newSide).compose(faceAction);
        }
    }
}

引用的其他类

  • MatrixUtil

    • 引用位置: 方法调用
    • 关联成员: MatrixUtil.isIdentity()
  • Transformation

    • 引用位置: 参数/字段/构造调用/返回值
    • 关联成员: Transformation()
  • Direction

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Direction.getApproximateNearest()
  • Util

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