package net.minecraft.client.renderer.block.model;

import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import java.lang.reflect.Type;
import javax.vecmath.Vector3f;
import net.minecraft.util.JsonUtils;
import net.minecraft.util.MathHelper;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

@SideOnly(Side.CLIENT)
public class ItemTransformVec3f
{
    public static final ItemTransformVec3f field_178366_a = new ItemTransformVec3f(new Vector3f(), new Vector3f(), new Vector3f(1.0F, 1.0F, 1.0F));
    public final Vector3f field_178364_b;
    public final Vector3f field_178365_c;
    public final Vector3f field_178363_d;
    private static final String __OBFID = "CL_00002484";

    public ItemTransformVec3f(Vector3f p_i46214_1_, Vector3f p_i46214_2_, Vector3f p_i46214_3_)
    {
        this.field_178364_b = new Vector3f(p_i46214_1_);
        this.field_178365_c = new Vector3f(p_i46214_2_);
        this.field_178363_d = new Vector3f(p_i46214_3_);
    }

    @SideOnly(Side.CLIENT)
    static class Deserializer implements JsonDeserializer
        {
            private static final Vector3f field_178362_a = new Vector3f(0.0F, 0.0F, 0.0F);
            private static final Vector3f field_178360_b = new Vector3f(0.0F, 0.0F, 0.0F);
            private static final Vector3f field_178361_c = new Vector3f(1.0F, 1.0F, 1.0F);
            private static final String __OBFID = "CL_00002483";

            public ItemTransformVec3f func_178359_a(JsonElement p_178359_1_, Type p_178359_2_, JsonDeserializationContext p_178359_3_)
            {
                JsonObject jsonobject = p_178359_1_.getAsJsonObject();
                Vector3f vector3f = this.func_178358_a(jsonobject, "rotation", field_178362_a);
                Vector3f vector3f1 = this.func_178358_a(jsonobject, "translation", field_178360_b);
                vector3f1.scale(0.0625F);
                MathHelper.clamp_double((double)vector3f1.x, -1.5D, 1.5D);
                MathHelper.clamp_double((double)vector3f1.y, -1.5D, 1.5D);
                MathHelper.clamp_double((double)vector3f1.z, -1.5D, 1.5D);
                Vector3f vector3f2 = this.func_178358_a(jsonobject, "scale", field_178361_c);
                MathHelper.clamp_double((double)vector3f2.x, -1.5D, 1.5D);
                MathHelper.clamp_double((double)vector3f2.y, -1.5D, 1.5D);
                MathHelper.clamp_double((double)vector3f2.z, -1.5D, 1.5D);
                return new ItemTransformVec3f(vector3f, vector3f1, vector3f2);
            }

            private Vector3f func_178358_a(JsonObject p_178358_1_, String p_178358_2_, Vector3f p_178358_3_)
            {
                if (!p_178358_1_.has(p_178358_2_))
                {
                    return p_178358_3_;
                }
                else
                {
                    JsonArray jsonarray = JsonUtils.getJsonObjectJsonArrayField(p_178358_1_, p_178358_2_);

                    if (jsonarray.size() != 3)
                    {
                        throw new JsonParseException("Expected 3 " + p_178358_2_ + " values, found: " + jsonarray.size());
                    }
                    else
                    {
                        float[] afloat = new float[3];

                        for (int i = 0; i < afloat.length; ++i)
                        {
                            afloat[i] = JsonUtils.getJsonElementFloatValue(jsonarray.get(i), p_178358_2_ + "[" + i + "]");
                        }

                        return new Vector3f(afloat);
                    }
                }
            }

            public Object deserialize(JsonElement p_deserialize_1_, Type p_deserialize_2_, JsonDeserializationContext p_deserialize_3_)
            {
                return this.func_178359_a(p_deserialize_1_, p_deserialize_2_, p_deserialize_3_);
            }
        }
}