-
Notifications
You must be signed in to change notification settings - Fork 497
/
GuiAdvancedInterface.java
147 lines (117 loc) · 3.82 KB
/
GuiAdvancedInterface.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/**
* Copyright (c) 2011-2014, SpaceToad and the BuildCraft Team
* http://www.mod-buildcraft.com
*
* BuildCraft is distributed under the terms of the Minecraft Mod Public
* License 1.0, or MMPL. Please check the contents of the license located in
* http://www.mod-buildcraft.com/MMPL-1.0.txt
*/
package buildcraft.core.gui;
import java.util.ArrayList;
import org.lwjgl.opengl.GL11;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.entity.RenderItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public abstract class GuiAdvancedInterface extends GuiBuildCraft {
public ArrayList<AdvancedSlot> slots = new ArrayList<AdvancedSlot>();
public GuiAdvancedInterface(BuildCraftContainer container, IInventory inventory, ResourceLocation texture) {
super(container, inventory, texture);
}
public int getSlotIndexAtLocation(int i, int j) {
int x = i - guiLeft;
int y = j - guiTop;
for (int position = 0; position < slots.size(); ++position) {
AdvancedSlot s = slots.get(position);
if (s != null && x >= s.x && x <= s.x + 16 && y >= s.y && y <= s.y + 16) {
return position;
}
}
return -1;
}
public AdvancedSlot getSlotAtLocation(int i, int j) {
int id = getSlotIndexAtLocation(i, j);
if (id != -1) {
return slots.get(id);
} else {
return null;
}
}
protected void drawBackgroundSlots() {
RenderHelper.enableGUIStandardItemLighting();
GL11.glPushMatrix();
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
GL11.glEnable(32826 /* GL_RESCALE_NORMAL_EXT */);
int i1 = 240;
int k1 = 240;
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, i1 / 1.0F, k1 / 1.0F);
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
if (slots != null) {
for (AdvancedSlot slot : slots) {
if (slot != null) {
slot.drawSprite(guiLeft, guiTop);
}
}
}
GL11.glPopMatrix();
}
public void drawTooltipForSlotAt(int mouseX, int mouseY) {
AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
if (slot != null) {
slot.drawTooltip(this, mouseX, mouseY);
}
}
public void drawTooltip(String caption, int mouseX, int mouseY) {
if (caption.length() > 0) {
int i2 = mouseX - guiLeft;
int k2 = mouseY - guiTop;
drawCreativeTabHoveringText(caption, i2, k2);
RenderHelper.enableGUIStandardItemLighting();
}
}
public static RenderItem getItemRenderer () {
return itemRender;
}
public int getXSize () {
return xSize;
}
public int getYSize () {
return ySize;
}
@Override
public void renderToolTip(ItemStack stack, int x, int y) {
super.renderToolTip(stack, x, y);
}
public void drawStack(ItemStack item, int x, int y) {
Minecraft mc = Minecraft.getMinecraft();
if (item != null) {
GL11.glEnable(GL11.GL_LIGHTING);
float prevZ = GuiAdvancedInterface.getItemRenderer().zLevel;
GuiAdvancedInterface.getItemRenderer().zLevel = 200F;
GuiAdvancedInterface.getItemRenderer().renderItemAndEffectIntoGUI(getFontRenderer(), mc.renderEngine, item, x, y);
GuiAdvancedInterface.getItemRenderer().renderItemOverlayIntoGUI(getFontRenderer(), mc.renderEngine, item, x, y);
GuiAdvancedInterface.getItemRenderer().zLevel = prevZ;
GL11.glDisable(GL11.GL_LIGHTING);
}
}
@Override
protected void mouseClicked(int mouseX, int mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
AdvancedSlot slot = getSlotAtLocation(mouseX, mouseY);
if (slot != null && slot.isDefined()) {
slotClicked(slot);
}
}
public void resetNullSlots(int size) {
slots.clear();
for (int i = 0; i < size; ++i) {
slots.add(null);
}
}
// TODO: Use this for all children of this class
protected void slotClicked(AdvancedSlot slot) {
}
}