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
|
package me.shedaniel.gui;
import me.shedaniel.api.IDisplayCategory;
import me.shedaniel.api.IRecipe;
import me.shedaniel.gui.widget.Button;
import me.shedaniel.gui.widget.Control;
import me.shedaniel.gui.widget.REISlot;
import me.shedaniel.gui.widget.Tab;
import me.shedaniel.impl.REIRecipeManager;
import net.minecraft.client.MainWindow;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.inventory.Container;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.MathHelper;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
public class RecipeGui extends GuiContainer {
private static final ResourceLocation CREATIVE_INVENTORY_TABS = new ResourceLocation("textures/gui/container/creative_inventory/tabs.png");
private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("almostenoughitems", "textures/gui/recipecontainer.png");
private final MainWindow mainWindow;
private final Container container;
private final GuiScreen prevScreen;
private final Map<IDisplayCategory, List<IRecipe>> recipes;
private int guiWidth = 176;
private int guiHeight = 222;
ArrayList<IDisplayCategory> categories = new ArrayList<>();
private int categoryTabPage = 0;
private IDisplayCategory selectedCategory;
private int recipePointer = 0;
private List<REISlot> slots;
private int cycleCounter = 0;
private int[] itemPointer;
List<Control> controls = new LinkedList<>();
private List<Tab> tabs;
private boolean tabsEnabled = false;
public RecipeGui(Container p_i1072_1_, GuiScreen prevScreen, Map<IDisplayCategory, List<IRecipe>> recipes) {
super(new RecipeContainer());
this.container = p_i1072_1_;
this.prevScreen = prevScreen;
this.recipes = recipes;
this.mc = Minecraft.getInstance();
this.itemRender = mc.getItemRenderer();
this.fontRenderer = mc.fontRenderer;
this.mainWindow = Minecraft.getInstance().mainWindow;
setupCategories();
}
private void setupCategories() {
for(IDisplayCategory adapter : REIRecipeManager.instance().getDisplayAdapters())
if (recipes.containsKey(adapter))
categories.add(adapter);
selectedCategory = categories.get(0);
categoryTabPage = 0;
tabs = new ArrayList<>();
for(int i = 0; i < 6; i++)
tabs.add(new Tab(i, 0, 0, 0, 28, 32));
tabs.forEach(tab -> tab.setOnClick(i -> {
return onClickTab(tab.getId());
}));
updateRecipe();
}
@Override
public void render(int mouseX, int mouseY, float partialTicks) {
super.render(mouseX, mouseY, partialTicks);
int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
drawCenteredString(this.fontRenderer, selectedCategory.getDisplayName(), guiLeft + guiWidth / 2, y + 11, -1);
drawCenteredString(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), guiLeft + guiWidth / 2, y + 34, -1);
controls.forEach(Control::draw);
}
private int getCurrentPage() {
return recipePointer / 2;
}
@Override
public void tick() {
super.tick();
slots.forEach(REISlot::tick);
controls.forEach(Control::tick);
}
@Override
public void onResize(Minecraft p_onResize_1_, int p_onResize_2_, int p_onResize_3_) {
super.onResize(p_onResize_1_, p_onResize_2_, p_onResize_3_);
updateRecipe();
}
private void updateRecipe() {
int categoryPointer = categories.indexOf(selectedCategory);
IRecipe recipe = recipes.get(categories.get(categoryPointer)).get(recipePointer);
categories.get(categoryPointer).resetRecipes();
categories.get(categoryPointer).addRecipe(recipe);
slots = categories.get(categoryPointer).setupDisplay(0);
if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2) {
IRecipe recipe2 = recipes.get(categories.get(categoryPointer)).get(recipePointer + 1);
categories.get(categoryPointer).addRecipe(recipe2);
slots.addAll(categories.get(categoryPointer).setupDisplay(1));
}
guiLeft = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
guiTop = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
slots.forEach(reiSlot -> reiSlot.move(guiLeft, guiTop));
Button btnCategoryLeft = new Button(guiLeft + 10, guiTop + 5, 15, 20, "<");
Button btnCategoryRight = new Button(guiLeft + guiWidth - 25, guiTop + 5, 15, 20, ">");
btnCategoryRight.onClick = this::btnCategoryRight;
btnCategoryLeft.onClick = this::btnCategoryLeft;
Button btnRecipeLeft = new Button(guiLeft + 10, guiTop + 28, 15, 20, "<");
Button btnRecipeRight = new Button(guiLeft + guiWidth - 25, guiTop + 28, 15, 20, ">");
btnRecipeLeft.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && recipePointer > 0);
btnRecipeRight.setEnabled(recipes.get(categories.get(categoryPointer)).size() > 1 && getCurrentPage() + 1 < getTotalPages());
btnRecipeRight.onClick = this::btnRecipeRight;
btnRecipeLeft.onClick = this::btnRecipeLeft;
controls.clear();
controls.add(btnCategoryLeft);
controls.add(btnCategoryRight);
if (categories.size() <= 1) {
btnCategoryLeft.setEnabled(false);
btnCategoryRight.setEnabled(false);
}
controls.add(btnRecipeLeft);
controls.add(btnRecipeRight);
itemPointer = new int[9];
for(int i = 0; i < itemPointer.length; i++) {
itemPointer[i] = 0;
}
List<Control> newControls = new LinkedList<>();
categories.get(categoryPointer).addWidget(newControls, 0);
if (recipes.get(categories.get(categoryPointer)).size() >= categoryPointer + 2)
categories.get(categoryPointer).addWidget(newControls, 1);
newControls.forEach(f -> f.move(guiLeft, guiTop));
controls.addAll(newControls);
updateTabs();
}
private void updateTabs() {
tabsEnabled = guiTop - 28 > 4;
if (tabsEnabled) {
tabs.forEach(tab -> tab.moveTo(guiLeft + 4, guiLeft + 2 + tabs.indexOf(tab) * 28, guiTop - 28));
for(int i = 0; i < tabs.size(); i++) {
int
|