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 f) {
        final Matrix4f b2 = Matrix4f.createTranslateMatrix(0.5f, 0.5f, 0.5f);
        b2.multiply(f.getMatrix());
        b2.multiply(Matrix4f.createTranslateMatrix(-0.5f, -0.5f, -0.5f));
        return new Transformation(b2);
    }
    
    public static Transformation getUVLockTransform(final Transformation f, final Direction fz, final Supplier<String> supplier) {
        final Direction fz2 = Direction.rotate(f.getMatrix(), fz);
        final Transformation f2 = f.inverse();
        if (f2 == null) {
            BlockMath.LOGGER.warn((String)supplier.get());
            return new Transformation(null, null, new Vector3f(0.0f, 0.0f, 0.0f), null);
        }
        final Transformation f3 = BlockMath.vanillaUvTransformGlobalToLocal.get(fz).compose(f2).compose(BlockMath.vanillaUvTransformLocalToGlobal.get(fz2));
        return blockCenterToCorner(f3);
    }
    
    static {
        LOGGER = LogManager.getLogger();
        final Direction east;
        final Quaternion d2;
        final Transformation value;
        final Object g1;
        final Direction west;
        final Quaternion d3;
        final Transformation value2;
        final Object g2;
        final Direction north;
        final Quaternion d4;
        final Transformation value3;
        final Object g3;
        final Direction up;
        final Quaternion d5;
        final Transformation value4;
        final Object g4;
        final Direction down;
        final Quaternion d6;
        final Transformation value5;
        final Object g5;
        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)g1, d2, 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)g2, d3, 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)g3, d4, 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)g4, d5, 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)g5, d6, null, null);
            enumMap.put(down, value5);
            return;
        });
        final Direction[] array;
        int length;
        int i = 0;
        Direction fz5;
        vanillaUvTransformGlobalToLocal = Util.<EnumMap<Direction, Transformation>>make(Maps.<Direction, Transformation>newEnumMap(Direction.class), enumMap -> {
            Direction.values();
            for (length = array.length; i < length; ++i) {
                fz5 = array[i];
                enumMap.put(fz5, BlockMath.vanillaUvTransformLocalToGlobal.get(fz5).inverse());
            }
        });
    }
}
