VillagerRecipeViewingScreen.java 23 KB

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