1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
package me.xmrvizzy.skyblocker.skyblock.quicknav;
import com.mojang.blaze3d.systems.RenderSystem;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.narration.NarrationMessageBuilder;
import net.minecraft.client.gui.widget.ClickableWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.util.Identifier;
@Environment(value=EnvType.CLIENT)
public class QuickNavButton extends ClickableWidget {
private static final MinecraftClient CLIENT = MinecraftClient.getInstance();
private static final Identifier BUTTON_TEXTURE = new Identifier("textures/gui/container/creative_inventory/tabs.png");
@Override
public void appendNarrations(NarrationMessageBuilder builder) {
}
public enum Type {
TOP,
BOTTOM,
}
private final Type type;
private boolean toggled;
private int u;
private int v;
private final String command;
private final ItemStack icon;
public QuickNavButton(int x, int y, Type type, boolean toggled, String command, ItemStack icon) {
super(x, y, 28, 32, LiteralText.EMPTY);
this.type = type;
if (type == Type.BOTTOM) {
this.u = 28;
this.v = 64;
} else {
this.u = 28;
this.v = 0;
}
this.toggled = toggled;
if (toggled) this.v += 32;
this.command = command;
this.icon = icon;
}
@Override
public void onClick(double mouseX, double mouseY) {
if (!this.toggled) {
this.toggled = true;
this.v += 32;
CLIENT.player.sendChatMessage(command);
}
}
@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
RenderSystem.setShaderTexture(0, BUTTON_TEXTURE);
RenderSystem.disableDepthTest();
// render button background
if (!this.toggled) {
if (this.type == Type.BOTTOM)
this.drawTexture(matrices, this.x, this.y + 4, this.u, this.v + 4, this.width, this.height - 4);
else
this.drawTexture(matrices, this.x, this.y, this.u, this.v, this.width, this.height - 4);
} else this.drawTexture(matrices, this.x, this.y, this.u, this.v, this.width, this.height);
// render button icon
if (!this.toggled) {
if (this.type == Type.BOTTOM)
CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 6);
else
CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 9);
} else {
if (this.type == Type.BOTTOM)
CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 9);
else
CLIENT.getItemRenderer().renderInGui(this.icon,this.x + 6, this.y + 6);
}
RenderSystem.enableDepthTest();
}
}
|