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

53 lines
1.6 KiB
Java
Raw Normal View History

2019-11-25 06:29:25 +00:00
package com.burnedkirby.TurnBasedMinecraft.client;
2020-11-12 08:10:01 +00:00
import com.mojang.blaze3d.matrix.MatrixStack;
2019-10-21 07:13:11 +00:00
import net.minecraft.client.gui.widget.button.Button;
2020-11-12 08:10:01 +00:00
import net.minecraft.util.text.StringTextComponent;
2020-11-12 08:10:01 +00:00
public class ItemSelectionButton extends Button {
2019-10-21 07:13:11 +00:00
private int itemStackID;
2019-10-21 07:13:11 +00:00
public ItemSelectionButton(int x, int y, int widthIn, int heightIn, String buttonText, int itemStackID, Button.IPressable onPress) {
2020-11-12 08:10:01 +00:00
super(x, y, widthIn, heightIn, new StringTextComponent(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
2020-11-12 08:10:01 +00:00
public void func_230430_a_(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
// field_230694_p_ is probably isVisible
if (field_230694_p_) {
boolean hovered = mouseX >= getX() && mouseY >= getY() && mouseX < getX() + getWidth() && mouseY < getY() + getHeight();
if (hovered) {
fill(matrixStack, getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x80FFFFFF);
2019-10-21 07:13:11 +00:00
} else {
2020-11-12 08:10:01 +00:00
fill(matrixStack, getX(), getY(), getX() + getWidth(), getY() + getHeight(), 0x20707070);
}
}
}
2020-11-12 08:10:01 +00:00
private int getX() {
return field_230690_l_;
}
private int getY() {
return field_230691_m_;
}
private int getWidth() {
return field_230688_j_;
}
private int getHeight() {
return field_230689_k_;
}
private void fill(MatrixStack matrixStack, int x, int y, int width, int height, int color) {
func_238467_a_(matrixStack, x, y, width, height, color);
}
}