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
|
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.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
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;
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_, 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 -> {
return onClickTab(tab.getId());
}));
updateRecipe();
}
@Override
public void draw(int mouseX, int mouseY, float partialTicks) {
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);
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));
}
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;
Button btnRecipeLeft = new Button(left + 10, top + 28, 15, 20, "<");
Button btnRecipeRight = new Button(left + guiWidth - 25, top + 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(left, top));
controls.addAll(newControls);
updateTabs();
}
private void updateTabs() {
tabsEnabled = top - 28 > 4;
if (tabsEnabled) {
tabs.forEach(tab -> tab.moveTo(left + 4, left + 2 + tabs.indexOf(tab) * 28, top - 28));
for(int i = 0; i < tabs.size(); i++) {
int ref = i + categoryTabPage * 6;
if<
|