VillagerRecipeViewingScreen.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.gui;
  6. import com.google.common.collect.Lists;
  7. import com.google.common.collect.Maps;
  8. import com.mojang.blaze3d.platform.GlStateManager;
  9. import com.zeitheron.hammercore.client.utils.Scissors;
  10. import me.shedaniel.math.api.Point;
  11. import me.shedaniel.math.api.Rectangle;
  12. import me.shedaniel.math.impl.PointHelper;
  13. import me.shedaniel.rei.RoughlyEnoughItemsCore;
  14. import me.shedaniel.rei.api.*;
  15. import me.shedaniel.rei.gui.renderers.RecipeRenderer;
  16. import me.shedaniel.rei.gui.widget.*;
  17. import me.shedaniel.rei.impl.ScreenHelper;
  18. import net.minecraft.client.MinecraftClient;
  19. import net.minecraft.client.gui.Element;
  20. import net.minecraft.client.gui.screen.Screen;
  21. import net.minecraft.client.render.BufferBuilder;
  22. import net.minecraft.client.render.GuiLighting;
  23. import net.minecraft.client.render.Tessellator;
  24. import net.minecraft.client.render.VertexFormats;
  25. import net.minecraft.client.resource.language.I18n;
  26. import net.minecraft.client.sound.PositionedSoundInstance;
  27. import net.minecraft.item.ItemStack;
  28. import net.minecraft.sound.SoundEvents;
  29. import net.minecraft.text.LiteralText;
  30. import net.minecraft.text.TranslatableText;
  31. import net.minecraft.util.Formatting;
  32. import net.minecraft.util.math.MathHelper;
  33. import java.util.*;
  34. import java.util.stream.Collectors;
  35. public class VillagerRecipeViewingScreen extends Screen {
  36. private static final int TABS_PER_PAGE = 8;
  37. private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoryMap;
  38. private final List<RecipeCategory<?>> categories;
  39. private final List<Widget> widgets;
  40. private final List<ButtonWidget> buttonWidgets;
  41. private final List<Renderer> recipeRenderers;
  42. private final List<TabWidget> tabs;
  43. public Rectangle bounds, scrollListBounds;
  44. private int selectedCategoryIndex, selectedRecipeIndex;
  45. private double scroll;
  46. private float scrollBarAlpha = 0;
  47. private float scrollBarAlphaFuture = 0;
  48. private long scrollBarAlphaFutureTime = -1;
  49. private boolean draggingScrollBar = false;
  50. private int tabsPage;
  51. public VillagerRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map) {
  52. super(new LiteralText(""));
  53. this.widgets = Lists.newArrayList();
  54. this.categoryMap = Maps.newLinkedHashMap();
  55. this.selectedCategoryIndex = 0;
  56. this.selectedRecipeIndex = 0;
  57. this.scrollBarAlpha = 0;
  58. this.scrollBarAlphaFuture = 0;
  59. this.scroll = 0;
  60. this.draggingScrollBar = false;
  61. this.tabsPage = 0;
  62. this.categories = Lists.newArrayList();
  63. this.buttonWidgets = Lists.newArrayList();
  64. this.tabs = Lists.newArrayList();
  65. this.recipeRenderers = Lists.newArrayList();
  66. RecipeHelper.getInstance().getAllCategories().forEach(category -> {
  67. if (map.containsKey(category)) {
  68. categories.add(category);
  69. categoryMap.put(category, map.get(category));
  70. }
  71. });
  72. }
  73. @Override
  74. protected void init() {
  75. super.init();
  76. this.draggingScrollBar = false;
  77. this.children.clear();
  78. this.widgets.clear();
  79. this.buttonWidgets.clear();
  80. this.recipeRenderers.clear();
  81. this.tabs.clear();
  82. int largestWidth = width - 100;
  83. int largestHeight = height - 40;
  84. RecipeCategory<RecipeDisplay> category = (RecipeCategory<RecipeDisplay>) categories.get(selectedCategoryIndex);
  85. RecipeDisplay display = categoryMap.get(category).get(selectedRecipeIndex);
  86. int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100;
  87. int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight);
  88. this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
  89. List<List<ItemStack>> workingStations = RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(category.getIdentifier());
  90. if (!workingStations.isEmpty()) {
  91. int ww = MathHelper.floor((bounds.width - 16) / 18f);
  92. int w = Math.min(ww, workingStations.size());
  93. int h = MathHelper.ceil(workingStations.size() / ((float) ww));
  94. int xx = bounds.x + 16;
  95. int yy = bounds.y + bounds.height + 5;
  96. widgets.add(new CategoryBaseWidget(new Rectangle(xx - 6, bounds.y + bounds.height - 5, 11 + w * 18, 15 + h * 18)));
  97. int index = 0;
  98. List<String> list = Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("text.rei.working_station"));
  99. for (List<ItemStack> workingStation : workingStations) {
  100. widgets.add(new SlotWidget(xx, yy, Renderer.fromItemStacks(workingStation), true, true, true) {
  101. @Override
  102. protected List<String> getExtraItemToolTips(ItemStack stack) {
  103. return list;
  104. }
  105. });
  106. index++;
  107. xx += 18;
  108. if (index >= ww) {
  109. index = 0;
  110. xx = bounds.x + 16;
  111. yy += 18;
  112. }
  113. }
  114. }
  115. this.widgets.add(new CategoryBaseWidget(bounds));
  116. this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97 + 5, guiHeight - 17 - 7);
  117. this.widgets.add(new SlotBaseWidget(scrollListBounds));
  118. Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight());
  119. List<Widget> setupDisplay = category.setupDisplay(() -> display, recipeBounds);
  120. this.widgets.addAll(setupDisplay);
  121. Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(category);
  122. if (supplier.isPresent() && supplier.get().get(recipeBounds) != null)
  123. this.widgets.add(new AutoCraftingButtonWidget(recipeBounds, supplier.get().get(recipeBounds), supplier.get().getButtonText(), () -> display, setupDisplay, category));
  124. int index = 0;
  125. for (RecipeDisplay recipeDisplay : categoryMap.get(category)) {
  126. int finalIndex = index;
  127. RecipeRenderer recipeRenderer;
  128. recipeRenderers.add(recipeRenderer = category.getSimpleRenderer(recipeDisplay));
  129. buttonWidgets.add(new ButtonWidget(bounds.x + 5, 0, recipeRenderer.getWidth(), recipeRenderer.getHeight(), "") {
  130. @Override
  131. public void onPressed() {
  132. selectedRecipeIndex = finalIndex;
  133. VillagerRecipeViewingScreen.this.init();
  134. }
  135. @Override
  136. public boolean isHovered(int mouseX, int mouseY) {
  137. return (isMouseOver(mouseX, mouseY) && scrollListBounds.contains(mouseX, mouseY)) || focused;
  138. }
  139. @Override
  140. protected int getTextureId(boolean boolean_1) {
  141. enabled = selectedRecipeIndex != finalIndex;
  142. return super.getTextureId(boolean_1);
  143. }
  144. @Override
  145. public boolean mouseClicked(double mouseX, double mouseY, int button) {
  146. if ((isMouseOver(mouseX, mouseY) && scrollListBounds.contains(mouseX, mouseY)) && enabled && button == 0) {
  147. minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  148. onPressed();
  149. return true;
  150. }
  151. return false;
  152. }
  153. });
  154. index++;
  155. }
  156. for (int i = 0; i < TABS_PER_PAGE; i++) {
  157. int j = i + tabsPage * TABS_PER_PAGE;
  158. if (categories.size() > j) {
  159. TabWidget tab;
  160. tabs.add(tab = new TabWidget(i, new Rectangle(bounds.x + bounds.width / 2 - Math.min(categories.size() - tabsPage * TABS_PER_PAGE, TABS_PER_PAGE) * 14 + i * 28, bounds.y - 28, 28, 28)) {
  161. @Override
  162. public boolean mouseClicked(double mouseX, double mouseY, int button) {
  163. if (getBounds().contains(mouseX, mouseY)) {
  164. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  165. if (getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex)
  166. return false;
  167. selectedCategoryIndex = getId() + tabsPage * TABS_PER_PAGE;
  168. scroll = 0;
  169. selectedRecipeIndex = 0;
  170. VillagerRecipeViewingScreen.this.init();
  171. return true;
  172. }
  173. return false;
  174. }
  175. });
  176. tab.setRenderer(categories.get(j), categories.get(j).getIcon(), categories.get(j).getCategoryName(), tab.getId() + tabsPage * TABS_PER_PAGE == selectedCategoryIndex);
  177. }
  178. }
  179. ButtonWidget w, w2;
  180. this.widgets.add(w = new ButtonWidget(bounds.x + 2, bounds.y - 16, 10, 10, new TranslatableText("text.rei.left_arrow")) {
  181. @Override
  182. public void onPressed() {
  183. tabsPage--;
  184. if (tabsPage < 0)
  185. tabsPage = MathHelper.ceil(categories.size() / (float) TABS_PER_PAGE) - 1;
  186. VillagerRecipeViewingScreen.this.init();
  187. }
  188. });
  189. this.widgets.add(w2 = new ButtonWidget(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10, new TranslatableText("text.rei.right_arrow")) {
  190. @Override
  191. public void onPressed() {
  192. tabsPage++;
  193. if (tabsPage > MathHelper.ceil(categories.size() / (float) TABS_PER_PAGE) - 1)
  194. tabsPage = 0;
  195. VillagerRecipeViewingScreen.this.init();
  196. }
  197. });
  198. w.enabled = w2.enabled = categories.size() > TABS_PER_PAGE;
  199. this.widgets.add(new ClickableLabelWidget(bounds.x + 4 + scrollListBounds.width / 2, bounds.y + 6, categories.get(selectedCategoryIndex).getCategoryName()) {
  200. @Override
  201. public void onLabelClicked() {
  202. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  203. ClientHelper.getInstance().executeViewAllRecipesKeyBind();
  204. }
  205. @Override
  206. public Optional<String> getTooltips() {
  207. return Optional.ofNullable(I18n.translate("text.rei.view_all_categories"));
  208. }
  209. @Override
  210. public void render(int mouseX, int mouseY, float delta) {
  211. GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  212. font.draw((isHovered(mouseX, mouseY) ? Formatting.UNDERLINE.toString() : "") + text, x - font.getStringWidth(text) / 2, y, getDefaultColor());
  213. if (clickable && getTooltips().isPresent())
  214. if (!focused && containsMouse(mouseX, mouseY))
  215. ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(getTooltips().get().split("\n")));
  216. else if (focused)
  217. ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(new Point(x, y), getTooltips().get().split("\n")));
  218. }
  219. @Override
  220. public int getDefaultColor() {
  221. return ScreenHelper.isDarkModeEnabled() ? 0xFFBBBBBB : 4210752;
  222. }
  223. });
  224. this.children.addAll(buttonWidgets);
  225. this.widgets.addAll(tabs);
  226. this.children.addAll(widgets);
  227. this.children.add(ScreenHelper.getLastOverlay(true, false));
  228. ScreenHelper.getLastOverlay().init();
  229. }
  230. @Override
  231. public boolean mouseClicked(double mouseX, double mouseY, int int_1) {
  232. double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight));
  233. int actualHeight = scrollListBounds.height - 2;
  234. if (height > actualHeight && scrollBarAlpha > 0 && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) {
  235. double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6;
  236. if (mouseX >= scrollbarPositionMinX & mouseX <= scrollbarPositionMinX + 8) {
  237. this.draggingScrollBar = true;
  238. scrollBarAlpha = 1;
  239. return false;
  240. }
  241. }
  242. this.draggingScrollBar = false;
  243. return super.mouseClicked(mouseX, mouseY, int_1);
  244. }
  245. @Override
  246. public boolean charTyped(char char_1, int int_1) {
  247. for (Element listener : children())
  248. if (listener.charTyped(char_1, int_1))
  249. return true;
  250. return super.charTyped(char_1, int_1);
  251. }
  252. @Override
  253. public boolean mouseScrolled(double double_1, double double_2, double double_3) {
  254. double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight));
  255. if (scrollListBounds.contains(double_1, double_2) && height > scrollListBounds.height - 2) {
  256. if (double_3 > 0)
  257. scroll -= 16;
  258. else
  259. scroll += 16;
  260. scroll = MathHelper.clamp(scroll, 0, height - scrollListBounds.height + 2);
  261. if (scrollBarAlphaFuture == 0)
  262. scrollBarAlphaFuture = 1f;
  263. if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f)
  264. scrollBarAlphaFutureTime = System.currentTimeMillis();
  265. return true;
  266. }
  267. for (Element listener : children())
  268. if (listener.mouseScrolled(double_1, double_2, double_3))
  269. return true;
  270. if (bounds.contains(PointHelper.fromMouse())) {
  271. if (double_3 < 0 && categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  272. selectedRecipeIndex++;
  273. if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size())
  274. selectedRecipeIndex = 0;
  275. init();
  276. } else if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  277. selectedRecipeIndex--;
  278. if (selectedRecipeIndex < 0)
  279. selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1;
  280. init();
  281. return true;
  282. }
  283. }
  284. return super.mouseScrolled(double_1, double_2, double_3);
  285. }
  286. @Override
  287. public void render(int mouseX, int mouseY, float delta) {
  288. if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesVillagerScreenHavePermanentScrollBar()) {
  289. scrollBarAlphaFutureTime = System.currentTimeMillis();
  290. scrollBarAlphaFuture = 0;
  291. scrollBarAlpha = 1;
  292. } else if (scrollBarAlphaFutureTime > 0) {
  293. long l = System.currentTimeMillis() - scrollBarAlphaFutureTime;
  294. if (l > 300f) {
  295. if (scrollBarAlphaFutureTime == 0) {
  296. scrollBarAlpha = scrollBarAlphaFuture;
  297. scrollBarAlphaFutureTime = -1;
  298. } else if (l > 2000f && scrollBarAlphaFuture == 1) {
  299. scrollBarAlphaFuture = 0;
  300. scrollBarAlphaFutureTime = System.currentTimeMillis();
  301. } else
  302. scrollBarAlpha = scrollBarAlphaFuture;
  303. } else {
  304. if (scrollBarAlphaFuture == 0)
  305. scrollBarAlpha = Math.min(scrollBarAlpha, 1 - Math.min(1f, l / 300f));
  306. else if (scrollBarAlphaFuture == 1)
  307. scrollBarAlpha = Math.max(Math.min(1f, l / 300f), scrollBarAlpha);
  308. }
  309. }
  310. this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
  311. int yOffset = 0;
  312. this.widgets.forEach(widget -> {
  313. GuiLighting.disable();
  314. widget.render(mouseX, mouseY, delta);
  315. });
  316. GuiLighting.disable();
  317. ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta);
  318. GlStateManager.pushMatrix();
  319. Scissors.begin();
  320. Scissors.scissor(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2);
  321. for (int i = 0; i < buttonWidgets.size(); i++) {
  322. ButtonWidget buttonWidget = buttonWidgets.get(i);
  323. buttonWidget.getBounds().y = scrollListBounds.y + 1 + yOffset - (int) scroll;
  324. if (buttonWidget.getBounds().getMaxY() > scrollListBounds.getMinY() && buttonWidget.getBounds().getMinY() < scrollListBounds.getMaxY()) {
  325. GuiLighting.disable();
  326. buttonWidget.render(mouseX, mouseY, delta);
  327. }
  328. yOffset += buttonWidget.getBounds().height;
  329. }
  330. for (int i = 0; i < buttonWidgets.size(); i++) {
  331. if (buttonWidgets.get(i).getBounds().getMaxY() > scrollListBounds.getMinY() && buttonWidgets.get(i).getBounds().getMinY() < scrollListBounds.getMaxY()) {
  332. GuiLighting.disable();
  333. recipeRenderers.get(i).setBlitOffset(1);
  334. recipeRenderers.get(i).render(buttonWidgets.get(i).getBounds().x, buttonWidgets.get(i).getBounds().y, mouseX, mouseY, delta);
  335. }
  336. }
  337. double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight));
  338. if (height > scrollListBounds.height - 2) {
  339. Tessellator tessellator = Tessellator.getInstance();
  340. BufferBuilder buffer = tessellator.getBufferBuilder();
  341. double maxScroll = height - scrollListBounds.height + 2;
  342. int scrollBarHeight = MathHelper.floor((scrollListBounds.height - 2) * (scrollListBounds.height - 2) / maxScroll);
  343. scrollBarHeight = MathHelper.clamp(scrollBarHeight, 32, scrollListBounds.height - 2 - 8);
  344. int minY = (int) (scroll * (scrollListBounds.height - 2 - scrollBarHeight) / maxScroll) + scrollListBounds.y + 1;
  345. if (minY < this.scrollListBounds.y + 1)
  346. minY = this.scrollListBounds.y + 1;
  347. double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6, scrollbarPositionMaxX = scrollListBounds.getMaxX() - 2;
  348. GuiLighting.disable();
  349. GlStateManager.disableTexture();
  350. GlStateManager.enableBlend();
  351. GlStateManager.disableAlphaTest();
  352. GlStateManager.blendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
  353. GlStateManager.shadeModel(7425);
  354. buffer.begin(7, VertexFormats.POSITION_COLOR);
  355. float b = ScreenHelper.isDarkModeEnabled() ? 0.37f : 1f;
  356. buffer.vertex(scrollbarPositionMinX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next();
  357. buffer.vertex(scrollbarPositionMaxX, minY + scrollBarHeight, 1000D).color(b, b, b, scrollBarAlpha).next();
  358. buffer.vertex(scrollbarPositionMaxX, minY, 1000D).color(b, b, b, scrollBarAlpha).next();
  359. buffer.vertex(scrollbarPositionMinX, minY, 1000D).color(b, b, b, scrollBarAlpha).next();
  360. tessellator.draw();
  361. GlStateManager.shadeModel(7424);
  362. GlStateManager.disableBlend();
  363. GlStateManager.enableAlphaTest();
  364. GlStateManager.enableTexture();
  365. }
  366. Scissors.end();
  367. GlStateManager.popMatrix();
  368. ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta);
  369. }
  370. @Override
  371. public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) {
  372. if (int_1 == 0 && scrollBarAlpha > 0 && draggingScrollBar) {
  373. double height = buttonWidgets.stream().map(ButtonWidget::getBounds).collect(Collectors.summingDouble(Rectangle::getHeight));
  374. int actualHeight = scrollListBounds.height - 2;
  375. if (height > actualHeight && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) {
  376. int int_3 = MathHelper.clamp((int) ((actualHeight * actualHeight) / height), 32, actualHeight - 8);
  377. double double_6 = Math.max(1.0D, Math.max(1d, height) / (double) (actualHeight - int_3));
  378. scrollBarAlphaFutureTime = System.currentTimeMillis();
  379. scrollBarAlphaFuture = 1f;
  380. scroll = MathHelper.clamp(scroll + double_4 * double_6, 0, height - scrollListBounds.height + 2);
  381. return true;
  382. }
  383. }
  384. return super.mouseDragged(mouseX, mouseY, int_1, double_3, double_4);
  385. }
  386. @Override
  387. public boolean keyPressed(int int_1, int int_2, int int_3) {
  388. if ((int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) && this.shouldCloseOnEsc()) {
  389. MinecraftClient.getInstance().openScreen(ScreenHelper.getLastContainerScreen());
  390. ScreenHelper.getLastOverlay().init();
  391. return true;
  392. }
  393. if (int_1 == 258) {
  394. boolean boolean_1 = !hasShiftDown();
  395. if (!this.changeFocus(boolean_1))
  396. this.changeFocus(boolean_1);
  397. return true;
  398. }
  399. if (ClientHelper.getInstance().getNextPageKeyBinding().matchesKey(int_1, int_2)) {
  400. if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  401. selectedRecipeIndex++;
  402. if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size())
  403. selectedRecipeIndex = 0;
  404. init();
  405. return true;
  406. }
  407. return false;
  408. } else if (ClientHelper.getInstance().getPreviousPageKeyBinding().matchesKey(int_1, int_2)) {
  409. if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  410. selectedRecipeIndex--;
  411. if (selectedRecipeIndex < 0)
  412. selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1;
  413. init();
  414. return true;
  415. }
  416. return false;
  417. }
  418. for (Element element : children())
  419. if (element.keyPressed(int_1, int_2, int_3))
  420. return true;
  421. if (int_1 == 259) {
  422. if (ScreenHelper.hasLastRecipeScreen())
  423. minecraft.openScreen(ScreenHelper.getLastRecipeScreen());
  424. else minecraft.openScreen(ScreenHelper.getLastContainerScreen());
  425. return true;
  426. }
  427. return super.keyPressed(int_1, int_2, int_3);
  428. }
  429. }