VillagerRecipeViewingScreen.java 24 KB

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