package io.gitlab.jfronny.respackopts; import com.mojang.blaze3d.systems.RenderSystem; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.util.NarratorManager; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.text.Text; import net.minecraft.util.Identifier; public class TexturedButtonWidget extends ButtonWidget { private final Identifier texture; private final int u; private final int v; private final int uWidth; private final int vHeight; public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, int uWidth, int vHeight, PressAction onPress) { this(x, y, width, height, u, v, texture, uWidth, vHeight, onPress, NarratorManager.EMPTY); } public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, int uWidth, int vHeight, PressAction onPress, Text message) { this(x, y, width, height, u, v, texture, uWidth, vHeight, onPress, message, EMPTY); } public TexturedButtonWidget(int x, int y, int width, int height, int u, int v, Identifier texture, int uWidth, int vHeight, PressAction onPress, Text message, TooltipSupplier tooltipSupplier) { super(x, y, width, height, message, onPress, tooltipSupplier); this.uWidth = uWidth; this.vHeight = vHeight; this.u = u; this.v = v; this.texture = texture; } public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) { MinecraftClient client = MinecraftClient.getInstance(); client.getTextureManager().bindTexture(this.texture); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.disableDepthTest(); int adjustedV = this.v; if (!this.active) { adjustedV += this.height * 2; } else if (this.isHovered()) { adjustedV += this.height; } drawTexture(matrices, this.x, this.y, (float)this.u, (float)adjustedV, this.width, this.height, this.uWidth, this.vHeight); RenderSystem.enableDepthTest(); if (this.isHovered()) { this.renderToolTip(matrices, mouseX, mouseY); } } }