package info.u_team.u_team_core.gui.elements;

import com.mojang.blaze3d.vertex.PoseStack;

import info.u_team.u_team_core.util.GuiUtil;
import info.u_team.u_team_core.util.RenderUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TextComponent;
import net.minecraft.resources.ResourceLocation;

public class CheckboxButton extends UButton {
	
	protected static final ResourceLocation TEXTURE = new ResourceLocation("textures/gui/checkbox.png");
	
	protected boolean checked;
	
	protected boolean drawText;
	protected boolean leftSideText;
	protected boolean dropShadow;
	
	public CheckboxButton(int x, int y, int width, int height, Component text, boolean checked, boolean drawText) {
		this(x, y, width, height, text, checked, drawText, EMTPY_PRESSABLE);
	}
	
	public CheckboxButton(int x, int y, int width, int height, Component text, boolean checked, boolean drawText, OnPress pessable) {
		this(x, y, width, height, text, checked, drawText, pessable, EMPTY_TOOLTIP);
	}
	
	public CheckboxButton(int x, int y, int width, int height, Component text, boolean checked, boolean drawText, OnTooltip tooltip) {
		this(x, y, width, height, text, checked, drawText, EMTPY_PRESSABLE, tooltip);
	}
	
	public CheckboxButton(int x, int y, int width, int height, Component text, boolean checked, boolean drawText, OnPress pessable, OnTooltip tooltip) {
		super(x, y, width, height, text, pessable, tooltip);
		this.checked = checked;
		this.drawText = drawText;
		leftSideText = false;
		dropShadow = false;
	}
	
	public boolean isChecked() {
		return checked;
	}
	
	public void setChecked(boolean checked) {
		this.checked = checked;
	}
	
	public boolean isDrawText() {
		return drawText;
	}
	
	public void setDrawText(boolean drawText) {
		this.drawText = drawText;
	}
	
	public boolean isLeftSideText() {
		return leftSideText;
	}
	
	public void setLeftSideText(boolean leftSideText) {
		this.leftSideText = leftSideText;
	}
	
	public void toggle() {
		checked = !checked;
	}
	
	@Override
	public void onPress() {
		toggle();
		super.onPress();
	}
	
	@Override
	public void renderButton(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) {
		final var minecraft = Minecraft.getInstance();
		
		minecraft.getTextureManager().bindForSetup(TEXTURE);
		
		RenderUtil.enableBlend();
		RenderUtil.defaultBlendFunc();
		GuiUtil.drawTexturedColoredQuad(matrixStack, x, y, width, height, 20, 20, isHovered() ? 20 : 0, checked ? 20 : 0, 64, 64, 0, getCurrentBackgroundColor(matrixStack, mouseX, mouseY, partialTicks));
		RenderUtil.disableBlend();
		
		renderBackground(matrixStack, minecraft, mouseX, mouseY, partialTicks);
		renderForeground(matrixStack, minecraft, mouseX, mouseY, partialTicks);
	}
	
	@Override
	public void renderForeground(PoseStack matrixStack, Minecraft minecraft, int mouseX, int mouseY, float partialTicks) {
		if (drawText) {
			final var fontRenderer = minecraft.font;
			
			final var message = getCurrentText();
			if (message != TextComponent.EMPTY) {
				final float xStart;
				final float yStart = y + (height - 8) / 2;
				
				if (leftSideText) {
					xStart = x - (fontRenderer.width(message) + 4);
				} else {
					xStart = x + width + 4;
				}
				
				final var color = getCurrentTextColor(matrixStack, mouseX, mouseY, partialTicks).getColorARGB();
				
				if (dropShadow) {
					fontRenderer.drawShadow(matrixStack, getCurrentText(), xStart, yStart, color);
				} else {
					fontRenderer.draw(matrixStack, getCurrentText(), xStart, yStart, color);
				}
			}
		}
	}
}

@@ -40,16 +40,64 @@
 ments;%0A%0A
+import com.mojang.blaze3d.systems.RenderSystem;%0A
 import c
@@ -189,47 +189,38 @@
 ort 
-info.u_team.u_team_core.util.RenderUtil
+net.minecraft.client.Minecraft
 ;%0Aim
@@ -241,33 +241,45 @@
 raft.client.
-Minecraft
+renderer.GameRenderer
 ;%0Aimport net
@@ -2324,58 +2324,153 @@
 %09%0A%09%09
-minecraft.getTextureManager().bindForSetup(TEXTURE
+RenderSystem.setShader(GameRenderer::getPositionTexShader);%0A%09%09RenderSystem.setShaderTexture(0, TEXTURE);%0A%09%09RenderSystem.setShaderColor(1, 1, 1, 1
 );%0A%09
@@ -2479,20 +2479,22 @@
 %09%09Render
-Util
+System
 .enableB
@@ -2509,20 +2509,22 @@
 %09%09Render
-Util
+System
 .default
@@ -2536,16 +2536,19 @@
 Func();%0A
+%09%09%0A
 %09%09GuiUti
@@ -2737,24 +2737,27 @@
 icks));%0A
+%09%09%0A
 %09%09Render
 Util.dis
@@ -2748,20 +2748,22 @@
 %09%09Render
-Util
+System
 .disable

Fix checkbox