TurnBasedMinecraftMod/src/main/java/com/burnedkirby/TurnBasedMinecraft/client/ItemSelectionButton.java

38 lines
1.2 KiB
Java
Raw Normal View History

2019-11-25 06:29:25 +00:00
package com.burnedkirby.TurnBasedMinecraft.client;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
2020-11-12 08:10:01 +00:00
public class ItemSelectionButton extends Button {
2019-10-21 07:13:11 +00:00
private int itemStackID;
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, Button.OnPress onPress) {
super(x, y, widthIn, heightIn, Component.literal(buttonText), onPress);
this.itemStackID = itemStackID;
}
2020-11-12 08:10:01 +00:00
2019-10-21 07:13:11 +00:00
public int getID() {
2020-11-12 08:10:01 +00:00
return itemStackID;
}
@Override
public void renderButton(PoseStack poseStack, int mouseX, int mouseY, float partialTicks) {
2021-05-21 05:44:31 +00:00
if (visible) {
2020-11-12 08:10:01 +00:00
boolean hovered = mouseX >= getX() && mouseY >= getY() && mouseX < getX() + getWidth() && mouseY < getY() + getHeight();
if (hovered) {
fill(poseStack, getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x80FFFFFF);
2019-10-21 07:13:11 +00:00
} else {
fill(poseStack, getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x20707070);
}
}
}
2020-11-12 08:10:01 +00:00
private int getX() {
2021-05-21 05:44:31 +00:00
return x;
2020-11-12 08:10:01 +00:00
}
private int getY() {
2021-05-21 05:44:31 +00:00
return y;
2020-11-12 08:10:01 +00:00
}
2021-05-21 05:44:31 +00:00
}