-
-
Notifications
You must be signed in to change notification settings - Fork 507
/
GuiSideHolder.java
78 lines (67 loc) · 3.18 KB
/
GuiSideHolder.java
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
package mekanism.client.gui.element;
import mekanism.client.SpecialColors;
import mekanism.client.gui.IGuiWrapper;
import mekanism.client.render.MekanismRenderer;
import mekanism.client.render.lib.ColorAtlas.ColorRegistryObject;
import mekanism.common.util.MekanismUtils;
import mekanism.common.util.MekanismUtils.ResourceType;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.resources.ResourceLocation;
import org.jetbrains.annotations.NotNull;
public abstract class GuiSideHolder extends GuiTexturedElement {
public static GuiSideHolder armorHolder(IGuiWrapper gui) {
return create(gui, -26, 62, 98, true, true, SpecialColors.TAB_ARMOR_SLOTS);
}
public static GuiSideHolder create(IGuiWrapper gui, int x, int y, int height, boolean left, boolean slotHolder, ColorRegistryObject tabColor) {
return new GuiSideHolder(gui, x, y, height, left, slotHolder) {
@Override
protected void colorTab(GuiGraphics guiGraphics) {
MekanismRenderer.color(guiGraphics, tabColor);
}
};
}
private static final ResourceLocation HOLDER_LEFT = MekanismUtils.getResource(ResourceType.GUI, "holder_left.png");
private static final ResourceLocation HOLDER_RIGHT = MekanismUtils.getResource(ResourceType.GUI, "holder_right.png");
private static final int TEXTURE_WIDTH = 26;
private static final int TEXTURE_HEIGHT = 9;
protected final boolean left;
private final boolean slotHolder;
protected GuiSideHolder(IGuiWrapper gui, int x, int y, int height, boolean left, boolean slotHolder) {
super(left ? HOLDER_LEFT : HOLDER_RIGHT, gui, x, y, TEXTURE_WIDTH, height);
this.left = left;
this.slotHolder = slotHolder;
active = false;
if (!this.slotHolder) {
setButtonBackground(ButtonBackground.DEFAULT);
}
}
protected abstract void colorTab(GuiGraphics guiGraphics);
@Override
public void renderWidget(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.renderWidget(guiGraphics, mouseX, mouseY, partialTicks);
if (this.slotHolder) {
//Slot holders need to draw here to render behind the slots instead of in front of them
draw(guiGraphics);
}
}
@Override
public void drawBackground(@NotNull GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) {
super.drawBackground(guiGraphics, mouseX, mouseY, partialTicks);
if (!this.slotHolder) {
draw(guiGraphics);
}
}
private void draw(@NotNull GuiGraphics guiGraphics) {
colorTab(guiGraphics);
//Top
guiGraphics.blit(getResource(), relativeX, relativeY, 0, 0, width, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT);
//Middle
int middleHeight = height - 8;
if (middleHeight > 0) {
guiGraphics.blit(getResource(), relativeX, relativeY + 4, width, middleHeight, 0, 4, width, 1, TEXTURE_WIDTH, TEXTURE_HEIGHT);
}
//Bottom
guiGraphics.blit(getResource(), relativeX, relativeY + 4 + middleHeight, 0, 5, width, 4, TEXTURE_WIDTH, TEXTURE_HEIGHT);
MekanismRenderer.resetColor(guiGraphics);
}
}