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
|
package me.shedaniel.gui;
import com.mojang.blaze3d.platform.GlStateManager;
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.MinecraftClient;
import net.minecraft.client.gui.ContainerGui;
import net.minecraft.client.gui.Gui;
import net.minecraft.client.render.GuiLighting;
import net.minecraft.client.util.Window;
import net.minecraft.container.Container;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import java.util.*;
public class RecipeGui extends ContainerGui {
private static final Identifier CREATIVE_INVENTORY_TABS = new Identifier("textures/gui/container/creative_inventory/tabs.png");
private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
private final Window mainWindow;
private final Container container;
private final Gui prevScreen;
public final Map<IDisplayCategory, List<IRecipe>> recipes;
public final int guiWidth = 176;
public final int guiHeight = 222;
ArrayList<IDisplayCategory> categories = new ArrayList<>();
private int categoryTabPage = 0;
public IDisplayCategory selectedCategory;
private int recipePointer = 0;
public List<REISlot> slots;
List<Control> controls = new LinkedList<>();
private List<Tab> tabs;
private boolean tabsEnabled = false;
private Button btnCategoryPageLeft, btnCategoryPageRight;
public Button btnRecipeLeft, btnRecipeRight;
public RecipeGui(Container p_i1072_1_, Gui prevScreen, Map<IDisplayCategory, List<IRecipe>> recipes) {
super(new RecipeContainer());
this.container = p_i1072_1_;
this.prevScreen = prevScreen;
this.recipes = recipes;
this.client = MinecraftClient.getInstance();
this.itemRenderer = client.getItemRenderer();
this.fontRenderer = client.fontRenderer;
this.mainWindow = client.window;
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 -> {
if (tab.getId() + categoryTabPage * 6 == categories.indexOf(selectedCategory))
return false;
selectedCategory = categories.get(tab.getId() + categoryTabPage * 6);
recipePointer = 0;
updateRecipe();
return false;
}));
updateRecipe();
}
@Override
public void draw(int mouseX, int mouseY, float partialTicks) {
drawBackground();
super.draw(mouseX, mouseY, partialTicks);
int y = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
drawStringCentered(this.fontRenderer, selectedCategory.getDisplayName(), left + guiWidth / 2, y + 11, -1);
drawStringCentered(this.fontRenderer, String.format("%d/%d", 1 + getCurrentPage(), getTotalPages()), left + guiWidth / 2, y + 34, -1);
controls.forEach(Control::draw);
}
private int getCurrentPage() {
return recipePointer / 2;
}
@Override
public void update() {
super.update();
slots.forEach(REISlot::tick);
controls.forEach(Control::tick);
}
@Override
public void onScaleChanged(MinecraftClient p_onResize_1_, int p_onResize_2_, int p_onResize_3_) {
super.onScaleChanged(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);
selectedCategory.resetRecipes();
selectedCategory.addRecipe(recipe);
slots = selectedCategory.setupDisplay(0);
if (recipes.get(selectedCategory).size() >= recipePointer + 2) {
IRecipe recipe2 = recipes.get(selectedCategory).get(recipePointer + 1);
selectedCategory.addRecipe(recipe2);
slots.addAll(selectedCategory.setupDisplay(1));
}
left = (int) ((mainWindow.getScaledWidth() / 2 - this.guiWidth / 2));
top = (int) ((mainWindow.getScaledHeight() / 2 - this.guiHeight / 2));
slots.forEach(reiSlot -> reiSlot.move(left, top));
Button btnCategoryLeft = new Button(left + 10, top + 5, 15, 20, "<");
Button btnCategoryRight = new Button(left + guiWidth - 25, top + 5, 15, 20, ">");
btnCategoryRight.onClick = this::btnCategoryRight;
btnCategoryLeft.onClick = this::btnCategoryLeft;
btnRecipeLeft = new Button(left + 10, top + 28, 15, 20, "<");
btnRecipeRight = new Button(left + guiWidth - 25, top + 28, 15, 20, ">");
btnRecipeLeft.setEnabled(recipes.get(selectedCategory).size() > 2);
btnRecipeRight.setEnabled(recipes.get(selectedCategory).size() > 2);
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);
} else if (categories.size() > 6) {
btnCategoryPageLeft = new Button(left, top - 52, 20, 20, "<");
btnCategoryPageRight = new Button(left + guiWidth - 20, top - 52, 20, 20, ">");
btnCategoryPageLeft.setOnClick(i -> {
categoryTabPage--;
if (categoryTabPage <= 0)
categoryTabPage = MathHelper.ceil(categories.size() / 6d);
updateRecipe();
return true;
});
btnCategoryPageRight.setOnClick(i -> {
categoryTabPage++;
if (categoryTabPage >= MathHelper.ceil(categories.size() / 6d))
categoryTabPage = 0;
updateRecipe();
return true;
});
if (top - 52 >= 2)
controls.addAll(Arrays.asList(btnCategoryPageLeft, btnCategoryPageRight));
}
controls.add(btnRecipeLeft);
controls.add(btnRecipeRight);
List<Control> newControls = new LinkedList<>();
categories.get(categoryPointer).addWidget(newControls, 0);
if (recipes.get(categories.g
|