RecipeViewingScreen.java 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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.mojang.blaze3d.systems.RenderSystem;
  8. import me.shedaniel.math.api.Point;
  9. import me.shedaniel.math.api.Rectangle;
  10. import me.shedaniel.math.impl.PointHelper;
  11. import me.shedaniel.rei.api.*;
  12. import me.shedaniel.rei.gui.widget.*;
  13. import me.shedaniel.rei.impl.ScreenHelper;
  14. import me.shedaniel.rei.utils.CollectionUtils;
  15. import net.minecraft.client.MinecraftClient;
  16. import net.minecraft.client.gui.Element;
  17. import net.minecraft.client.gui.screen.Screen;
  18. import net.minecraft.client.resource.language.I18n;
  19. import net.minecraft.client.sound.PositionedSoundInstance;
  20. import net.minecraft.client.util.Window;
  21. import net.minecraft.sound.SoundEvents;
  22. import net.minecraft.text.LiteralText;
  23. import net.minecraft.util.Formatting;
  24. import net.minecraft.util.Identifier;
  25. import net.minecraft.util.math.MathHelper;
  26. import org.jetbrains.annotations.ApiStatus;
  27. import org.jetbrains.annotations.Nullable;
  28. import java.util.*;
  29. import java.util.function.Supplier;
  30. @ApiStatus.Internal
  31. public class RecipeViewingScreen extends Screen {
  32. public static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
  33. private final List<Widget> preWidgets;
  34. private final List<Widget> widgets;
  35. private final List<TabWidget> tabs;
  36. private final Map<RecipeCategory<?>, List<RecipeDisplay>> categoriesMap;
  37. private final List<RecipeCategory<?>> categories;
  38. public int guiWidth;
  39. public int guiHeight;
  40. public int page, categoryPages;
  41. public int largestWidth, largestHeight;
  42. public boolean choosePageActivated;
  43. public RecipeChoosePageWidget recipeChoosePageWidget;
  44. private int tabsPerPage = 5;
  45. private Rectangle bounds;
  46. @Nullable private CategoryBaseWidget workingStationsBaseWidget;
  47. private RecipeCategory<RecipeDisplay> selectedCategory;
  48. private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext;
  49. private EntryStack mainStackToNotice = EntryStack.empty();
  50. public RecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> categoriesMap) {
  51. super(new LiteralText(""));
  52. this.categoryPages = 0;
  53. this.preWidgets = Lists.newArrayList();
  54. this.widgets = Lists.newArrayList();
  55. Window window = MinecraftClient.getInstance().getWindow();
  56. this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 150);
  57. this.categoriesMap = categoriesMap;
  58. this.categories = Lists.newArrayList();
  59. for (RecipeCategory<?> category : RecipeHelper.getInstance().getAllCategories()) {
  60. if (categoriesMap.containsKey(category))
  61. categories.add(category);
  62. }
  63. this.selectedCategory = (RecipeCategory<RecipeDisplay>) categories.get(0);
  64. this.tabs = new ArrayList<>();
  65. this.choosePageActivated = false;
  66. }
  67. static void transformNotice(List<Widget> setupDisplay, EntryStack mainStackToNotice) {
  68. if (mainStackToNotice.isEmpty())
  69. return;
  70. for (Widget widget : setupDisplay) {
  71. if (widget instanceof EntryWidget) {
  72. EntryWidget entry = (EntryWidget) widget;
  73. if (entry.entries().size() > 1) {
  74. EntryStack stack = CollectionUtils.firstOrNullEqualsAll(entry.entries(), mainStackToNotice);
  75. if (stack != null) {
  76. entry.clearStacks();
  77. entry.entry(stack);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. public void addMainStackToNotice(EntryStack stack) {
  84. this.mainStackToNotice = stack;
  85. }
  86. @Nullable
  87. public CategoryBaseWidget getWorkingStationsBaseWidget() {
  88. return workingStationsBaseWidget;
  89. }
  90. @Override
  91. public boolean keyPressed(int int_1, int int_2, int int_3) {
  92. if (int_1 == 256 && choosePageActivated) {
  93. choosePageActivated = false;
  94. init();
  95. return true;
  96. }
  97. if ((int_1 == 256 || this.minecraft.options.keyInventory.matchesKey(int_1, int_2)) && this.shouldCloseOnEsc()) {
  98. MinecraftClient.getInstance().openScreen(ScreenHelper.getLastContainerScreen());
  99. ScreenHelper.getLastOverlay().init();
  100. return true;
  101. }
  102. if (int_1 == 258) {
  103. boolean boolean_1 = !hasShiftDown();
  104. if (!this.changeFocus(boolean_1))
  105. this.changeFocus(boolean_1);
  106. return true;
  107. }
  108. if (choosePageActivated)
  109. return recipeChoosePageWidget.keyPressed(int_1, int_2, int_3);
  110. else if (ConfigObject.getInstance().getNextPageKeybind().matchesKey(int_1, int_2)) {
  111. if (recipeNext.enabled)
  112. recipeNext.onPressed();
  113. return recipeNext.enabled;
  114. } else if (ConfigObject.getInstance().getPreviousPageKeybind().matchesKey(int_1, int_2)) {
  115. if (recipeBack.enabled)
  116. recipeBack.onPressed();
  117. return recipeBack.enabled;
  118. }
  119. for (Element element : children())
  120. if (element.keyPressed(int_1, int_2, int_3))
  121. return true;
  122. if (int_1 == 259) {
  123. if (ScreenHelper.hasLastRecipeScreen())
  124. minecraft.openScreen(ScreenHelper.getLastRecipeScreen());
  125. else
  126. minecraft.openScreen(ScreenHelper.getLastContainerScreen());
  127. return true;
  128. }
  129. return super.keyPressed(int_1, int_2, int_3);
  130. }
  131. @Override
  132. public boolean isPauseScreen() {
  133. return false;
  134. }
  135. @Override
  136. public void init() {
  137. super.init();
  138. boolean isCompactTabs = ConfigObject.getInstance().isUsingCompactTabs();
  139. int tabSize = isCompactTabs ? 24 : 28;
  140. this.children.clear();
  141. this.tabs.clear();
  142. this.preWidgets.clear();
  143. this.widgets.clear();
  144. this.largestWidth = width - 100;
  145. this.largestHeight = Math.max(height - 36, 100);
  146. int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), display -> selectedCategory.getDisplayWidth(display), (Comparator<Integer>) Comparator.naturalOrder()).orElse(150);
  147. this.guiWidth = maxWidthDisplay + 20;
  148. this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight));
  149. this.tabsPerPage = Math.max(5, MathHelper.floor((guiWidth - 20d) / tabSize));
  150. this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight);
  151. this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1);
  152. ButtonWidget w, w2;
  153. this.widgets.add(w = new ButtonWidget(new Rectangle(bounds.x + 2, bounds.y - 16, 10, 10), I18n.translate("text.rei.left_arrow")) {
  154. @Override
  155. public void onPressed() {
  156. categoryPages--;
  157. if (categoryPages < 0)
  158. categoryPages = MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1;
  159. RecipeViewingScreen.this.init();
  160. }
  161. });
  162. this.widgets.add(w2 = new ButtonWidget(new Rectangle(bounds.x + bounds.width - 12, bounds.y - 16, 10, 10), I18n.translate("text.rei.right_arrow")) {
  163. @Override
  164. public void onPressed() {
  165. categoryPages++;
  166. if (categoryPages > MathHelper.ceil(categories.size() / (float) tabsPerPage) - 1)
  167. categoryPages = 0;
  168. RecipeViewingScreen.this.init();
  169. }
  170. });
  171. w.enabled = w2.enabled = categories.size() > tabsPerPage;
  172. widgets.add(categoryBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.left_arrow")) {
  173. @Override
  174. public void onPressed() {
  175. int currentCategoryIndex = categories.indexOf(selectedCategory);
  176. currentCategoryIndex--;
  177. if (currentCategoryIndex < 0)
  178. currentCategoryIndex = categories.size() - 1;
  179. selectedCategory = (RecipeCategory<RecipeDisplay>) categories.get(currentCategoryIndex);
  180. categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage);
  181. page = 0;
  182. RecipeViewingScreen.this.init();
  183. }
  184. @Override
  185. public Optional<String> getTooltips() {
  186. return Optional.ofNullable(I18n.translate("text.rei.previous_category"));
  187. }
  188. });
  189. widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 7), "") {
  190. @Override
  191. public void render(int mouseX, int mouseY, float delta) {
  192. setText(selectedCategory.getCategoryName());
  193. super.render(mouseX, mouseY, delta);
  194. }
  195. @Override
  196. public Optional<String> getTooltips() {
  197. return Optional.ofNullable(I18n.translate("text.rei.view_all_categories"));
  198. }
  199. @Override
  200. public void onLabelClicked() {
  201. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  202. ClientHelper.getInstance().executeViewAllRecipesKeyBind();
  203. }
  204. });
  205. widgets.add(categoryNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 5, 12, 12), I18n.translate("text.rei.right_arrow")) {
  206. @Override
  207. public void onPressed() {
  208. int currentCategoryIndex = categories.indexOf(selectedCategory);
  209. currentCategoryIndex++;
  210. if (currentCategoryIndex >= categories.size())
  211. currentCategoryIndex = 0;
  212. selectedCategory = (RecipeCategory<RecipeDisplay>) categories.get(currentCategoryIndex);
  213. categoryPages = MathHelper.floor(currentCategoryIndex / (double) tabsPerPage);
  214. page = 0;
  215. RecipeViewingScreen.this.init();
  216. }
  217. @Override
  218. public Optional<String> getTooltips() {
  219. return Optional.ofNullable(I18n.translate("text.rei.next_category"));
  220. }
  221. });
  222. categoryBack.enabled = categories.size() > 1;
  223. categoryNext.enabled = categories.size() > 1;
  224. widgets.add(recipeBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.left_arrow")) {
  225. @Override
  226. public void onPressed() {
  227. page--;
  228. if (page < 0)
  229. page = getTotalPages(selectedCategory) - 1;
  230. RecipeViewingScreen.this.init();
  231. }
  232. @Override
  233. public Optional<String> getTooltips() {
  234. return Optional.ofNullable(I18n.translate("text.rei.previous_page"));
  235. }
  236. });
  237. widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 21), "") {
  238. @Override
  239. public void render(int mouseX, int mouseY, float delta) {
  240. setText(String.format("%d/%d", page + 1, getTotalPages(selectedCategory)));
  241. super.render(mouseX, mouseY, delta);
  242. }
  243. @Override
  244. public Optional<String> getTooltips() {
  245. return Optional.ofNullable(I18n.translate("text.rei.choose_page"));
  246. }
  247. @Override
  248. public void onLabelClicked() {
  249. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  250. RecipeViewingScreen.this.choosePageActivated = true;
  251. RecipeViewingScreen.this.init();
  252. }
  253. }.clickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight()));
  254. widgets.add(recipeNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.right_arrow")) {
  255. @Override
  256. public void onPressed() {
  257. page++;
  258. if (page >= getTotalPages(selectedCategory))
  259. page = 0;
  260. RecipeViewingScreen.this.init();
  261. }
  262. @Override
  263. public Optional<String> getTooltips() {
  264. return Optional.ofNullable(I18n.translate("text.rei.next_page"));
  265. }
  266. });
  267. recipeBack.enabled = recipeNext.enabled = categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight();
  268. int tabV = isCompactTabs ? 166 : 192;
  269. for (int i = 0; i < tabsPerPage; i++) {
  270. int j = i + categoryPages * tabsPerPage;
  271. if (categories.size() > j) {
  272. TabWidget tab;
  273. tabs.add(tab = new TabWidget(i, tabSize, bounds.x + bounds.width / 2 - Math.min(categories.size() - categoryPages * tabsPerPage, tabsPerPage) * tabSize / 2, bounds.y, 0, tabV) {
  274. @Override
  275. public boolean mouseClicked(double mouseX, double mouseY, int button) {
  276. if (containsMouse(mouseX, mouseY)) {
  277. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  278. if (getId() + categoryPages * tabsPerPage == categories.indexOf(selectedCategory))
  279. return false;
  280. selectedCategory = (RecipeCategory<RecipeDisplay>) categories.get(getId() + categoryPages * tabsPerPage);
  281. page = 0;
  282. RecipeViewingScreen.this.init();
  283. return true;
  284. }
  285. return false;
  286. }
  287. });
  288. tab.setRenderer(categories.get(j), categories.get(j).getLogo(), categories.get(j).getCategoryName(), tab.getId() + categoryPages * tabsPerPage == categories.indexOf(selectedCategory));
  289. }
  290. }
  291. Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(selectedCategory);
  292. int recipeHeight = selectedCategory.getDisplayHeight();
  293. List<RecipeDisplay> currentDisplayed = getCurrentDisplayed();
  294. for (int i = 0; i < currentDisplayed.size(); i++) {
  295. int finalI = i;
  296. final Supplier<RecipeDisplay> displaySupplier = () -> currentDisplayed.get(finalI);
  297. int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get());
  298. final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().y - 2 + 36 + recipeHeight * i + 4 * i, displayWidth, recipeHeight);
  299. List<Widget> setupDisplay = selectedCategory.setupDisplay(displaySupplier, displayBounds);
  300. transformNotice(setupDisplay, mainStackToNotice);
  301. this.widgets.addAll(setupDisplay);
  302. if (supplier.isPresent() && supplier.get().get(displayBounds) != null)
  303. this.widgets.add(new AutoCraftingButtonWidget(displayBounds, supplier.get().get(displayBounds), supplier.get().getButtonText(), displaySupplier, setupDisplay, selectedCategory));
  304. }
  305. if (choosePageActivated)
  306. recipeChoosePageWidget = new RecipeChoosePageWidget(this, page, getTotalPages(selectedCategory));
  307. else
  308. recipeChoosePageWidget = null;
  309. workingStationsBaseWidget = null;
  310. List<List<EntryStack>> workingStations = RecipeHelper.getInstance().getWorkingStations(selectedCategory.getIdentifier());
  311. if (!workingStations.isEmpty()) {
  312. int hh = MathHelper.floor((bounds.height - 16) / 18f);
  313. int actualHeight = Math.min(hh, workingStations.size());
  314. int innerWidth = MathHelper.ceil(workingStations.size() / ((float) hh));
  315. int xx = bounds.x - (8 + innerWidth * 16) + 6;
  316. int yy = bounds.y + 16;
  317. preWidgets.add(workingStationsBaseWidget = new CategoryBaseWidget(new Rectangle(xx - 5, yy - 5, 15 + innerWidth * 16, 10 + actualHeight * 16)));
  318. preWidgets.add(new SlotBaseWidget(new Rectangle(xx - 1, yy - 1, innerWidth * 16 + 2, actualHeight * 16 + 2)));
  319. int index = 0;
  320. List<String> list = Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("text.rei.working_station"));
  321. xx += (innerWidth - 1) * 16;
  322. for (List<EntryStack> workingStation : workingStations) {
  323. preWidgets.add(new WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list))));
  324. index++;
  325. yy += 16;
  326. if (index >= hh) {
  327. index = 0;
  328. yy = bounds.y + 16;
  329. xx -= 16;
  330. }
  331. }
  332. }
  333. children.addAll(tabs);
  334. children.add(ScreenHelper.getLastOverlay(true, false));
  335. children.addAll(widgets);
  336. children.addAll(preWidgets);
  337. }
  338. public List<Widget> getWidgets() {
  339. return widgets;
  340. }
  341. public List<RecipeDisplay> getCurrentDisplayed() {
  342. List<RecipeDisplay> list = Lists.newArrayList();
  343. int recipesPerPage = getRecipesPerPage();
  344. for (int i = 0; i <= recipesPerPage; i++)
  345. if (page * (recipesPerPage + 1) + i < categoriesMap.get(selectedCategory).size())
  346. list.add(categoriesMap.get(selectedCategory).get(page * (recipesPerPage + 1) + i));
  347. return list;
  348. }
  349. public RecipeCategory<RecipeDisplay> getSelectedCategory() {
  350. return selectedCategory;
  351. }
  352. public int getPage() {
  353. return page;
  354. }
  355. public int getCategoryPage() {
  356. return categoryPages;
  357. }
  358. private int getRecipesPerPage() {
  359. if (selectedCategory.getFixedRecipesPerPage() > 0)
  360. return selectedCategory.getFixedRecipesPerPage() - 1;
  361. int height = selectedCategory.getDisplayHeight();
  362. return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 36) / ((double) height + 4)) - 1, 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1));
  363. }
  364. private int getRecipesPerPageByHeight() {
  365. int height = selectedCategory.getDisplayHeight();
  366. return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 36) / ((double) height + 4)), 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1));
  367. }
  368. @Override
  369. public void render(int mouseX, int mouseY, float delta) {
  370. this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
  371. for (Widget widget : preWidgets) {
  372. widget.render(mouseX, mouseY, delta);
  373. }
  374. if (selectedCategory != null)
  375. selectedCategory.drawCategoryBackground(bounds, mouseX, mouseY, delta);
  376. else {
  377. PanelWidget.render(bounds, -1);
  378. if (ScreenHelper.isDarkModeEnabled()) {
  379. fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF404040);
  380. fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 30, 0xFF404040);
  381. } else {
  382. fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF9E9E9E);
  383. fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, 0xFF9E9E9E);
  384. }
  385. }
  386. for (TabWidget tab : tabs) {
  387. if (!tab.isSelected())
  388. tab.render(mouseX, mouseY, delta);
  389. }
  390. super.render(mouseX, mouseY, delta);
  391. for (Widget widget : widgets) {
  392. widget.render(mouseX, mouseY, delta);
  393. }
  394. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  395. for (TabWidget tab : tabs) {
  396. if (tab.isSelected())
  397. tab.render(mouseX, mouseY, delta);
  398. }
  399. ScreenHelper.getLastOverlay().render(mouseX, mouseY, delta);
  400. ScreenHelper.getLastOverlay().lateRender(mouseX, mouseY, delta);
  401. if (choosePageActivated) {
  402. setBlitOffset(500);
  403. this.fillGradient(0, 0, this.width, this.height, -1072689136, -804253680);
  404. setBlitOffset(0);
  405. recipeChoosePageWidget.render(mouseX, mouseY, delta);
  406. }
  407. }
  408. public int getTotalPages(RecipeCategory<RecipeDisplay> category) {
  409. return MathHelper.ceil(categoriesMap.get(category).size() / (double) (getRecipesPerPage() + 1));
  410. }
  411. public Rectangle getBounds() {
  412. return bounds;
  413. }
  414. @Override
  415. public boolean charTyped(char char_1, int int_1) {
  416. if (choosePageActivated) {
  417. return recipeChoosePageWidget.charTyped(char_1, int_1);
  418. }
  419. for (Element listener : children())
  420. if (listener.charTyped(char_1, int_1))
  421. return true;
  422. return super.charTyped(char_1, int_1);
  423. }
  424. @Override
  425. public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
  426. if (choosePageActivated) {
  427. return recipeChoosePageWidget.mouseDragged(double_1, double_2, int_1, double_3, double_4);
  428. }
  429. return super.mouseDragged(double_1, double_2, int_1, double_3, double_4);
  430. }
  431. @Override
  432. public boolean mouseReleased(double double_1, double double_2, int int_1) {
  433. if (choosePageActivated) {
  434. return recipeChoosePageWidget.mouseReleased(double_1, double_2, int_1);
  435. }
  436. return super.mouseReleased(double_1, double_2, int_1);
  437. }
  438. @Override
  439. public boolean mouseScrolled(double i, double j, double amount) {
  440. for (Element listener : children())
  441. if (listener.mouseScrolled(i, j, amount))
  442. return true;
  443. if (getBounds().contains(PointHelper.fromMouse())) {
  444. if (amount > 0 && recipeBack.enabled)
  445. recipeBack.onPressed();
  446. else if (amount < 0 && recipeNext.enabled)
  447. recipeNext.onPressed();
  448. }
  449. if ((new Rectangle(bounds.x, bounds.y - 28, bounds.width, 28)).contains(PointHelper.fromMouse())) {
  450. if (amount > 0 && categoryBack.enabled)
  451. categoryBack.onPressed();
  452. else if (amount < 0 && categoryNext.enabled)
  453. categoryNext.onPressed();
  454. }
  455. return super.mouseScrolled(i, j, amount);
  456. }
  457. @Override
  458. public boolean mouseClicked(double double_1, double double_2, int int_1) {
  459. if (choosePageActivated)
  460. if (recipeChoosePageWidget.containsMouse(double_1, double_2)) {
  461. return recipeChoosePageWidget.mouseClicked(double_1, double_2, int_1);
  462. } else {
  463. choosePageActivated = false;
  464. init();
  465. return false;
  466. }
  467. for (Element entry : children())
  468. if (entry.mouseClicked(double_1, double_2, int_1)) {
  469. setFocused(entry);
  470. if (int_1 == 0)
  471. setDragging(true);
  472. return true;
  473. }
  474. return false;
  475. }
  476. @Override
  477. public Element getFocused() {
  478. if (choosePageActivated)
  479. return recipeChoosePageWidget;
  480. return super.getFocused();
  481. }
  482. public static class WorkstationSlotWidget extends EntryWidget {
  483. public WorkstationSlotWidget(int x, int y, List<EntryStack> widgets) {
  484. super(new Point(x, y));
  485. entries(widgets);
  486. noBackground();
  487. }
  488. @Override
  489. public boolean containsMouse(double mouseX, double mouseY) {
  490. return getInnerBounds().contains(mouseX, mouseY);
  491. }
  492. }
  493. }