package net.minecraft.client.gui;

import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import com.mojang.blaze3d.vertex.BufferBuilder;
import com.mojang.blaze3d.vertex.BufferUploader;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.Tesselator;
import com.mojang.math.Matrix4f;
import com.mojang.math.Transformation;
import net.minecraft.resources.ResourceLocation;

public abstract class GuiComponent {
    public static final ResourceLocation BACKGROUND_LOCATION;
    public static final ResourceLocation STATS_ICON_LOCATION;
    public static final ResourceLocation GUI_ICONS_LOCATION;
    private int blitOffset;
    
    protected void hLine(int integer1, int integer2, final int integer3, final int integer4) {
        if (integer2 < integer1) {
            final int integer5 = integer1;
            integer1 = integer2;
            integer2 = integer5;
        }
        fill(integer1, integer3, integer2 + 1, integer3 + 1, integer4);
    }
    
    protected void vLine(final int integer1, int integer2, int integer3, final int integer4) {
        if (integer3 < integer2) {
            final int integer5 = integer2;
            integer2 = integer3;
            integer3 = integer5;
        }
        fill(integer1, integer2 + 1, integer1 + 1, integer3, integer4);
    }
    
    public static void fill(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5) {
        fill(Transformation.identity().getMatrix(), integer1, integer2, integer3, integer4, integer5);
    }
    
    public static void fill(final Matrix4f b, int integer2, int integer3, int integer4, int integer5, final int integer6) {
        if (integer2 < integer4) {
            final int integer7 = integer2;
            integer2 = integer4;
            integer4 = integer7;
        }
        if (integer3 < integer5) {
            final int integer7 = integer3;
            integer3 = integer5;
            integer5 = integer7;
        }
        final float float7 = (integer6 >> 24 & 0xFF) / 255.0f;
        final float float8 = (integer6 >> 16 & 0xFF) / 255.0f;
        final float float9 = (integer6 >> 8 & 0xFF) / 255.0f;
        final float float10 = (integer6 & 0xFF) / 255.0f;
        final BufferBuilder cyg11 = Tesselator.getInstance().getBuilder();
        RenderSystem.enableBlend();
        RenderSystem.disableTexture();
        RenderSystem.defaultBlendFunc();
        cyg11.begin(7, DefaultVertexFormat.POSITION_COLOR);
        cyg11.vertex(b, (float)integer2, (float)integer5, 0.0f).color(float8, float9, float10, float7).endVertex();
        cyg11.vertex(b, (float)integer4, (float)integer5, 0.0f).color(float8, float9, float10, float7).endVertex();
        cyg11.vertex(b, (float)integer4, (float)integer3, 0.0f).color(float8, float9, float10, float7).endVertex();
        cyg11.vertex(b, (float)integer2, (float)integer3, 0.0f).color(float8, float9, float10, float7).endVertex();
        cyg11.end();
        BufferUploader.end(cyg11);
        RenderSystem.enableTexture();
        RenderSystem.disableBlend();
    }
    
    protected void fillGradient(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
        final float float8 = (integer5 >> 24 & 0xFF) / 255.0f;
        final float float9 = (integer5 >> 16 & 0xFF) / 255.0f;
        final float float10 = (integer5 >> 8 & 0xFF) / 255.0f;
        final float float11 = (integer5 & 0xFF) / 255.0f;
        final float float12 = (integer6 >> 24 & 0xFF) / 255.0f;
        final float float13 = (integer6 >> 16 & 0xFF) / 255.0f;
        final float float14 = (integer6 >> 8 & 0xFF) / 255.0f;
        final float float15 = (integer6 & 0xFF) / 255.0f;
        RenderSystem.disableTexture();
        RenderSystem.enableBlend();
        RenderSystem.disableAlphaTest();
        RenderSystem.defaultBlendFunc();
        RenderSystem.shadeModel(7425);
        final Tesselator cym16 = Tesselator.getInstance();
        final BufferBuilder cyg17 = cym16.getBuilder();
        cyg17.begin(7, DefaultVertexFormat.POSITION_COLOR);
        cyg17.vertex(integer3, integer2, this.blitOffset).color(float9, float10, float11, float8).endVertex();
        cyg17.vertex(integer1, integer2, this.blitOffset).color(float9, float10, float11, float8).endVertex();
        cyg17.vertex(integer1, integer4, this.blitOffset).color(float13, float14, float15, float12).endVertex();
        cyg17.vertex(integer3, integer4, this.blitOffset).color(float13, float14, float15, float12).endVertex();
        cym16.end();
        RenderSystem.shadeModel(7424);
        RenderSystem.disableBlend();
        RenderSystem.enableAlphaTest();
        RenderSystem.enableTexture();
    }
    
    public void drawCenteredString(final Font dch, final String string, final int integer3, final int integer4, final int integer5) {
        dch.drawShadow(string, (float)(integer3 - dch.width(string) / 2), (float)integer4, integer5);
    }
    
    public void drawRightAlignedString(final Font dch, final String string, final int integer3, final int integer4, final int integer5) {
        dch.drawShadow(string, (float)(integer3 - dch.width(string)), (float)integer4, integer5);
    }
    
    public void drawString(final Font dch, final String string, final int integer3, final int integer4, final int integer5) {
        dch.drawShadow(string, (float)integer3, (float)integer4, integer5);
    }
    
    public static void blit(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final TextureAtlasSprite eaj) {
        innerBlit(integer1, integer1 + integer4, integer2, integer2 + integer5, integer3, eaj.getU0(), eaj.getU1(), eaj.getV0(), eaj.getV1());
    }
    
    public void blit(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6) {
        blit(integer1, integer2, this.blitOffset, (float)integer3, (float)integer4, integer5, integer6, 256, 256);
    }
    
    public static void blit(final int integer1, final int integer2, final int integer3, final float float4, final float float5, final int integer6, final int integer7, final int integer8, final int integer9) {
        innerBlit(integer1, integer1 + integer6, integer2, integer2 + integer7, integer3, integer6, integer7, float4, float5, integer9, integer8);
    }
    
    public static void blit(final int integer1, final int integer2, final int integer3, final int integer4, final float float5, final float float6, final int integer7, final int integer8, final int integer9, final int integer10) {
        innerBlit(integer1, integer1 + integer3, integer2, integer2 + integer4, 0, integer7, integer8, float5, float6, integer9, integer10);
    }
    
    public static void blit(final int integer1, final int integer2, final float float3, final float float4, final int integer5, final int integer6, final int integer7, final int integer8) {
        blit(integer1, integer2, integer5, integer6, float3, float4, integer5, integer6, integer7, integer8);
    }
    
    private static void innerBlit(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final int integer6, final int integer7, final float float8, final float float9, final int integer10, final int integer11) {
        innerBlit(integer1, integer2, integer3, integer4, integer5, (float8 + 0.0f) / integer10, (float8 + integer6) / integer10, (float9 + 0.0f) / integer11, (float9 + integer7) / integer11);
    }
    
    protected static void innerBlit(final int integer1, final int integer2, final int integer3, final int integer4, final int integer5, final float float6, final float float7, final float float8, final float float9) {
        final BufferBuilder cyg10 = Tesselator.getInstance().getBuilder();
        cyg10.begin(7, DefaultVertexFormat.POSITION_TEX);
        cyg10.vertex(integer1, integer4, integer5).uv(float6, float9).endVertex();
        cyg10.vertex(integer2, integer4, integer5).uv(float7, float9).endVertex();
        cyg10.vertex(integer2, integer3, integer5).uv(float7, float8).endVertex();
        cyg10.vertex(integer1, integer3, integer5).uv(float6, float8).endVertex();
        cyg10.end();
        RenderSystem.enableAlphaTest();
        BufferUploader.end(cyg10);
    }
    
    public int getBlitOffset() {
        return this.blitOffset;
    }
    
    public void setBlitOffset(final int integer) {
        this.blitOffset = integer;
    }
    
    static {
        BACKGROUND_LOCATION = new ResourceLocation("textures/gui/options_background.png");
        STATS_ICON_LOCATION = new ResourceLocation("textures/gui/container/stats_icons.png");
        GUI_ICONS_LOCATION = new ResourceLocation("textures/gui/icons.png");
    }
}
