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

import net.minecraft.util.GsonHelper;
import com.google.gson.JsonParseException;
import net.minecraft.client.resources.model.BlockModelRotation;
import com.google.gson.JsonObject;
import com.google.gson.JsonDeserializationContext;
import java.lang.reflect.Type;
import com.google.gson.JsonElement;
import com.google.gson.JsonDeserializer;
import java.util.Objects;
import com.mojang.math.Transformation;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.client.resources.model.ModelState;

public class Variant implements ModelState {
    private final ResourceLocation modelLocation;
    private final Transformation rotation;
    private final boolean uvLock;
    private final int weight;
    
    public Variant(final ResourceLocation uh, final Transformation f, final boolean boolean3, final int integer) {
        this.modelLocation = uh;
        this.rotation = f;
        this.uvLock = boolean3;
        this.weight = integer;
    }
    
    public ResourceLocation getModelLocation() {
        return this.modelLocation;
    }
    
    @Override
    public Transformation getRotation() {
        return this.rotation;
    }
    
    @Override
    public boolean isUvLocked() {
        return this.uvLock;
    }
    
    public int getWeight() {
        return this.weight;
    }
    
    @Override
    public String toString() {
        return "Variant{modelLocation=" + this.modelLocation + ", rotation=" + this.rotation + ", uvLock=" + this.uvLock + ", weight=" + this.weight + '}';
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (object instanceof Variant) {
            final Variant edh3 = (Variant)object;
            return this.modelLocation.equals(edh3.modelLocation) && Objects.equals(this.rotation, edh3.rotation) && this.uvLock == edh3.uvLock && this.weight == edh3.weight;
        }
        return false;
    }
    
    @Override
    public int hashCode() {
        int integer2 = this.modelLocation.hashCode();
        integer2 = 31 * integer2 + this.rotation.hashCode();
        integer2 = 31 * integer2 + Boolean.valueOf(this.uvLock).hashCode();
        integer2 = 31 * integer2 + this.weight;
        return integer2;
    }
    
    public static class Deserializer implements JsonDeserializer<Variant> {
        @Override
        public Variant deserialize(final JsonElement jsonElement, final Type type, final JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
            final JsonObject jsonObject5 = jsonElement.getAsJsonObject();
            final ResourceLocation uh6 = this.getModel(jsonObject5);
            final BlockModelRotation eni7 = this.getBlockRotation(jsonObject5);
            final boolean boolean8 = this.getUvLock(jsonObject5);
            final int integer9 = this.getWeight(jsonObject5);
            return new Variant(uh6, eni7.getRotation(), boolean8, integer9);
        }
        
        private boolean getUvLock(final JsonObject jsonObject) {
            return GsonHelper.getAsBoolean(jsonObject, "uvlock", false);
        }
        
        protected BlockModelRotation getBlockRotation(final JsonObject jsonObject) {
            final int integer3 = GsonHelper.getAsInt(jsonObject, "x", 0);
            final int integer4 = GsonHelper.getAsInt(jsonObject, "y", 0);
            final BlockModelRotation eni5 = BlockModelRotation.by(integer3, integer4);
            if (eni5 == null) {
                throw new JsonParseException("Invalid BlockModelRotation x: " + integer3 + ", y: " + integer4);
            }
            return eni5;
        }
        
        protected ResourceLocation getModel(final JsonObject jsonObject) {
            return new ResourceLocation(GsonHelper.getAsString(jsonObject, "model"));
        }
        
        protected int getWeight(final JsonObject jsonObject) {
            final int integer3 = GsonHelper.getAsInt(jsonObject, "weight", 1);
            if (integer3 < 1) {
                throw new JsonParseException("Invalid weight " + integer3 + " found, expected integer >= 1");
            }
            return integer3;
        }
    }
}
