2015-12-04 18:14:03 +01:00
|
|
|
/*
|
2016-05-16 22:52:27 +02:00
|
|
|
* This file ("TexturedButton.java") is part of the Actually Additions mod for Minecraft.
|
2015-12-04 18:14:03 +01:00
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
* under the Actually Additions License to be found at
|
2016-05-16 22:52:27 +02:00
|
|
|
* http://ellpeck.de/actaddlicense
|
2015-12-04 18:14:03 +01:00
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
*
|
2017-01-01 16:23:26 +01:00
|
|
|
* © 2015-2017 Ellpeck
|
2015-12-04 18:14:03 +01:00
|
|
|
*/
|
|
|
|
|
2016-11-10 19:50:01 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.inventory.gui;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2021-02-27 22:59:18 +01:00
|
|
|
import com.mojang.blaze3d.platform.GlStateManager;
|
2021-03-01 20:55:50 +01:00
|
|
|
import com.mojang.blaze3d.systems.RenderSystem;
|
2015-12-04 18:14:03 +01:00
|
|
|
import net.minecraft.client.Minecraft;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.client.gui.GuiGraphics;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.client.gui.components.Button;
|
2024-03-03 01:20:53 +01:00
|
|
|
import net.minecraft.network.chat.Component;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.resources.ResourceLocation;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.api.distmarker.Dist;
|
|
|
|
import net.neoforged.api.distmarker.OnlyIn;
|
2021-02-26 22:15:48 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
2021-04-19 21:20:23 +02:00
|
|
|
import java.util.stream.Collectors;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2021-02-26 22:15:48 +01:00
|
|
|
@OnlyIn(Dist.CLIENT)
|
2021-02-27 22:59:18 +01:00
|
|
|
public class TexturedButton extends Button {
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2019-02-27 19:53:05 +01:00
|
|
|
public final List<String> textList = new ArrayList<>();
|
2016-11-16 20:31:16 +01:00
|
|
|
private final ResourceLocation resLoc;
|
2015-12-04 18:14:03 +01:00
|
|
|
public int texturePosX;
|
|
|
|
public int texturePosY;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, OnPress pressable) {
|
2021-04-19 21:20:23 +02:00
|
|
|
this(resLoc, x, y, texturePosX, texturePosY, width, height, new ArrayList<>(), pressable);
|
2015-12-19 10:30:39 +01:00
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public TexturedButton(ResourceLocation resLoc, int x, int y, int texturePosX, int texturePosY, int width, int height, List<String> hoverTextList, OnPress pressable) {
|
2024-03-03 01:20:53 +01:00
|
|
|
super(x, y, width, height, Component.empty(), pressable, DEFAULT_NARRATION);
|
2015-12-04 18:14:03 +01:00
|
|
|
this.texturePosX = texturePosX;
|
|
|
|
this.texturePosY = texturePosY;
|
2016-11-10 19:50:01 +01:00
|
|
|
this.resLoc = resLoc;
|
2015-12-04 18:14:03 +01:00
|
|
|
this.textList.addAll(hoverTextList);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-04 21:54:00 +01:00
|
|
|
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
|
2021-04-19 21:20:23 +02:00
|
|
|
? 1
|
|
|
|
: 0;
|
2015-12-04 18:14:03 +01:00
|
|
|
|
2024-03-04 21:54:00 +01:00
|
|
|
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);
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|
2016-11-12 15:09:30 +01:00
|
|
|
|
2024-03-03 01:20:53 +01:00
|
|
|
public void drawHover(GuiGraphics guiGraphics, int x, int y) {
|
2021-04-19 21:20:23 +02:00
|
|
|
if (this.isMouseOver(x, y)) {
|
2021-02-26 22:15:48 +01:00
|
|
|
Minecraft mc = Minecraft.getInstance();
|
2024-03-12 16:35:56 +01:00
|
|
|
guiGraphics.renderComponentTooltip(mc.font, this.textList.stream().map(Component::literal).collect(Collectors.toList()), x, y);
|
2016-11-12 15:09:30 +01:00
|
|
|
}
|
|
|
|
}
|
2015-12-04 18:14:03 +01:00
|
|
|
}
|