ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/TexturedButton.java
2024-03-12 16:35:56 +01:00

68 lines
2.7 KiB
Java

/*
* This file ("TexturedButton.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2017 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.api.distmarker.OnlyIn;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
@OnlyIn(Dist.CLIENT)
public class TexturedButton extends Button {
public final List<String> textList = new ArrayList<>();
private final ResourceLocation resLoc;
public int texturePosX;
public int texturePosY;
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, OnPress pressable) {
this(resLoc, x, y, texturePosX, texturePosY, width, height, new ArrayList<>(), pressable);
}
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, List<String> hoverTextList, OnPress pressable) {
super(x, y, width, height, Component.empty(), pressable, DEFAULT_NARRATION);
this.texturePosX = texturePosX;
this.texturePosY = texturePosY;
this.resLoc = resLoc;
this.textList.addAll(hoverTextList);
}
@Override
public void renderWidget(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
int k = this.isHovered
? 1
: 0;
GlStateManager._enableBlend();
GlStateManager._blendFuncSeparate(770, 771, 1, 0);
GlStateManager._blendFunc(770, 771);
guiGraphics.blit(this.resLoc, this.getX(), this.getY(), this.texturePosX, this.texturePosY - this.height + k * this.height, this.width, this.height);
// this.mouseDragged(minecraft, x, y);
}
public void drawHover(GuiGraphics guiGraphics, int x, int y) {
if (this.isMouseOver(x, y)) {
Minecraft mc = Minecraft.getInstance();
guiGraphics.renderComponentTooltip(mc.font, this.textList.stream().map(Component::literal).collect(Collectors.toList()), x, y);
}
}
}