/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.Maps * org.joml.Matrix4f * org.joml.Matrix4fc * org.joml.Quaternionf * org.joml.Quaternionfc * org.joml.Vector3f */ package net.minecraft.core; import com.google.common.collect.Maps; import com.mojang.math.MatrixUtil; import com.mojang.math.Transformation; import java.util.Map; import net.minecraft.core.Direction; import net.minecraft.util.Util; import org.joml.Matrix4f; import org.joml.Matrix4fc; import org.joml.Quaternionf; import org.joml.Quaternionfc; import org.joml.Vector3f; public class BlockMath { private static final Map VANILLA_UV_TRANSFORM_LOCAL_TO_GLOBAL = Maps.newEnumMap(Map.of(Direction.SOUTH, Transformation.identity(), Direction.EAST, new Transformation(null, (Quaternionfc)new Quaternionf().rotateY(1.5707964f), null, null), Direction.WEST, new Transformation(null, (Quaternionfc)new Quaternionf().rotateY(-1.5707964f), null, null), Direction.NORTH, new Transformation(null, (Quaternionfc)new Quaternionf().rotateY((float)Math.PI), null, null), Direction.UP, new Transformation(null, (Quaternionfc)new Quaternionf().rotateX(-1.5707964f), null, null), Direction.DOWN, new Transformation(null, (Quaternionfc)new Quaternionf().rotateX(1.5707964f), null, null))); private static final Map 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((Matrix4fc)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((Matrix4fc)ret); } public static Transformation getFaceTransformation(Transformation transformation, Direction originalSide) { if (MatrixUtil.isIdentity(transformation.getMatrix())) { return transformation; } 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); } }