package net.minecraft.core;

import net.minecraft.Util;
import com.google.common.collect.Maps;
import org.apache.logging.log4j.LogManager;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import java.util.function.Supplier;
import com.mojang.math.Matrix4f;
import com.mojang.math.Transformation;
import java.util.EnumMap;
import org.apache.logging.log4j.Logger;

public class BlockMath {
    private static final Logger LOGGER;
    public static final EnumMap<Direction, Transformation> vanillaUvTransformLocalToGlobal;
    public static final EnumMap<Direction, Transformation> vanillaUvTransformGlobalToLocal;
    
    public static Transformation blockCenterToCorner(final Transformation d) {
        final Matrix4f b2 = Matrix4f.createTranslateMatrix(0.5f, 0.5f, 0.5f);
        b2.multiply(d.getMatrix());
        b2.multiply(Matrix4f.createTranslateMatrix(-0.5f, -0.5f, -0.5f));
        return new Transformation(b2);
    }
    
    public static Transformation getUVLockTransform(final Transformation d, final Direction fp, final Supplier<String> supplier) {
        final Direction fp2 = Direction.rotate(d.getMatrix(), fp);
        final Transformation d2 = d.inverse();
        if (d2 == null) {
            BlockMath.LOGGER.warn((String)supplier.get());
            return new Transformation(null, null, new Vector3f(0.0f, 0.0f, 0.0f), null);
        }
        final Transformation d3 = BlockMath.vanillaUvTransformGlobalToLocal.get(fp).compose(d2).compose(BlockMath.vanillaUvTransformLocalToGlobal.get(fp2));
        return blockCenterToCorner(d3);
    }
    
    static {
        LOGGER = LogManager.getLogger();
        final Direction east;
        final Quaternion c2;
        final Transformation value;
        final Object e1;
        final Direction west;
        final Quaternion c3;
        final Transformation value2;
        final Object e2;
        final Direction north;
        final Quaternion c4;
        final Transformation value3;
        final Object e3;
        final Direction up;
        final Quaternion c5;
        final Transformation value4;
        final Object e4;
        final Direction down;
        final Quaternion c6;
        final Transformation value5;
        final Object e5;
        vanillaUvTransformLocalToGlobal = Util.<EnumMap<Direction, Transformation>>make(Maps.<Direction, Transformation>newEnumMap(Direction.class), enumMap -> {
            enumMap.put(Direction.SOUTH, Transformation.identity());
            east = Direction.EAST;
            // new(com.mojang.math.Transformation.class)
            new Quaternion(new Vector3f(0.0f, 1.0f, 0.0f), 90.0f, true);
            new Transformation((Vector3f)e1, c2, null, null);
            enumMap.put(east, value);
            west = Direction.WEST;
            // new(com.mojang.math.Transformation.class)
            new Quaternion(new Vector3f(0.0f, 1.0f, 0.0f), -90.0f, true);
            new Transformation((Vector3f)e2, c3, null, null);
            enumMap.put(west, value2);
            north = Direction.NORTH;
            // new(com.mojang.math.Transformation.class)
            new Quaternion(new Vector3f(0.0f, 1.0f, 0.0f), 180.0f, true);
            new Transformation((Vector3f)e3, c4, null, null);
            enumMap.put(north, value3);
            up = Direction.UP;
            // new(com.mojang.math.Transformation.class)
            new Quaternion(new Vector3f(1.0f, 0.0f, 0.0f), -90.0f, true);
            new Transformation((Vector3f)e4, c5, null, null);
            enumMap.put(up, value4);
            down = Direction.DOWN;
            // new(com.mojang.math.Transformation.class)
            new Quaternion(new Vector3f(1.0f, 0.0f, 0.0f), 90.0f, true);
            new Transformation((Vector3f)e5, c6, null, null);
            enumMap.put(down, value5);
            return;
        });
        final Direction[] array;
        int length;
        int i = 0;
        Direction fp5;
        vanillaUvTransformGlobalToLocal = Util.<EnumMap<Direction, Transformation>>make(Maps.<Direction, Transformation>newEnumMap(Direction.class), enumMap -> {
            Direction.values();
            for (length = array.length; i < length; ++i) {
                fp5 = array[i];
                enumMap.put(fp5, BlockMath.vanillaUvTransformLocalToGlobal.get(fp5).inverse());
            }
        });
    }
}
