package net.minecraft.client.resources.model;

import java.util.Objects;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.renderer.MultiBufferSource;
import java.util.function.Function;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import javax.annotation.Nullable;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;

public class Material {
    private final ResourceLocation atlasLocation;
    private final ResourceLocation texture;
    @Nullable
    private RenderType renderType;
    
    public Material(final ResourceLocation sm1, final ResourceLocation sm2) {
        this.atlasLocation = sm1;
        this.texture = sm2;
    }
    
    public ResourceLocation atlasLocation() {
        return this.atlasLocation;
    }
    
    public ResourceLocation texture() {
        return this.texture;
    }
    
    public TextureAtlasSprite sprite() {
        return Minecraft.getInstance().getTextureAtlas(this.atlasLocation()).apply(this.texture());
    }
    
    public RenderType renderType(final Function<ResourceLocation, RenderType> function) {
        if (this.renderType == null) {
            this.renderType = function.apply(this.atlasLocation);
        }
        return this.renderType;
    }
    
    public VertexConsumer buffer(final MultiBufferSource dqt, final Function<ResourceLocation, RenderType> function) {
        return this.sprite().wrap(dqt.getBuffer(this.renderType(function)));
    }
    
    @Override
    public boolean equals(final Object object) {
        if (this == object) {
            return true;
        }
        if (object == null || this.getClass() != object.getClass()) {
            return false;
        }
        final Material eby3 = (Material)object;
        return this.atlasLocation.equals(eby3.atlasLocation) && this.texture.equals(eby3.texture);
    }
    
    @Override
    public int hashCode() {
        return Objects.hash(this.atlasLocation, this.texture);
    }
    
    @Override
    public String toString() {
        return "Material{atlasLocation=" + this.atlasLocation + ", texture=" + this.texture + '}';
    }
}
