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
|
package io.github.moulberry.notenoughupdates.miscgui;
import com.google.gson.JsonObject;
import io.github.moulberry.notenoughupdates.NEUManager;
import io.github.moulberry.notenoughupdates.util.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.input.Keyboard;
import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11;
import org.lwjgl.util.vector.Vector2f;
import java.awt.*;
import java.io.IOException;
import java.util.List;
public class GuiItemRecipe extends GuiScreen {
private static final ResourceLocation resourcePacksTexture = new ResourceLocation("textures/gui/resource_packs.png");
private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation("textures/gui/container/crafting_table.png");
private final List<ItemStack[]> craftMatrices;
private final List<JsonObject> results;
private int currentIndex = 0;
private final String title;
private final NEUManager manager;
public int guiLeft = 0;
public int guiTop = 0;
public int xSize = 176;
public int ySize = 166;
public GuiItemRecipe(String title, List<ItemStack[]> craftMatrices, List<JsonObject> results, NEUManager manager) {
this.craftMatrices = craftMatrices;
this.results = results;
this.manager = manager;
this.title = title;
}
private String getCraftText() {
if(results.get(currentIndex).has("crafttext")) {
return results.get(currentIndex).get("crafttext").getAsString();
} else {
return "";
}
}
@Override
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
drawDefaultBackground();
if(currentIndex < 0) {
currentIndex = 0;
} else if(currentIndex >= craftMatrices.size()) {
currentIndex = craftMatrices.size()-1;
}
FontRenderer fontRendererObj = Minecraft.getMinecraft().fontRendererObj;
this.guiLeft = (width - this.xSize) / 2;
this.guiTop = (height - this.ySize) / 2;
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(craftingTableGuiTextures);
this.drawTexturedModalRect(guiLeft, guiTop, 0, 0, this.xSize, this.ySize);
List<String> tooltipToRender = null;
for(int index=0; index <= 45; index++) {
Vector2f pos = getPositionForIndex(index);
Utils.drawItemStack(getStackForIndex(index), (int)pos.x, (int)pos.y);
if(mouseX > pos.x && mouseX < pos.x+16) {
if(mouseY > pos.y && mouseY < pos.y+16) {
ItemStack stack = getStackForIndex(index);
if(stack != null) {
tooltipToRender = stack.getTooltip(Minecraft.getMinecraft().thePlayer, false);
}
}
}
}
if(craftMatrices.size() > 1) {
int guiX = mouseX - guiLeft;
int guiY = mouseY - guiTop;
int buttonWidth = 7;
int buttonHeight = 11;
boolean leftSelected = false;
boolean rightSelected = false;
if(guiY > + 63 && guiY < + 63 + buttonHeight) {
if(guiX > + 110 && guiX < 110 + buttonWidth) {
leftSelected = true;
} else if(guiX > 147 && guiX < 147 + buttonWidth) {
rightSelected = true;
}
}
Minecraft.getMinecraft().getTextureManager().bindTexture(resourcePacksTexture);
//Left arrow
Utils.drawTexturedRect(guiLeft+110, guiTop+63, 7, 11, 34/256f, 48/256f,
5/256f + (leftSelected ? 32/256f : 0), 27/256f + (leftSelected ? 32/256f : 0));
//Right arrow
Utils.drawTexturedRect(guiLeft+147, guiTop+63, 7, 11, 10/256f, 24/256f,
5/256f + (rightSelected ? 32/256f : 0), 27/256f + (rightSelected ? 32/256f : 0));
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
String str = (currentIndex+1)+"/"+craftMatrices.size();
Utils.drawStringCenteredScaledMaxWidth(str, fontRendererObj, guiLeft+132, guiTop+69,
false, 24, Color.BLACK.getRGB());
}
Utils.drawStringCenteredScaledMaxWidth(getCraftText(), fontRendererObj, guiLeft+132, guiTop+25,
false, 75, 4210752);
Utils.drawStringScaledMaxWidth(title, fontRendererObj, guiLeft+28, guiTop+6, title.contains("\u00a7"), xSize-38, 4210752);
if(tooltipToRender != null) {
Utils.drawHoveringText(tooltipToRender, mouseX, mouseY, width, height, -1, fontRendererObj);
}
}
public ItemStack getStackForIndex(int index) {
if(index == 0) {
return manager.jsonToStack(results.get(currentIndex));
} else if(index >= 1 && index <= 9) {
return craftMatrices.get(currentIndex)[index-1];
} else {
return Minecraft.getMinecraft().thePlayer.inventory.getStackInSlot(index-10);
}
}
public Vector2f getPositionForIndex(int index) {
//0 = result
//1-9 = craft matrix
//10-18 = hotbar
//19-45 = player inv
if(index == 0) {
return new Vector2f(guiLeft+124, guiTop+35);
} else if(index >= 1 && index <= 9) {
index -= 1;
int x = index % 3;
int y = index / 3;
return new Vector2f(guiLeft+30 + x*18, guiTop+17 + y * 18);
} else if(index >= 10 && index <= 18) {
index -= 10;
return new Vector2f(guiLeft+8 + index*18, guiTop+142);
} else if(index >= 19 && index <= 45) {
index -= 19;
int x = index % 9;
int y = index / 9;
return new Vector2f(guiLeft+8 + x*18, guiTop+84 + y*18);
}
return null;
}
@Override
public void handleKeyboardInput() throws IOException {
super.handleKeyboardInput();
if(!Keyboard.getEventKeyState()) return;
ScaledResolution scaledResolution = new ScaledResolution(Minecraft.getMinecraft());
int width = scaledResolution.getScaledWidth();
int height = scaledResolution.getScaledHeight();
int mouseX = Mouse.getX() * width / Minecraft.getMinecraft().displayWidth;
int mouseY = height - Mouse.getY() * height / Minecraft.getMinecraft().displayHeight - 1;
int keyPressed = Keyboard.getEventKey() == 0 ? Keyboard.getEventCharacter()+256 : Keyboard.getEventKey();
for(int index=0; index <= 45; index++)
|