VillagerRecipeViewingScreen.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  1. /*
  2. * This file is licensed under the MIT License, part of Roughly Enough Items.
  3. * Copyright (c) 2018, 2019, 2020 shedaniel
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in all
  13. * copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package me.shedaniel.rei.gui;
  24. import com.google.common.collect.Lists;
  25. import com.google.common.collect.Maps;
  26. import com.mojang.blaze3d.systems.RenderSystem;
  27. import me.shedaniel.clothconfig2.ClothConfigInitializer;
  28. import me.shedaniel.clothconfig2.api.ScissorsHandler;
  29. import me.shedaniel.math.api.Point;
  30. import me.shedaniel.math.api.Rectangle;
  31. import me.shedaniel.math.impl.PointHelper;
  32. import me.shedaniel.rei.api.*;
  33. import me.shedaniel.rei.gui.entries.RecipeEntry;
  34. import me.shedaniel.rei.gui.widget.*;
  35. import me.shedaniel.rei.impl.ScreenHelper;
  36. import me.shedaniel.rei.utils.CollectionUtils;
  37. import net.minecraft.client.MinecraftClient;
  38. import net.minecraft.client.gui.Element;
  39. import net.minecraft.client.gui.screen.Screen;
  40. import net.minecraft.client.render.BufferBuilder;
  41. import net.minecraft.client.render.Tessellator;
  42. import net.minecraft.client.render.VertexFormats;
  43. import net.minecraft.client.resource.language.I18n;
  44. import net.minecraft.client.sound.PositionedSoundInstance;
  45. import net.minecraft.client.util.NarratorManager;
  46. import net.minecraft.sound.SoundEvents;
  47. import net.minecraft.text.LiteralText;
  48. import net.minecraft.text.TranslatableText;
  49. import net.minecraft.util.Formatting;
  50. import net.minecraft.util.math.MathHelper;
  51. import org.jetbrains.annotations.ApiStatus;
  52. import java.util.Collections;
  53. import java.util.List;
  54. import java.util.Map;
  55. import java.util.Optional;
  56. @ApiStatus.Internal
  57. public class VillagerRecipeViewingScreen extends Screen implements StackToNoticeScreen {
  58. private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoryMap;
  59. private final List<RecipeCategory<?>> categories;
  60. private final List<Widget> widgets;
  61. private final List<ButtonWidget> buttonWidgets;
  62. private final List<RecipeEntry> recipeRenderers;
  63. private final List<TabWidget> tabs;
  64. public Rectangle bounds, scrollListBounds;
  65. private int tabsPerPage = 8;
  66. private int selectedCategoryIndex, selectedRecipeIndex;
  67. private double scroll;
  68. private double target;
  69. private long start;
  70. private long duration;
  71. private float scrollBarAlpha;
  72. private float scrollBarAlphaFuture;
  73. private long scrollBarAlphaFutureTime = -1;
  74. private boolean draggingScrollBar;
  75. private int tabsPage;
  76. private EntryStack ingredientStackToNotice = EntryStack.empty();
  77. private EntryStack resultStackToNotice = EntryStack.empty();
  78. public VillagerRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map) {
  79. super(new LiteralText(""));
  80. this.widgets = Lists.newArrayList();
  81. this.categoryMap = Maps.newLinkedHashMap();
  82. this.selectedCategoryIndex = 0;
  83. this.selectedRecipeIndex = 0;
  84. this.scrollBarAlpha = 0;
  85. this.scrollBarAlphaFuture = 0;
  86. this.scroll = 0;
  87. this.draggingScrollBar = false;
  88. this.tabsPage = 0;
  89. this.categories = Lists.newArrayList();
  90. this.buttonWidgets = Lists.newArrayList();
  91. this.tabs = Lists.newArrayList();
  92. this.recipeRenderers = Lists.newArrayList();
  93. RecipeHelper.getInstance().getAllCategories().forEach(category -> {
  94. if (map.containsKey(category)) {
  95. categories.add(category);
  96. categoryMap.put(category, map.get(category));
  97. }
  98. });
  99. }
  100. @Override
  101. public boolean isPauseScreen() {
  102. return false;
  103. }
  104. @Override
  105. public void addIngredientStackToNotice(EntryStack stack) {
  106. ingredientStackToNotice = stack;
  107. }
  108. @Override
  109. public void addResultStackToNotice(EntryStack stack) {
  110. resultStackToNotice = stack;
  111. }
  112. @Override
  113. protected void init() {
  114. super.init();
  115. boolean isCompactTabs = ConfigObject.getInstance().isUsingCompactTabs();
  116. int tabSize = isCompactTabs ? 24 : 28;
  117. this.draggingScrollBar = false;
  118. this.children.clear();
  119. this.widgets.clear();
  120. this.buttonWidgets.clear();
  121. this.recipeRenderers.clear();
  122. this.tabs.clear();
  123. int largestWidth = width - 100;
  124. int largestHeight = height - 40;
  125. RecipeCategory<RecipeDisplay> category = (RecipeCategory<RecipeDisplay>) categories.get(selectedCategoryIndex);
  126. RecipeDisplay display = categoryMap.get(category).get(selectedRecipeIndex);
  127. int guiWidth = MathHelper.clamp(category.getDisplayWidth(display) + 30, 0, largestWidth) + 100;
  128. int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight);
  129. this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize));
  130. this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
  131. List<List<EntryStack>> workingStations = RecipeHelper.getInstance().getWorkingStations(category.getIdentifier());
  132. if (!workingStations.isEmpty()) {
  133. int ww = MathHelper.floor((bounds.width - 16) / 18f);
  134. int w = Math.min(ww, workingStations.size());
  135. int h = MathHelper.ceil(workingStations.size() / ((float) ww));
  136. int xx = bounds.x + 16;
  137. int yy = bounds.y + bounds.height + 2;
  138. widgets.add(new CategoryBaseWidget(new Rectangle(xx - 5, bounds.y + bounds.height - 5, 10 + w * 16, 12 + h * 16)));
  139. widgets.add(new SlotBaseWidget(new Rectangle(xx - 1, yy - 1, 2 + w * 16, 2 + h * 16)));
  140. int index = 0;
  141. List<String> list = Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("text.rei.working_station"));
  142. for (List<EntryStack> workingStation : workingStations) {
  143. widgets.add(new RecipeViewingScreen.WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list))));
  144. index++;
  145. xx += 16;
  146. if (index >= ww) {
  147. index = 0;
  148. xx = bounds.x + 16;
  149. yy += 16;
  150. }
  151. }
  152. }
  153. this.widgets.add(new CategoryBaseWidget(bounds));
  154. this.scrollListBounds = new Rectangle(bounds.x + 4, bounds.y + 17, 97 + 5, guiHeight - 17 - 7);
  155. this.widgets.add(new SlotBaseWidget(scrollListBounds));
  156. 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());
  157. List<Widget> setupDisplay = category.setupDisplay(() -> display, recipeBounds);
  158. RecipeViewingScreen.transformIngredientNotice(setupDisplay, ingredientStackToNotice);
  159. RecipeViewingScreen.transformResultNotice(setupDisplay, resultStackToNotice);
  160. this.widgets.addAll(setupDisplay);
  161. Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(category);
  162. if (supplier.isPresent() && supplier.get().get(recipeBounds) != null)
  163. this.widgets.add(new AutoCraftingButtonWidget(recipeBounds, supplier.get().get(recipeBounds), supplier.get().getButtonText(), () -> display, setupDisplay, category));
  164. int index = 0;
  165. for (RecipeDisplay recipeDisplay : categoryMap.get(category)) {
  166. int finalIndex = index;
  167. RecipeEntry recipeEntry;
  168. recipeRenderers.add(recipeEntry = category.getSimpleRenderer(recipeDisplay));
  169. buttonWidgets.add(new ButtonWidget(new Rectangle(bounds.x + 5, 0, recipeEntry.getWidth(), recipeEntry.getHeight()), NarratorManager.EMPTY) {
  170. @Override
  171. public void onPressed() {
  172. selectedRecipeIndex = finalIndex;
  173. VillagerRecipeViewingScreen.this.init();
  174. }
  175. @Override
  176. public boolean isHovered(int mouseX, int mouseY) {
  177. return (isMouseOver(mouseX, mouseY) && scrollListBounds.contains(mouseX, mouseY)) || focused;
  178. }
  179. @Override
  180. protected int getTextureId(boolean boolean_1) {
  181. enabled = selectedRecipeIndex != finalIndex;
  182. return super.getTextureId(boolean_1);
  183. }
  184. @Override
  185. public boolean mouseClicked(double mouseX, double mouseY, int button) {
  186. if ((isMouseOver(mouseX, mouseY) && scrollListBounds.contains(mouseX, mouseY)) && enabled && button == 0) {
  187. minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  188. onPressed();
  189. return true;
  190. }
  191. return false;
  192. }
  193. });
  194. index++;
  195. }
  196. int tabV = isCompactTabs ? 166 : 192;
  197. for (int i = 0; i < tabsPerPage; i++) {
  198. int j = i + tabsPage * tabsPerPage;
  199. if (categories.size() > j) {
  200. TabWidget tab;
  201. tabs.add(tab = new TabWidget(i, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - tabsPage * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, tabV) {
  202. @Override
  203. public boolean mouseClicked(double mouseX, double mouseY, int button) {
  204. if (containsMouse(mouseX, mouseY)) {
  205. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  206. if (getId() + tabsPage * tabsPerPage == selectedCategoryIndex)
  207. return false;
  208. selectedCategoryIndex = getId() + tabsPage * tabsPerPage;
  209. scroll = 0;
  210. selectedRecipeIndex = 0;
  211. VillagerRecipeViewingScreen.this.init();
  212. return true;
  213. }
  214. return false;
  215. }
  216. });
  217. tab.setRenderer(categories.get(j), categories.get(j).getLogo(), categories.get(j).getCategoryName(), tab.getId() + tabsPage * tabsPerPage == selectedCategoryIndex);
  218. }
  219. }
  220. ButtonWidget w, w2;
  221. this.widgets.add(w = ButtonWidget.create(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), new TranslatableText("text.rei.left_arrow"), buttonWidget -> {
  222. tabsPage--;
  223. if (tabsPage < 0)
  224. tabsPage = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1;
  225. VillagerRecipeViewingScreen.this.init();
  226. }));
  227. this.widgets.add(w2 = ButtonWidget.create(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), new TranslatableText("text.rei.right_arrow"), buttonWidget -> {
  228. tabsPage++;
  229. if (tabsPage > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1)
  230. tabsPage = 0;
  231. VillagerRecipeViewingScreen.this.init();
  232. }));
  233. w.enabled = w2.enabled = categories.size() > tabsPerPage;
  234. this.widgets.add(new ClickableLabelWidget(new Point(bounds.x + 4 + scrollListBounds.width / 2, bounds.y + 6), categories.get(selectedCategoryIndex).getCategoryName()) {
  235. @Override
  236. public void onLabelClicked() {
  237. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  238. ClientHelper.getInstance().executeViewAllRecipesKeyBind();
  239. }
  240. @Override
  241. public Optional<String> getTooltips() {
  242. return Optional.ofNullable(I18n.translate("text.rei.view_all_categories"));
  243. }
  244. });
  245. this.children.addAll(buttonWidgets);
  246. this.widgets.addAll(tabs);
  247. this.children.addAll(widgets);
  248. this.children.add(ScreenHelper.getLastOverlay(true, false));
  249. ScreenHelper.getLastOverlay().init();
  250. }
  251. private double getMaxScroll() {
  252. return Math.max(0, this.getMaxScrollPosition() - (scrollListBounds.height - 2));
  253. }
  254. @Override
  255. public boolean mouseClicked(double mouseX, double mouseY, int int_1) {
  256. double height = getMaxScrollPosition();
  257. int actualHeight = scrollListBounds.height - 2;
  258. if (height > actualHeight && scrollBarAlpha > 0 && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) {
  259. double scrollbarPositionMinX = scrollListBounds.getMaxX() - 6;
  260. if (mouseX >= scrollbarPositionMinX & mouseX <= scrollbarPositionMinX + 8) {
  261. this.draggingScrollBar = true;
  262. scrollBarAlpha = 1;
  263. return false;
  264. }
  265. }
  266. this.draggingScrollBar = false;
  267. return super.mouseClicked(mouseX, mouseY, int_1);
  268. }
  269. @Override
  270. public boolean charTyped(char char_1, int int_1) {
  271. for (Element listener : children())
  272. if (listener.charTyped(char_1, int_1))
  273. return true;
  274. return super.charTyped(char_1, int_1);
  275. }
  276. public void offset(double value, boolean animated) {
  277. scrollTo(target + value, animated);
  278. }
  279. public void scrollTo(double value, boolean animated) {
  280. scrollTo(value, animated, ClothConfigInitializer.getScrollDuration());
  281. }
  282. public void scrollTo(double value, boolean animated, long duration) {
  283. target = ClothConfigInitializer.clamp(value, getMaxScroll());
  284. if (animated) {
  285. start = System.currentTimeMillis();
  286. this.duration = duration;
  287. } else
  288. scroll = target;
  289. }
  290. @Override
  291. public boolean mouseScrolled(double double_1, double double_2, double double_3) {
  292. double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight());
  293. if (scrollListBounds.contains(double_1, double_2) && height > scrollListBounds.height - 2) {
  294. offset(ClothConfigInitializer.getScrollStep() * -double_3, true);
  295. if (scrollBarAlphaFuture == 0)
  296. scrollBarAlphaFuture = 1f;
  297. if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f)
  298. scrollBarAlphaFutureTime = System.currentTimeMillis();
  299. return true;
  300. }
  301. for (Element listener : children())
  302. if (listener.mouseScrolled(double_1, double_2, double_3))
  303. return true;
  304. if (bounds.contains(PointHelper.fromMouse())) {
  305. if (double_3 < 0 && categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  306. selectedRecipeIndex++;
  307. if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size())
  308. selectedRecipeIndex = 0;
  309. init();
  310. } else if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  311. selectedRecipeIndex--;
  312. if (selectedRecipeIndex < 0)
  313. selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1;
  314. init();
  315. return true;
  316. }
  317. }
  318. return super.mouseScrolled(double_1, double_2, double_3);
  319. }
  320. private double getMaxScrollPosition() {
  321. return CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight());
  322. }
  323. @Override
  324. public void render(int mouseX, int mouseY, float delta) {
  325. if (ConfigObject.getInstance().doesVillagerScreenHavePermanentScrollBar()) {
  326. scrollBarAlphaFutureTime = System.currentTimeMillis();
  327. scrollBarAlphaFuture = 0;
  328. scrollBarAlpha = 1;
  329. } else if (scrollBarAlphaFutureTime > 0) {
  330. long l = System.currentTimeMillis() - scrollBarAlphaFutureTime;
  331. if (l > 300f) {
  332. if (scrollBarAlphaFutureTime == 0) {
  333. scrollBarAlpha = scrollBarAlphaFuture;
  334. scrollBarAlphaFutureTime = -1;
  335. } else if (l > 2000f && scrollBarAlphaFuture == 1) {
  336. scrollBarAlphaFuture = 0;
  337. scrollBarAlphaFutureTime = System.currentTimeMillis();
  338. } else
  339. scrollBarAlpha = scrollBarAlphaFuture;
  340. } else {
  341. if (scrollBarAlphaFuture == 0)
  342. scrollBarAlpha = Math.min(scrollBarAlpha, 1 - Math.min(1f, l / 300f));
  343. else if (scrollBarAlphaFuture == 1)
  344. scrollBarAlpha = Math.max(Math.min(1f, l / 300f), scrollBarAlpha);
  345. }
  346. }
  347. updatePosition(delta);
  348. this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
  349. int yOffset = 0;
  350. for (Widget widget : widgets) {
  351. widget.render(mouseX, mouseY, delta);
  352. }
  353. ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta);
  354. RenderSystem.pushMatrix();
  355. ScissorsHandler.INSTANCE.scissor(new Rectangle(0, scrollListBounds.y + 1, width, scrollListBounds.height - 2));
  356. for (ButtonWidget buttonWidget : buttonWidgets) {
  357. buttonWidget.getBounds().y = scrollListBounds.y + 1 + yOffset - (int) scroll;
  358. if (buttonWidget.getBounds().getMaxY() > scrollListBounds.getMinY() && buttonWidget.getBounds().getMinY() < scrollListBounds.getMaxY()) {
  359. buttonWidget.render(mouseX, mouseY, delta);
  360. }
  361. yOffset += buttonWidget.getBounds().height;
  362. }
  363. for (int i = 0; i < buttonWidgets.size(); i++) {
  364. if (buttonWidgets.get(i).getBounds().getMaxY() > scrollListBounds.getMinY() && buttonWidgets.get(i).getBounds().getMinY() < scrollListBounds.getMaxY()) {
  365. recipeRenderers.get(i).setZ(1);
  366. recipeRenderers.get(i).render(buttonWidgets.get(i).getBounds(), mouseX, mouseY, delta);
  367. ScreenHelper.getLastOverlay().addTooltip(recipeRenderers.get(i).getTooltip(mouseX, mouseY));
  368. }
  369. }
  370. double maxScroll = getMaxScrollPosition();
  371. if (maxScroll > scrollListBounds.height - 2) {
  372. Tessellator tessellator = Tessellator.getInstance();
  373. BufferBuilder buffer = tessellator.getBuffer();
  374. int height = (int) (((scrollListBounds.height - 2) * (scrollListBounds.height - 2)) / this.getMaxScrollPosition());
  375. height = MathHelper.clamp(height, 32, scrollListBounds.height - 2 - 8);
  376. height -= Math.min((scroll < 0 ? (int) -scroll : scroll > getMaxScroll() ? (int) scroll - getMaxScroll() : 0), height * .95);
  377. height = Math.max(10, height);
  378. int minY = (int) Math.min(Math.max((int) scroll * (scrollListBounds.height - 2 - height) / getMaxScroll() + scrollListBounds.y + 1, scrollListBounds.y + 1), scrollListBounds.getMaxY() - 1 - height);
  379. int scrollbarPositionMinX = scrollListBounds.getMaxX() - 6, scrollbarPositionMaxX = scrollListBounds.getMaxX() - 1;
  380. boolean hovered = (new Rectangle(scrollbarPositionMinX, minY, scrollbarPositionMaxX - scrollbarPositionMinX, height)).contains(PointHelper.fromMouse());
  381. float bottomC = (hovered ? .67f : .5f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f);
  382. float topC = (hovered ? .87f : .67f) * (ScreenHelper.isDarkModeEnabled() ? 0.8f : 1f);
  383. RenderSystem.disableTexture();
  384. RenderSystem.enableBlend();
  385. RenderSystem.disableAlphaTest();
  386. RenderSystem.blendFuncSeparate(770, 771, 1, 0);
  387. RenderSystem.shadeModel(7425);
  388. buffer.begin(7, VertexFormats.POSITION_COLOR);
  389. buffer.vertex(scrollbarPositionMinX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next();
  390. buffer.vertex(scrollbarPositionMaxX, minY + height, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next();
  391. buffer.vertex(scrollbarPositionMaxX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next();
  392. buffer.vertex(scrollbarPositionMinX, minY, 800).color(bottomC, bottomC, bottomC, scrollBarAlpha).next();
  393. tessellator.draw();
  394. buffer.begin(7, VertexFormats.POSITION_COLOR);
  395. buffer.vertex(scrollbarPositionMinX, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next();
  396. buffer.vertex(scrollbarPositionMaxX - 1, minY + height - 1, 800).color(topC, topC, topC, scrollBarAlpha).next();
  397. buffer.vertex(scrollbarPositionMaxX - 1, minY, 800).color(topC, topC, topC, scrollBarAlpha).next();
  398. buffer.vertex(scrollbarPositionMinX, minY, 800).color(topC, topC, topC, scrollBarAlpha).next();
  399. tessellator.draw();
  400. RenderSystem.shadeModel(7424);
  401. RenderSystem.disableBlend();
  402. RenderSystem.enableAlphaTest();
  403. RenderSystem.enableTexture();
  404. }
  405. ScissorsHandler.INSTANCE.removeLastScissor();
  406. RenderSystem.popMatrix();
  407. ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta);
  408. }
  409. private void updatePosition(float delta) {
  410. double[] target = new double[]{this.target};
  411. this.scroll = ClothConfigInitializer.handleScrollingPosition(target, this.scroll, this.getMaxScroll(), delta, this.start, this.duration);
  412. this.target = target[0];
  413. }
  414. @Override
  415. public boolean mouseDragged(double mouseX, double mouseY, int int_1, double double_3, double double_4) {
  416. if (int_1 == 0 && scrollBarAlpha > 0 && draggingScrollBar) {
  417. double height = CollectionUtils.sumInt(buttonWidgets, b -> b.getBounds().getHeight());
  418. int actualHeight = scrollListBounds.height - 2;
  419. if (height > actualHeight && mouseY >= scrollListBounds.y + 1 && mouseY <= scrollListBounds.getMaxY() - 1) {
  420. int int_3 = MathHelper.clamp((int) ((actualHeight * actualHeight) / height), 32, actualHeight - 8);
  421. double double_6 = Math.max(1.0D, Math.max(1d, height) / (double) (actualHeight - int_3));
  422. scrollBarAlphaFutureTime = System.currentTimeMillis();
  423. scrollBarAlphaFuture = 1f;
  424. scroll = target = MathHelper.clamp(scroll + double_4 * double_6, 0, height - scrollListBounds.height + 2);
  425. return true;
  426. }
  427. }
  428. return super.mouseDragged(mouseX, mouseY, int_1, double_3, double_4);
  429. }
  430. @Override
  431. public boolean keyPressed(int int_1, int int_2, int int_3) {
  432. if (int_1 == 258) {
  433. boolean boolean_1 = !hasShiftDown();
  434. if (!this.changeFocus(boolean_1))
  435. this.changeFocus(boolean_1);
  436. return true;
  437. }
  438. if (ConfigObject.getInstance().getNextPageKeybind().matchesKey(int_1, int_2)) {
  439. if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  440. selectedRecipeIndex++;
  441. if (selectedRecipeIndex >= categoryMap.get(categories.get(selectedCategoryIndex)).size())
  442. selectedRecipeIndex = 0;
  443. init();
  444. return true;
  445. }
  446. return false;
  447. } else if (ConfigObject.getInstance().getPreviousPageKeybind().matchesKey(int_1, int_2)) {
  448. if (categoryMap.get(categories.get(selectedCategoryIndex)).size() > 1) {
  449. selectedRecipeIndex--;
  450. if (selectedRecipeIndex < 0)
  451. selectedRecipeIndex = categoryMap.get(categories.get(selectedCategoryIndex)).size() - 1;
  452. init();
  453. return true;
  454. }
  455. return false;
  456. }
  457. for (Element element : children())
  458. if (element.keyPressed(int_1, int_2, int_3))
  459. return true;
  460. if (int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) {
  461. MinecraftClient.getInstance().openScreen(ScreenHelper.getLastContainerScreen());
  462. ScreenHelper.getLastOverlay().init();
  463. return true;
  464. }
  465. if (int_1 == 259) {
  466. if (ScreenHelper.hasLastRecipeScreen())
  467. minecraft.openScreen(ScreenHelper.getLastRecipeScreen());
  468. else
  469. minecraft.openScreen(ScreenHelper.getLastContainerScreen());
  470. return true;
  471. }
  472. return super.keyPressed(int_1, int_2, int_3);
  473. }
  474. }