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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
|
package darkknight.jewelrycraft.client.gui;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import darkknight.jewelrycraft.JewelrycraftMod;
import darkknight.jewelrycraft.client.gui.container.ContainerJewelryModifier;
import darkknight.jewelrycraft.network.PacketRequestSetSlot;
import darkknight.jewelrycraft.util.JewelryNBT;
import darkknight.jewelrycraft.util.JewelrycraftUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiButton;
import net.minecraft.client.gui.GuiTextField;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
public class GuiJewelryModifier extends GuiContainer {
private ResourceLocation texture;
private GuiTextField searchField, pages;
private int page =
1, maxPages = 1, selectedX = 0, selectedY = 0,
selectedPage = 0, enabled = 0;
private ItemStack selectedItem;
private ArrayList<
ItemStack> selectedItems =
new ArrayList<>();
private List<Map<Integer,
Map<Integer,
Integer>>> selectedItemsPos =
new ArrayList<>();
ContainerJewelryModifier jMod;
public GuiJewelryModifier(ContainerJewelryModifier containerJewelryTab,
ResourceLocation texture) {
super(containerJewelryTab);
xSize = 211;
ySize = 247;
jMod = containerJewelryTab;
this.maxPages = JewelrycraftUtil.objects.size() / 48 + 1;
this.texture = texture;
}
@Override
public void drawGuiContainerBackgroundLayer(float f, int mouseX,
int mouseY) {
GL11.glColor3f(1, 1, 1);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
int k = (this.width - this.xSize) / 2;
int l = (this.height - this.ySize) / 2;
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
if (selectedX != 0 && selectedY != 0 && page == selectedPage)
drawTexturedModalRect(k + selectedX, l + selectedY, 211, 0, 18,
18);
for (Map<Integer,
Map<Integer, Integer>> items : selectedItemsPos) {
for (Object itemPage : items.keySet()) {
if (page == (Integer) itemPage)
for (int x : items.get(itemPage).keySet())
drawTexturedModalRect(k + x,
l + items.get(itemPage).get(x), 211, 0, 18,
18);
}
}
this.searchField.drawTextBox();
this.pages.drawTextBox();
}
@Override
public void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
int i = 0;
for (ItemStack item : JewelrycraftUtil.objects) {
if (item != null && item.getItem() != null
&& (this.searchField.getText() == ""
|| item.getDisplayName().toLowerCase()
.contains(this.searchField.getText()
.toLowerCase()))) {
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glColor3f(1F, 1F, 1F);
GL11.glEnable(GL11.GL_LIGHTING);
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
if (i >= (page - 1) * 48 && i < page * 48)
try {
itemRender.renderItemAndEffectIntoGUI(
this.fontRendererObj,
this.mc.getTextureManager(), item,
88 + 20 * (i % 6),
7 + 17 * (i / 6) - 136 * (page - 1));
} catch (Exception e) {
JewelrycraftMod.logger
.info("Trying to display an item but gets this error: "
+ e.getMessage()
+ "\nThe item causing the issue is: "
+ item);
}
GL11.glDisable(GL11.GL_LIGHTING);
i++;
}
}
}
@Override
protected void keyTyped(char character, int key) {
if (this.searchField.textboxKeyTyped(character, key)) {
int items = 0;
for (ItemStack item : JewelrycraftUtil.objects)
if (item != null && searchField != null
&& searchField.getText() != ""
&& item.getItem() != null
&& item.getDisplayName().toLowerCase().contains(
this.searchField.getText().toLowerCase()))
items++;
maxPages = items / 48 + 1;
page = 1;
this.pages.setText(page + "/" + maxPages);
} else
super.keyTyped(character, key);
}
@Override
protected void mouseClicked(int x, int y, int id) {
super.mouseClicked(x, y, id);
if (x >= this.searchField.xPosition
&& x <= this.searchField.xPosition + this.searchField.width
&& y >= this.searchField.yPosition
&& y <= this.searchField.yPosition
+ this.searchField.height) {
this.searchField.setText("");
this.searchField.setFocused(true);
maxPages = JewelrycraftUtil.objects.size() / 48 + 1;
} else
this.searchField.setFocused(false);
for (Object button : this.buttonList) {
if (((GuiButton) button).id < 4
&& ((GuiButton) button).mousePressed(mc, x, y)) {
if (((GuiButton) button).id != 3) {
this.selectedItems.removeAll(selectedItems);
this.selectedItemsPos.removeAll(selectedItemsPos);
} else {
this.selectedX = 0;
this.selectedY = 0;
this.selectedItem = null;
}
((GuiButton) buttonList.get(0)).enabled = true;
((GuiButton) buttonList.get(1)).enabled = true;
((GuiButton) buttonList.get(2)).enabled = true;
((GuiButton) buttonList.get(3)).enabled = true;
((GuiButton) button).enabled = false;
enabled = ((GuiButton) button).id;
}
}
int i = 0;
for (ItemStack item : JewelrycraftUtil.objects) {
if (item != null && item.getItem() != null
&& (this.searchField.getText() == ""
|| item.getDisplayName().toLowerCase()
.contains(this.searchField.getText()
.toLowerCase()))) {
if (i >= (page - 1) * 48 && i < page * 48
&& x >= this.guiLeft + 88 + 20 * (i % 6)
&& x < this.guiLeft + 108 + 20 * (i % 6)
&& y >= this.guiTop + 9 + 17 * (i / 6)
- 136 * (page - 1)
&& y < this.guiTop + 25 + 17 * (i / 6)
- 136 * (page - 1)) {
try {
if (!((GuiButton) buttonList.get(0)).enabled
|| !((GuiButton) buttonList.get(1)).enabled
|| !((GuiButton) buttonList
.get(2)).enabled) {
this.selectedItem = item;
this.selectedX = 87 + 20 * (i % 6);
this.selectedY =
6 + 17 * (i / 6) - 136 * (page - 1);
this.selectedPage = page;
} else if (!((GuiButton) buttonList
.get(3)).enabled) {
Map<Integer, Map<Integer, Integer>> itemPage =
new HashMap<>();
Map<Integer, Integer> pos = new HashMap<>();
pos.put(87 + 20 * (i % 6),
6 + 17 * (i / 6) - 136 * (page - 1));
itemPage.put(page, pos);
if (!this.selectedItems.contains(item)) {
this.selectedItems.add(item);
this.selectedItemsPos.add(itemPage);
} else {
this.selectedItems.remove(item);
this.selectedItemsPos.remove(itemPage);
}
}
} catch (Exception e) {
JewelrycraftMod.logger
.info("Trying to display an item but gets this error: "
+ e.getMessage()
+ "\nThe item causing the issue is: "
+ item);
}
}
i++;
}
}
if (((GuiButton) buttonList.get(5)).mousePressed(mc, x, y)
&& page > 1)
page--;
if (((GuiButton) buttonList.get(6)).mousePressed(mc, x, y)
&& page < maxPages)
page++;
if (jMod.modInv.getStackInSlot(36) != null) {
ItemStack targetItem = jMod.modInv.getStackInSlot(36).copy();
if (((GuiButton) buttonList.get(4)).mousePressed(mc, x, y)
&& !((GuiButton) buttonList.get(0)).enabled) {
JewelryNBT.addIngotColor(targetItem, 16777215);
JewelryNBT.addMetal(targetItem,
new ItemStack(Item.getItemById(0), 0, 0));
if (selectedItem != null)
JewelryNBT.addMetal(targetItem, this.selectedItem);
JewelrycraftMod.netWrapper.sendToServer(
new PacketRequestSetSlot(targetItem));
}
if (((GuiButton) buttonList.get(4)).mousePressed(mc, x, y)
&& !((GuiButton) buttonList.get(1)).enabled) {
JewelryNBT.addGemColor(targetItem, 16777215);
JewelryNBT.addGem(targetItem,
new ItemStack(Item.getItemById(0), 0, 0));
if (selectedItem != null)
JewelryNBT.addGem(targetItem, this.selectedItem);
JewelrycraftMod.netWrapper.sendToServer(
new PacketRequestSetSlot(targetItem));
}
if (((GuiButton) buttonList.get(4)).mousePressed(mc, x, y)
&& !((GuiButton) buttonList.get(2)).enabled) {
if (selectedItem != null)
JewelryNBT.addItem(targetItem, selectedItem);
JewelrycraftMod.netWrapper.sendToServer(
new PacketRequestSetSlot(targetItem));
}
if (((GuiButton) buttonList.get(4)).mousePressed(mc, x, y)
&& !((GuiButton) buttonList.get(3)).enabled) {
if (!selectedItems.isEmpty())
JewelryNBT.addModifiers(targetItem, selectedItems);
JewelrycraftMod.netWrapper.sendToServer(
new PacketRequestSetSlot(targetItem));
}
}
this.pages.setText(page + "/" + maxPages);
}
@Override
public void initGui() {
super.initGui();
this.searchField = new GuiTextField(this.fontRendererObj,
this.guiLeft + 89, this.guiTop + 148, 115,
this.fontRendererObj.FONT_HEIGHT + 3);
this.searchField.setMaxStringLength(15);
this.searchField.setTextColor(16777215);
this.searchField.setVisible(true);
this.searchField.setCanLoseFocus(true);
this.pages = new GuiTextField(this.fontRendererObj,
this.guiLeft + 20, this.guiTop + 146, 50,
this.fontRendererObj.FONT_HEIGHT + 3);
this.pages.setMaxStringLength(15);
this.pages.setTextColor(16777215);
this.pages.setVisible(true);
this.pages.setText(page + "/" + maxPages);
this.buttonList.add(new GuiButton(0, this.guiLeft + 17,
this.guiTop + 30, 52, 20, "Metal"));
this.buttonList.add(new GuiButton(1, this.guiLeft + 17,
this.guiTop + 52, 52, 20, "Gem"));
this.buttonList.add(new GuiButton(2, this.guiLeft + 17,
this.guiTop + 74, 52, 20, "Item"));
this.buttonList.add(new GuiButton(3, this.guiLeft + 17,
this.guiTop + 96, 52, 20, "Modifiers"));
this.buttonList.add(new GuiButton(4, this.guiLeft + 17,
this.guiTop + 118, 52, 20, "Add Items"));
this.buttonList.add(new GuiButton(5, this.guiLeft + 5,
this.guiTop + 142, 13, 20, "<<"));
this.buttonList.add(new GuiButton(6, this.guiLeft + 73,
this.guiTop + 142, 13, 20, ">>"));
((GuiButton) buttonList.get(enabled)).enabled = false;
}
@Override
public void drawScreen(int x, int y, float z) {
super.drawScreen(x, y, z);
int i = 0;
List<String> list = new ArrayList<>();
for (ItemStack item : JewelrycraftUtil.objects) {
if (item != null && item.getItem() != null
&& (this.searchField.getText() == ""
|| item.getDisplayName().toLowerCase()
.contains(this.searchField.getText()
.toLowerCase()))) {
if (i >= (page - 1) * 48 && i < page * 48
&& x >= this.guiLeft + 88 + 20 * (i % 6)
&& x < this.guiLeft + 108 + 20 * (i % 6)
&& y >= this.guiTop + 9 + 17 * (i / 6)
- 136 * (page - 1)
&& y < this.guiTop + 25 + 17 * (i / 6)
- 136 * (page - 1)) {
list.add(item.getDisplayName());
if (item.getTooltip(mc.thePlayer,
mc.gameSettings.advancedItemTooltips) != null)
this.renderToolTip(item, x, y);
else
this.drawHoveringText(list, x, y,
this.fontRendererObj);
}
i++;
}
}
}
}
|