ContainerScreenOverlay.java 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  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.RoughlyEnoughItemsCore;
  12. import me.shedaniel.rei.api.*;
  13. import me.shedaniel.rei.gui.config.SearchFieldLocation;
  14. import me.shedaniel.rei.gui.widget.*;
  15. import me.shedaniel.rei.impl.ScreenHelper;
  16. import me.shedaniel.rei.impl.Weather;
  17. import me.shedaniel.rei.listeners.ContainerScreenHooks;
  18. import me.shedaniel.rei.utils.CollectionUtils;
  19. import net.minecraft.client.MinecraftClient;
  20. import net.minecraft.client.gui.Element;
  21. import net.minecraft.client.gui.screen.Screen;
  22. import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
  23. import net.minecraft.client.render.GuiLighting;
  24. import net.minecraft.client.render.Tessellator;
  25. import net.minecraft.client.render.VertexConsumerProvider;
  26. import net.minecraft.client.resource.language.I18n;
  27. import net.minecraft.client.sound.PositionedSoundInstance;
  28. import net.minecraft.client.util.Window;
  29. import net.minecraft.client.util.math.Matrix4f;
  30. import net.minecraft.client.util.math.MatrixStack;
  31. import net.minecraft.client.world.ClientWorld;
  32. import net.minecraft.container.Slot;
  33. import net.minecraft.item.ItemStack;
  34. import net.minecraft.sound.SoundEvents;
  35. import net.minecraft.util.ActionResult;
  36. import net.minecraft.util.Identifier;
  37. import net.minecraft.util.math.MathHelper;
  38. import net.minecraft.world.GameMode;
  39. import org.apache.logging.log4j.util.TriConsumer;
  40. import javax.annotation.Nullable;
  41. import java.util.*;
  42. public class ContainerScreenOverlay extends Widget {
  43. private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png");
  44. private static final List<QueuedTooltip> QUEUED_TOOLTIPS = Lists.newArrayList();
  45. public static String searchTerm = "";
  46. private static int page = 0;
  47. private static EntryListWidget entryListWidget;
  48. private final List<Widget> widgets = Lists.newLinkedList();
  49. public boolean shouldReInit = false;
  50. private int tooltipWidth;
  51. private int tooltipHeight;
  52. private List<String> tooltipLines;
  53. public final TriConsumer<Integer, Integer, Float> renderTooltipCallback = (x, y, aFloat) -> {
  54. RenderSystem.disableRescaleNormal();
  55. RenderSystem.disableDepthTest();
  56. setBlitOffset(999);
  57. this.fillGradient(x - 3, y - 4, x + tooltipWidth + 3, y - 3, -267386864, -267386864);
  58. this.fillGradient(x - 3, y + tooltipHeight + 3, x + tooltipWidth + 3, y + tooltipHeight + 4, -267386864, -267386864);
  59. this.fillGradient(x - 3, y - 3, x + tooltipWidth + 3, y + tooltipHeight + 3, -267386864, -267386864);
  60. this.fillGradient(x - 4, y - 3, x - 3, y + tooltipHeight + 3, -267386864, -267386864);
  61. this.fillGradient(x + tooltipWidth + 3, y - 3, x + tooltipWidth + 4, y + tooltipHeight + 3, -267386864, -267386864);
  62. this.fillGradient(x - 3, y - 3 + 1, x - 3 + 1, y + tooltipHeight + 3 - 1, 1347420415, 1344798847);
  63. this.fillGradient(x + tooltipWidth + 2, y - 3 + 1, x + tooltipWidth + 3, y + tooltipHeight + 3 - 1, 1347420415, 1344798847);
  64. this.fillGradient(x - 3, y - 3, x + tooltipWidth + 3, y - 3 + 1, 1347420415, 1347420415);
  65. this.fillGradient(x - 3, y + tooltipHeight + 2, x + tooltipWidth + 3, y + tooltipHeight + 3, 1344798847, 1344798847);
  66. int currentY = y;
  67. MatrixStack matrixStack_1 = new MatrixStack();
  68. VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer());
  69. matrixStack_1.translate(0.0D, 0.0D, getBlitOffset());
  70. Matrix4f matrix4f_1 = matrixStack_1.peek().getModel();
  71. for (int lineIndex = 0; lineIndex < tooltipLines.size(); lineIndex++) {
  72. font.draw(tooltipLines.get(lineIndex), x, currentY, -1, true, matrix4f_1, immediate, false, 0, 15728880);
  73. currentY += lineIndex == 0 ? 12 : 10;
  74. }
  75. immediate.draw();
  76. setBlitOffset(0);
  77. RenderSystem.enableDepthTest();
  78. RenderSystem.enableRescaleNormal();
  79. };
  80. private Rectangle rectangle;
  81. private Window window;
  82. private CraftableToggleButtonWidget toggleButtonWidget;
  83. private ButtonWidget buttonLeft, buttonRight;
  84. public static EntryListWidget getEntryListWidget() {
  85. return entryListWidget;
  86. }
  87. public static void setPage(int page) {
  88. ContainerScreenOverlay.page = page;
  89. }
  90. public void init() {
  91. init(false);
  92. }
  93. @SuppressWarnings("deprecation")
  94. public void init(boolean setPage) {
  95. this.shouldReInit = false;
  96. //Update Variables
  97. this.children().clear();
  98. this.window = MinecraftClient.getInstance().getWindow();
  99. @SuppressWarnings({"RawTypeCanBeGeneric", "rawtypes"})
  100. DisplayHelper.DisplayBoundsHandler boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass());
  101. this.rectangle = ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen);
  102. widgets.add(entryListWidget = new EntryListWidget(page));
  103. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false);
  104. if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) {
  105. widgets.add(buttonLeft = new ButtonWidget(new Rectangle(rectangle.x, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.left_arrow")) {
  106. @Override
  107. public void onPressed() {
  108. page--;
  109. if (page < 0)
  110. page = getTotalPage();
  111. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false);
  112. }
  113. @Override
  114. public Optional<String> getTooltips() {
  115. return Optional.ofNullable(I18n.translate("text.rei.previous_page"));
  116. }
  117. @Override
  118. public boolean changeFocus(boolean boolean_1) {
  119. return false;
  120. }
  121. @Override
  122. public boolean containsMouse(double mouseX, double mouseY) {
  123. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  124. }
  125. });
  126. widgets.add(buttonRight = new ButtonWidget(new Rectangle(rectangle.x + rectangle.width - 18, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), I18n.translate("text.rei.right_arrow")) {
  127. @Override
  128. public void onPressed() {
  129. page++;
  130. if (page > getTotalPage())
  131. page = 0;
  132. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false);
  133. }
  134. @Override
  135. public Optional<String> getTooltips() {
  136. return Optional.ofNullable(I18n.translate("text.rei.next_page"));
  137. }
  138. @Override
  139. public boolean changeFocus(boolean boolean_1) {
  140. return false;
  141. }
  142. @Override
  143. public boolean containsMouse(double mouseX, double mouseY) {
  144. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  145. }
  146. });
  147. }
  148. if (setPage)
  149. page = MathHelper.clamp(page, 0, getTotalPage());
  150. widgets.add(new ButtonWidget(new Rectangle(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20), "") {
  151. @Override
  152. public void onPressed() {
  153. if (Screen.hasShiftDown()) {
  154. ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating());
  155. return;
  156. }
  157. ConfigManager.getInstance().openConfigScreen(ScreenHelper.getLastContainerScreen());
  158. }
  159. @Override
  160. public void render(int mouseX, int mouseY, float delta) {
  161. super.render(mouseX, mouseY, delta);
  162. GuiLighting.disable();
  163. Rectangle bounds = getBounds();
  164. if (ClientHelper.getInstance().isCheating() && RoughlyEnoughItemsCore.hasOperatorPermission()) {
  165. if (RoughlyEnoughItemsCore.hasPermissionToUsePackets())
  166. fill(bounds.x + 1, bounds.y + 1, bounds.getMaxX() - 1, bounds.getMaxY() - 1, 721354752);
  167. else
  168. fill(bounds.x + 1, bounds.y + 1, bounds.getMaxX() - 1, bounds.getMaxY() - 1, 1476440063);
  169. }
  170. MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
  171. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  172. blit(bounds.x + 3, bounds.y + 3, 0, 0, 14, 14);
  173. }
  174. @Override
  175. public Optional<String> getTooltips() {
  176. String tooltips = I18n.translate("text.rei.config_tooltip");
  177. tooltips += "\n ";
  178. if (!ClientHelper.getInstance().isCheating())
  179. tooltips += "\n" + I18n.translate("text.rei.cheating_disabled");
  180. else if (!RoughlyEnoughItemsCore.hasOperatorPermission())
  181. tooltips += "\n" + I18n.translate("text.rei.cheating_enabled_no_perms");
  182. else if (RoughlyEnoughItemsCore.hasPermissionToUsePackets())
  183. tooltips += "\n" + I18n.translate("text.rei.cheating_enabled");
  184. else
  185. tooltips += "\n" + I18n.translate("text.rei.cheating_limited_enabled");
  186. return Optional.ofNullable(tooltips);
  187. }
  188. @Override
  189. public boolean changeFocus(boolean boolean_1) {
  190. return false;
  191. }
  192. @Override
  193. public boolean containsMouse(double mouseX, double mouseY) {
  194. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  195. }
  196. });
  197. if (ConfigManager.getInstance().getConfig().doesShowUtilsButtons()) {
  198. widgets.add(new ButtonWidget(new Rectangle(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20), "") {
  199. @Override
  200. public void onPressed() {
  201. MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName()));
  202. }
  203. @Override
  204. public void render(int mouseX, int mouseY, float delta) {
  205. setText(getGameModeShortText(getCurrentGameMode()));
  206. super.render(mouseX, mouseY, delta);
  207. }
  208. @Override
  209. public Optional<String> getTooltips() {
  210. return Optional.ofNullable(I18n.translate("text.rei.gamemode_button.tooltip", getGameModeText(getNextGameMode(Screen.hasShiftDown()))));
  211. }
  212. @Override
  213. public boolean changeFocus(boolean boolean_1) {
  214. return false;
  215. }
  216. @Override
  217. public boolean containsMouse(double mouseX, double mouseY) {
  218. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  219. }
  220. });
  221. int xxx = ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10;
  222. for (Weather weather : Weather.values()) {
  223. widgets.add(new ButtonWidget(new Rectangle(xxx, 35, 20, 20), "") {
  224. @Override
  225. public void onPressed() {
  226. MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT)));
  227. }
  228. @Override
  229. public void render(int mouseX, int mouseY, float delta) {
  230. super.render(mouseX, mouseY, delta);
  231. GuiLighting.disable();
  232. MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE);
  233. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  234. blit(getBounds().x + 3, getBounds().y + 3, weather.getId() * 14, 14, 14, 14);
  235. }
  236. @Override
  237. public Optional<String> getTooltips() {
  238. return Optional.ofNullable(I18n.translate("text.rei.weather_button.tooltip", I18n.translate(weather.getTranslateKey())));
  239. }
  240. @Override
  241. public boolean changeFocus(boolean boolean_1) {
  242. return false;
  243. }
  244. @Override
  245. public boolean containsMouse(double mouseX, double mouseY) {
  246. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  247. }
  248. });
  249. xxx += ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? -25 : 25;
  250. }
  251. }
  252. if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) {
  253. widgets.add(new ClickableLabelWidget(new Point(rectangle.x + (rectangle.width / 2), rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), "") {
  254. @Override
  255. public void render(int mouseX, int mouseY, float delta) {
  256. page = MathHelper.clamp(page, 0, getTotalPage());
  257. setText(String.format("%s/%s", page + 1, getTotalPage() + 1));
  258. super.render(mouseX, mouseY, delta);
  259. }
  260. @Override
  261. public Optional<String> getTooltips() {
  262. return Optional.ofNullable(I18n.translate("text.rei.go_back_first_page"));
  263. }
  264. @Override
  265. public void onLabelClicked() {
  266. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  267. page = 0;
  268. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false);
  269. }
  270. @Override
  271. public boolean changeFocus(boolean boolean_1) {
  272. return false;
  273. }
  274. }.clickable(getTotalPage() > 0));
  275. buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0;
  276. }
  277. if (ScreenHelper.getSearchField() == null) {
  278. ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0));
  279. }
  280. ScreenHelper.getSearchField().getBounds().setBounds(getTextFieldArea());
  281. this.widgets.add(ScreenHelper.getSearchField());
  282. ScreenHelper.getSearchField().setText(searchTerm);
  283. ScreenHelper.getSearchField().setChangedListener(s -> {
  284. searchTerm = s;
  285. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true);
  286. });
  287. if (ConfigManager.getInstance().getConfig().isCraftableFilterEnabled())
  288. this.widgets.add(toggleButtonWidget = new CraftableToggleButtonWidget(getCraftableToggleArea()) {
  289. @Override
  290. public void onPressed() {
  291. ConfigManager.getInstance().toggleCraftableOnly();
  292. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true);
  293. }
  294. @Override
  295. public void lateRender(int mouseX, int mouseY, float delta) {
  296. setBlitOffset(300);
  297. super.lateRender(mouseX, mouseY, delta);
  298. }
  299. @Override
  300. public boolean containsMouse(double mouseX, double mouseY) {
  301. return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY);
  302. }
  303. });
  304. else
  305. toggleButtonWidget = null;
  306. this.entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false);
  307. }
  308. private Weather getNextWeather() {
  309. try {
  310. Weather current = getCurrentWeather();
  311. int next = current.getId() + 1;
  312. if (next >= 3)
  313. next = 0;
  314. return Weather.byId(next);
  315. } catch (Exception e) {
  316. return Weather.CLEAR;
  317. }
  318. }
  319. private Weather getCurrentWeather() {
  320. ClientWorld world = MinecraftClient.getInstance().world;
  321. if (world.isThundering())
  322. return Weather.THUNDER;
  323. if (world.getLevelProperties().isRaining())
  324. return Weather.RAIN;
  325. return Weather.CLEAR;
  326. }
  327. private String getGameModeShortText(GameMode gameMode) {
  328. return I18n.translate("text.rei.short_gamemode." + gameMode.getName());
  329. }
  330. private String getGameModeText(GameMode gameMode) {
  331. return I18n.translate("selectWorld.gameMode." + gameMode.getName());
  332. }
  333. private GameMode getNextGameMode(boolean reverse) {
  334. try {
  335. GameMode current = getCurrentGameMode();
  336. int next = current.getId() + 1;
  337. if (reverse)
  338. next -= 2;
  339. if (next > 3)
  340. next = 0;
  341. if (next < 0)
  342. next = 3;
  343. return GameMode.byId(next);
  344. } catch (Exception e) {
  345. return GameMode.NOT_SET;
  346. }
  347. }
  348. private GameMode getCurrentGameMode() {
  349. return MinecraftClient.getInstance().getNetworkHandler().getPlayerListEntry(MinecraftClient.getInstance().player.getGameProfile().getId()).getGameMode();
  350. }
  351. private Rectangle getTextFieldArea() {
  352. int widthRemoved = ConfigManager.getInstance().getConfig().isCraftableFilterEnabled() ? 22 : 2;
  353. SearchFieldLocation searchFieldLocation = ConfigManager.getInstance().getConfig().getSearchFieldLocation();
  354. if (searchFieldLocation == SearchFieldLocation.BOTTOM_SIDE)
  355. return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18);
  356. if (searchFieldLocation == SearchFieldLocation.TOP_SIDE)
  357. return new Rectangle(rectangle.x + 2, 4, rectangle.width - 6 - widthRemoved, 18);
  358. if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) {
  359. RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen;
  360. return new Rectangle(widget.getBounds().x, window.getScaledHeight() - 22, widget.getBounds().width - widthRemoved, 18);
  361. }
  362. if (MinecraftClient.getInstance().currentScreen instanceof VillagerRecipeViewingScreen) {
  363. VillagerRecipeViewingScreen widget = (VillagerRecipeViewingScreen) MinecraftClient.getInstance().currentScreen;
  364. return new Rectangle(widget.bounds.x, window.getScaledHeight() - 22, widget.bounds.width - widthRemoved, 18);
  365. }
  366. return new Rectangle(ScreenHelper.getLastContainerScreenHooks().rei_getContainerLeft(), window.getScaledHeight() - 22, ScreenHelper.getLastContainerScreenHooks().rei_getContainerWidth() - widthRemoved, 18);
  367. }
  368. private Rectangle getCraftableToggleArea() {
  369. Rectangle searchBoxArea = getTextFieldArea();
  370. searchBoxArea.setLocation(searchBoxArea.x + searchBoxArea.width + 4, searchBoxArea.y - 1);
  371. searchBoxArea.setSize(20, 20);
  372. return searchBoxArea;
  373. }
  374. private String getCheatModeText() {
  375. return I18n.translate(String.format("%s%s", "text.rei.", ClientHelper.getInstance().isCheating() ? "cheat" : "nocheat"));
  376. }
  377. public Rectangle getRectangle() {
  378. return rectangle;
  379. }
  380. @Override
  381. public void render(int mouseX, int mouseY, float delta) {
  382. List<ItemStack> currentStacks = ClientHelper.getInstance().getInventoryItemsTypes();
  383. if (DisplayHelper.getInstance().getBaseBoundsHandler() != null && DisplayHelper.getInstance().getBaseBoundsHandler().shouldRecalculateArea(!ConfigManager.getInstance().getConfig().isLeftHandSidePanel(), rectangle))
  384. shouldReInit = true;
  385. if (shouldReInit)
  386. init(true);
  387. else if (ConfigManager.getInstance().isCraftableOnlyEnabled() && ((currentStacks.size() != ScreenHelper.inventoryStacks.size()) || !hasSameListContent(new LinkedList<>(ScreenHelper.inventoryStacks), currentStacks))) {
  388. ScreenHelper.inventoryStacks = currentStacks;
  389. DisplayHelper.DisplayBoundsHandler<?> boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass());
  390. entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true);
  391. }
  392. if (OverlaySearchField.isSearching) {
  393. GuiLighting.disable();
  394. setBlitOffset(200);
  395. if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen) {
  396. ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen;
  397. int left = hooks.rei_getContainerLeft(), top = hooks.rei_getContainerTop();
  398. for (Slot slot : ((AbstractContainerScreen<?>) MinecraftClient.getInstance().currentScreen).getContainer().slotList)
  399. if (!slot.hasStack() || !entryListWidget.filterEntry(EntryStack.create(slot.getStack()), entryListWidget.getLastSearchArgument()))
  400. fillGradient(left + slot.xPosition, top + slot.yPosition, left + slot.xPosition + 16, top + slot.yPosition + 16, -601874400, -601874400);
  401. }
  402. setBlitOffset(0);
  403. }
  404. RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
  405. GuiLighting.disable();
  406. this.renderWidgets(mouseX, mouseY, delta);
  407. if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigManager.getInstance().getConfig().areClickableRecipeArrowsEnabled()) {
  408. ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen;
  409. for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas())
  410. if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass()))
  411. if (area.getRectangle().contains(mouseX - hooks.rei_getContainerLeft(), mouseY - hooks.rei_getContainerTop())) {
  412. String collect = CollectionUtils.mapAndJoinToString(area.getCategories(), identifier -> RecipeHelper.getInstance().getCategory(identifier).getCategoryName(), ", ");
  413. QUEUED_TOOLTIPS.add(QueuedTooltip.create(I18n.translate("text.rei.view_recipes_for", collect)));
  414. break;
  415. }
  416. }
  417. }
  418. public void lateRender(int mouseX, int mouseY, float delta) {
  419. if (ScreenHelper.isOverlayVisible()) {
  420. ScreenHelper.getSearchField().laterRender(mouseX, mouseY, delta);
  421. if (toggleButtonWidget != null)
  422. toggleButtonWidget.lateRender(mouseX, mouseY, delta);
  423. Screen currentScreen = MinecraftClient.getInstance().currentScreen;
  424. if (!(currentScreen instanceof RecipeViewingScreen) || !((RecipeViewingScreen) currentScreen).choosePageActivated)
  425. for (QueuedTooltip queuedTooltip : QUEUED_TOOLTIPS) {
  426. if (queuedTooltip != null)
  427. renderTooltip(queuedTooltip);
  428. }
  429. }
  430. QUEUED_TOOLTIPS.clear();
  431. }
  432. @SuppressWarnings("deprecation")
  433. public void renderTooltip(QueuedTooltip tooltip) {
  434. if (tooltip.getConsumer() == null)
  435. renderTooltip(tooltip.getText(), tooltip.getX(), tooltip.getY());
  436. else
  437. tooltip.getConsumer().accept(tooltip);
  438. }
  439. public void renderTooltip(List<String> lines, int mouseX, int mouseY) {
  440. if (lines.isEmpty())
  441. return;
  442. tooltipWidth = lines.stream().map(font::getStringWidth).max(Integer::compareTo).get();
  443. tooltipHeight = lines.size() <= 1 ? 8 : lines.size() * 10;
  444. tooltipLines = lines;
  445. ScreenHelper.drawHoveringWidget(mouseX, mouseY, renderTooltipCallback, tooltipWidth, tooltipHeight, 0);
  446. }
  447. private boolean hasSameListContent(List<ItemStack> list1, List<ItemStack> list2) {
  448. list1.sort(Comparator.comparing(Object::toString));
  449. list2.sort(Comparator.comparing(Object::toString));
  450. return CollectionUtils.mapAndJoinToString(list1, Object::toString, "").equals(CollectionUtils.mapAndJoinToString(list2, Object::toString, ""));
  451. }
  452. public void addTooltip(@Nullable QueuedTooltip queuedTooltip) {
  453. if (queuedTooltip != null)
  454. QUEUED_TOOLTIPS.add(queuedTooltip);
  455. }
  456. public void renderWidgets(int int_1, int int_2, float float_1) {
  457. if (!ScreenHelper.isOverlayVisible())
  458. return;
  459. if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled())
  460. buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0;
  461. widgets.forEach(widget -> {
  462. GuiLighting.disable();
  463. widget.render(int_1, int_2, float_1);
  464. });
  465. GuiLighting.disable();
  466. }
  467. private int getTotalPage() {
  468. return entryListWidget.getTotalPage();
  469. }
  470. @Override
  471. public boolean mouseScrolled(double i, double j, double amount) {
  472. if (!ScreenHelper.isOverlayVisible())
  473. return false;
  474. if (isInside(PointHelper.fromMouse())) {
  475. if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) {
  476. if (amount > 0 && buttonLeft.enabled)
  477. buttonLeft.onPressed();
  478. else if (amount < 0 && buttonRight.enabled)
  479. buttonRight.onPressed();
  480. else
  481. return false;
  482. return true;
  483. } else {
  484. return entryListWidget.mouseScrolled(i, j, amount);
  485. }
  486. }
  487. for (Widget widget : widgets)
  488. if (widget.mouseScrolled(i, j, amount))
  489. return true;
  490. return false;
  491. }
  492. @Override
  493. public boolean keyPressed(int int_1, int int_2, int int_3) {
  494. if (ScreenHelper.isOverlayVisible())
  495. for (Element listener : widgets)
  496. if (listener.keyPressed(int_1, int_2, int_3))
  497. return true;
  498. if (ClientHelper.getInstance().getHideKeyBinding().matchesKey(int_1, int_2)) {
  499. ScreenHelper.toggleOverlayVisible();
  500. return true;
  501. }
  502. ItemStack itemStack = null;
  503. if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen)
  504. if (ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot() != null && !ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack().isEmpty())
  505. itemStack = ScreenHelper.getLastContainerScreenHooks().rei_getHoveredSlot().getStack();
  506. if (itemStack != null && !itemStack.isEmpty()) {
  507. if (ClientHelper.getInstance().getRecipeKeyBinding().matchesKey(int_1, int_2))
  508. return ClientHelper.getInstance().executeRecipeKeyBind(itemStack);
  509. else if (ClientHelper.getInstance().getUsageKeyBinding().matchesKey(int_1, int_2))
  510. return ClientHelper.getInstance().executeUsageKeyBind(itemStack);
  511. }
  512. if (!ScreenHelper.isOverlayVisible())
  513. return false;
  514. if (ClientHelper.getInstance().getFocusSearchFieldKeyBinding().matchesKey(int_1, int_2)) {
  515. ScreenHelper.getSearchField().setFocused(true);
  516. setFocused(ScreenHelper.getSearchField());
  517. ScreenHelper.getSearchField().keybindFocusTime = System.currentTimeMillis();
  518. ScreenHelper.getSearchField().keybindFocusKey = int_1;
  519. return true;
  520. }
  521. return false;
  522. }
  523. @Override
  524. public boolean charTyped(char char_1, int int_1) {
  525. if (!ScreenHelper.isOverlayVisible())
  526. return false;
  527. for (Element listener : widgets)
  528. if (listener.charTyped(char_1, int_1))
  529. return true;
  530. return false;
  531. }
  532. @Override
  533. public List<? extends Element> children() {
  534. return widgets;
  535. }
  536. @Override
  537. public boolean mouseClicked(double double_1, double double_2, int int_1) {
  538. if (!ScreenHelper.isOverlayVisible())
  539. return false;
  540. if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigManager.getInstance().getConfig().areClickableRecipeArrowsEnabled()) {
  541. ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen;
  542. for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas())
  543. if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass()))
  544. if (area.getRectangle().contains(double_1 - hooks.rei_getContainerLeft(), double_2 - hooks.rei_getContainerTop())) {
  545. ClientHelper.getInstance().executeViewAllRecipesFromCategories(Arrays.asList(area.getCategories()));
  546. MinecraftClient.getInstance().getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
  547. return true;
  548. }
  549. }
  550. for (Element element : widgets)
  551. if (element.mouseClicked(double_1, double_2, int_1)) {
  552. this.setFocused(element);
  553. if (int_1 == 0)
  554. this.setDragging(true);
  555. return true;
  556. }
  557. return false;
  558. }
  559. @Override
  560. public boolean mouseDragged(double double_1, double double_2, int int_1, double double_3, double double_4) {
  561. if (!ScreenHelper.isOverlayVisible())
  562. return false;
  563. return this.getFocused() != null && this.isDragging() && int_1 == 0 ? this.getFocused().mouseDragged(double_1, double_2, int_1, double_3, double_4) : false;
  564. }
  565. public boolean isInside(double mouseX, double mouseY) {
  566. if (!rectangle.contains(mouseX, mouseY))
  567. return false;
  568. for (DisplayHelper.DisplayBoundsHandler<?> handler : DisplayHelper.getInstance().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) {
  569. ActionResult in = handler.isInZone(!ConfigManager.getInstance().getConfig().isLeftHandSidePanel(), mouseX, mouseY);
  570. if (in != ActionResult.PASS)
  571. return in == ActionResult.SUCCESS;
  572. }
  573. return true;
  574. }
  575. public boolean isNotInExclusionZones(double mouseX, double mouseY) {
  576. for (DisplayHelper.DisplayBoundsHandler<?> handler : DisplayHelper.getInstance().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) {
  577. ActionResult in = handler.isInZone(true, mouseX, mouseY);
  578. if (in != ActionResult.PASS)
  579. return in == ActionResult.SUCCESS;
  580. in = handler.isInZone(false, mouseX, mouseY);
  581. if (in != ActionResult.PASS)
  582. return in == ActionResult.SUCCESS;
  583. }
  584. return true;
  585. }
  586. public boolean isInside(Point point) {
  587. return isInside(point.getX(), point.getY());
  588. }
  589. }