package info.u_team.u_team_core.gui.elements;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.widget.button.Button;
import net.minecraftforge.fml.client.gui.GuiUtils;

/**
 * A button that fixes vanilla not drawing the continuous border if the button is smaller than 20 The code is adapted
 * from the 1.13.2 GuiButtonExt.
 * 
 * @author HyCraftHD
 */
public class UButton extends Button {
	
	protected static IPressable EMTPY_PRESSABLE = button -> {
	};
	
	public UButton(int x, int y, int width, int height, String displayString) {
		super(x, y, width, height, displayString, EMTPY_PRESSABLE);
	}
	
	public UButton(int x, int y, int width, int height, String displayString, IPressable pessable) {
		super(x, y, width, height, displayString, pessable);
	}
	
	public void setPressable(IPressable pressable) {
		onPress = pressable;
	}
	
	public void setPressable(Runnable runnable) {
		onPress = button -> runnable.run();
	}
	
	@Override
	public void renderButton(int mouseX, int mouseY, float partialTicks) {
		final Minecraft minecraft = Minecraft.getInstance();
		final FontRenderer fontRenderer = minecraft.fontRenderer;
		
		String message = getMessage();
		
		GuiUtils.drawContinuousTexturedBox(WIDGETS_LOCATION, x, y, 0, 46 + getYImage(isHovered()) * 20, width, height, 200, 20, 2, 3, 2, 2, 0);
		renderBg(minecraft, mouseX, mouseY);
		
		final int messageWidth = fontRenderer.getStringWidth(message);
		final int ellipsisWidth = fontRenderer.getStringWidth("...");
		
		if (messageWidth > width - 6 && messageWidth > ellipsisWidth) {
			message = fontRenderer.trimStringToWidth(message, width - 6 - ellipsisWidth).trim() + "...";
		}
		
		drawCenteredString(fontRenderer, message, x + width / 2, y + (height - 8) / 2, getFGColor());
	}
}

@@ -40,16 +40,63 @@
 ments;%0A%0A
+import com.mojang.blaze3d.matrix.MatrixStack;%0A%0A
 import n
@@ -226,16 +226,50 @@
 Button;%0A
+import net.minecraft.util.text.*;%0A
 import n
@@ -650,38 +650,46 @@
 int height, 
-String
+ITextComponent
  display
 String) %7B%0A%09%09
@@ -676,22 +676,16 @@
  display
-String
 ) %7B%0A%09%09su
@@ -716,22 +716,16 @@
  display
-String
 , EMTPY_
@@ -798,22 +798,30 @@
 ht, 
-String
+ITextComponent
  display
 Stri
@@ -816,22 +816,16 @@
  display
-String
 , IPress
@@ -877,22 +877,16 @@
  display
-String
 , pessab
@@ -947,23 +947,31 @@
 le) %7B%0A%09%09
-onPress
+field_230697_t_
  = press
@@ -1034,15 +1034,23 @@
 %7B%0A%09%09
-onPress
+field_230697_t_
  = b
@@ -1107,21 +1107,48 @@
 oid 
-renderButton(
+func_230431_b_(MatrixStack matrixStack, 
 int 
@@ -1330,18 +1330,34 @@
 e = 
-getMessage
+func_230458_i_().getString
 ();%0A
@@ -1400,82 +1400,138 @@
 Box(
-WIDGETS_LOCATION, x, y, 0, 46 + getYImage(isHovered()) * 20, width, height
+field_230687_i_, field_230690_l_, field_230691_m_, 0, 46 + func_230989_a_(func_230449_g_()) * 20, field_230688_j_, field_230689_k_
 , 20
@@ -1559,17 +1559,36 @@
 ;%0A%09%09
-renderBg(
+func_230441_a_(matrixStack, 
 mine
@@ -1767,21 +1767,31 @@
 Width %3E 
-width
+field_230688_j_
  - 6 && 
@@ -1852,40 +1852,47 @@
 rer.
-trimStringToWidth(message, width
+func_238412_a_(message, field_230688_j_
  - 6
@@ -1938,76 +1938,132 @@
 %09%0A%09%09
-drawCenteredString(fontRenderer, message, x + width / 2, y + (height
+func_238471_a_(matrixStack, fontRenderer, message, field_230690_l_ + field_230688_j_ / 2, field_230691_m_ + (field_230689_k_
  - 8

Fix ubutton