package info.u_team.u_team_core.gui.elements;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.Matrix4f;
import net.minecraft.util.math.MathHelper;
import net.minecraftforge.fml.client.gui.GuiUtils;
import net.minecraftforge.fml.client.gui.widget.Slider;

public class BetterFontSlider extends Slider {
	
	protected float scale;
	
	public BetterFontSlider(int xPos, int yPos, int width, int height, String prefix, String suf, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, float scale, ISlider par) {
		super(xPos, yPos, width, height, prefix, suf, minVal, maxVal, currentVal, showDec, drawStr, slider -> {
		}, par);
		this.scale = scale;
	}
	
	@Override
	protected void renderBg(Minecraft minecraft, int x, int y) {
		if (visible) {
			if (dragging) {
				sliderValue = (x - (this.x + 4)) / (float) (this.width - 8);
				updateSlider();
			}
			GuiUtils.drawContinuousTexturedBox(WIDGETS_LOCATION, this.x + (int) (this.sliderValue * (this.width - 8)), this.y, 0, 66 + (isHovered() ? 20 : 0), 8, this.height, 200, 20, 2, 3, 2, 2, this.getBlitOffset());
		}
	}
	
	@Override
	public void renderButton(int mouseX, int mouseY, float partial) {
		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 = MathHelper.ceil(scale * fontRenderer.getStringWidth(message));
		final int ellipsisWidth = MathHelper.ceil(scale * fontRenderer.getStringWidth("..."));
		
		if (messageWidth > width - 6 && messageWidth > ellipsisWidth) {
			message = fontRenderer.trimStringToWidth(message, width - 6 - ellipsisWidth).trim() + "...";
		}
		
		final float positionFactor = 1 / scale;
		
		final float xStart = (x + (width / 2) - messageWidth / 2) * positionFactor;
		final float yStart = (y + ((int) (height - 8 * scale)) / 2) * positionFactor;
		
		fontRenderer.renderString(message, xStart, yStart, getFGColor(), Matrix4f.makeScale(scale, scale, 0), true);
	}
}

package info.u_team.u_team_core.gui.elements;

import com.mojang.blaze3d.matrix.MatrixStack;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.vector.Matrix4f;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.client.gui.GuiUtils;
import net.minecraftforge.fml.client.gui.widget.Slider;

public class BetterFontSlider extends Slider {
	
	protected float scale;
	
	public BetterFontSlider(int xPos, int yPos, int width, int height, ITextComponent prefix, ITextComponent suffix, double minVal, double maxVal, double currentVal, boolean showDec, boolean drawStr, float scale, ISlider par) {
		super(xPos, yPos, width, height, prefix, suffix, minVal, maxVal, currentVal, showDec, drawStr, slider -> {
		}, par);
		this.scale = scale;
	}
	
	@Override
	protected void func_230441_a_(MatrixStack matrixStack, Minecraft minecraft, int x, int y) {
		if (field_230694_p_) {
			if (dragging) {
				sliderValue = (x - (field_230690_l_ + 4)) / (float) (field_230688_j_ - 8);
				updateSlider();
			}
			GuiUtils.drawContinuousTexturedBox(field_230687_i_, field_230690_l_ + (int) (sliderValue * (field_230688_j_ - 8)), field_230691_m_, 0, 66 + (func_230449_g_() ? 20 : 0), 8, field_230689_k_, 200, 20, 2, 3, 2, 2, func_230927_p_());
		}
	}
	
	@Override
	public void func_230431_b_(MatrixStack matrixStack, int mouseX, int mouseY, float partial) {
		final Minecraft minecraft = Minecraft.getInstance();
		final FontRenderer fontRenderer = minecraft.fontRenderer;
		
		String message = func_230458_i_().getString();
		
		GuiUtils.drawContinuousTexturedBox(field_230687_i_, field_230690_l_, field_230691_m_, 0, 46 + func_230989_a_(func_230449_g_()) * 20, field_230688_j_, field_230689_k_, 200, 20, 2, 3, 2, 2, 0);
		func_230441_a_(matrixStack, minecraft, mouseX, mouseY);
		
		final int messageWidth = MathHelper.ceil(scale * fontRenderer.getStringWidth(message));
		final int ellipsisWidth = MathHelper.ceil(scale * fontRenderer.getStringWidth("..."));
		
		if (messageWidth > field_230688_j_ - 6 && messageWidth > ellipsisWidth) {
			message = fontRenderer.func_238412_a_(message, field_230688_j_ - 6 - ellipsisWidth).trim() + "...";
		}
		
		final float positionFactor = 1 / scale;
		
		final float xStart = (field_230690_l_ + (field_230688_j_ / 2) - messageWidth / 2) * positionFactor;
		final float yStart = (field_230691_m_ + ((int) (field_230689_k_ - 8 * scale)) / 2) * positionFactor;
		
		fontRenderer.renderString(message, xStart, yStart, getFGColor(), Matrix4f.makeScale(scale, scale, 0), true, false);
	}
}

Fix better font slider