From 0bde3511d83e54b990c3840573523d643cc843e9 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 28 May 2021 20:28:48 +0800 Subject: Fix #540 --- .../main/java/me/shedaniel/rei/PluginDetector.java | 2 +- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 4 +- .../rei/RoughlyEnoughItemsInitializer.java | 2 +- .../rei/impl/client/ClientHelperImpl.java | 8 +- .../shedaniel/rei/impl/client/ErrorDisplayer.java | 2 +- .../shedaniel/rei/impl/client/REIHelperImpl.java | 16 +- .../rei/impl/client/config/ConfigManagerImpl.java | 99 +-- .../rei/impl/client/config/ConfigObjectImpl.java | 18 - .../client/config/entries/FilteringScreen.java | 4 +- .../impl/client/gui/ContainerScreenOverlay.java | 850 --------------------- .../rei/impl/client/gui/ScreenOverlayImpl.java | 802 +++++++++++++++++++ .../impl/client/gui/craftable/CraftableFilter.java | 50 ++ .../rei/impl/client/gui/credits/CreditsScreen.java | 15 +- .../entries/EntryStackSubsetsMenuEntry.java | 6 +- .../gui/modules/entries/SubSubsetsMenuEntry.java | 6 +- .../rei/impl/client/gui/screen/DelegateScreen.java | 292 ------- .../impl/client/gui/screen/TransformingScreen.java | 151 ---- .../impl/client/gui/widget/EntryListWidget.java | 8 +- .../rei/impl/client/gui/widget/EntryWidget.java | 7 +- .../client/gui/widget/FavoritesListWidget.java | 4 +- .../gui/widget/search/OverlaySearchField.java | 6 +- .../registry/category/CategoryRegistryImpl.java | 2 +- .../rei/impl/client/search/AsyncSearchManager.java | 5 +- .../shedaniel/rei/impl/client/view/ViewsImpl.java | 62 +- .../display/DisplaySerializerRegistryImpl.java | 30 +- .../rei/impl/common/plugins/PluginManagerImpl.java | 8 +- .../impl/common/transfer/MenuInfoRegistryImpl.java | 2 + .../plugin/client/DefaultClientRuntimePlugin.java | 6 +- 28 files changed, 974 insertions(+), 1493 deletions(-) delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ScreenOverlayImpl.java create mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/craftable/CraftableFilter.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/DelegateScreen.java delete mode 100644 runtime/src/main/java/me/shedaniel/rei/impl/client/gui/screen/TransformingScreen.java (limited to 'runtime/src/main/java') diff --git a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java index 56d7c65c7..28592bcf3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java +++ b/runtime/src/main/java/me/shedaniel/rei/PluginDetector.java @@ -23,7 +23,7 @@ package me.shedaniel.rei; -import me.shedaniel.architectury.annotations.ExpectPlatform; +import dev.architectury.injectables.annotations.ExpectPlatform; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 1edb3c221..eec3d7514 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -71,7 +71,7 @@ import me.shedaniel.rei.impl.client.REIHelperImpl; import me.shedaniel.rei.impl.client.config.ConfigManagerImpl; import me.shedaniel.rei.impl.client.entry.type.types.RenderingEntryDefinition; import me.shedaniel.rei.impl.client.favorites.FavoriteEntryTypeRegistryImpl; -import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; +import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; import me.shedaniel.rei.impl.client.gui.widget.QueuedTooltip; import me.shedaniel.rei.impl.client.registry.category.CategoryRegistryImpl; @@ -574,7 +574,7 @@ public class RoughlyEnoughItemsCore { return; resetFocused(screen); REIHelper.getInstance().getOverlay().get().render(matrices, mouseX, mouseY, delta); - ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).lateRender(matrices, mouseX, mouseY, delta); + ((ScreenOverlayImpl) REIHelper.getInstance().getOverlay().get()).lateRender(matrices, mouseX, mouseY, delta); resetFocused(screen); }); ClientScreenInputEvent.MOUSE_DRAGGED_PRE.register((minecraftClient, screen, mouseX1, mouseY1, button, mouseX2, mouseY2) -> { diff --git a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java index 78f118501..0ee468267 100644 --- a/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java +++ b/runtime/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsInitializer.java @@ -23,7 +23,7 @@ package me.shedaniel.rei; -import me.shedaniel.architectury.annotations.ExpectPlatform; +import dev.architectury.injectables.annotations.ExpectPlatform; import net.fabricmc.api.EnvType; import java.lang.reflect.InvocationTargetException; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java index 849856165..140c1edc1 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ClientHelperImpl.java @@ -24,6 +24,8 @@ package me.shedaniel.rei.impl.client; import io.netty.buffer.Unpooled; +import it.unimi.dsi.fastutil.longs.LongOpenHashSet; +import it.unimi.dsi.fastutil.longs.LongSet; import me.shedaniel.architectury.networking.NetworkManager; import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.RoughlyEnoughItemsNetwork; @@ -65,7 +67,6 @@ import org.jetbrains.annotations.Nullable; import java.time.LocalDateTime; import java.util.*; import java.util.function.Supplier; -import java.util.stream.Collectors; @ApiStatus.Internal @Environment(EnvType.CLIENT) @@ -215,11 +216,12 @@ public class ClientHelperImpl implements ClientHelper { } @ApiStatus.Internal - public Set> _getInventoryItemsTypes() { + public LongSet _getInventoryItemsTypes() { return Minecraft.getInstance().player.inventory.compartments.stream() .flatMap(Collection::stream) .map(EntryStacks::of) - .collect(Collectors.toSet()); + .mapToLong(EntryStacks::hashExact) + .collect(LongOpenHashSet::new, LongOpenHashSet::add, LongOpenHashSet::addAll); } @ApiStatus.Internal diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java index b6eb5da51..12bf9da50 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/ErrorDisplayer.java @@ -23,7 +23,7 @@ package me.shedaniel.rei.impl.client; -import me.shedaniel.architectury.annotations.ExpectPlatform; +import dev.architectury.injectables.annotations.ExpectPlatform; import me.shedaniel.rei.RoughlyEnoughItemsState; import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen; import net.minecraft.client.Minecraft; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java index 4f44c5fe4..731b2a996 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/REIHelperImpl.java @@ -30,15 +30,15 @@ import me.shedaniel.architectury.event.events.GuiEvent; import me.shedaniel.architectury.event.events.client.ClientTickEvent; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.client.REIHelper; -import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.config.ConfigObject; import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; import me.shedaniel.rei.api.client.gui.screen.DisplayScreen; import me.shedaniel.rei.api.client.gui.widgets.TextField; import me.shedaniel.rei.api.client.gui.widgets.Tooltip; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; +import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; @@ -60,7 +60,7 @@ public class REIHelperImpl implements REIHelper { private static final ResourceLocation DISPLAY_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/display_dark.png"); @ApiStatus.Internal public static boolean isWithinRecipeViewingScreen = false; - private ContainerScreenOverlay overlay; + private ScreenOverlayImpl overlay; private OverlaySearchField searchField; private AbstractContainerScreen previousContainerScreen = null; private Screen previousScreen = null; @@ -128,7 +128,7 @@ public class REIHelperImpl implements REIHelper { @Override public Optional getOverlay(boolean reset) { if (overlay == null || reset) { - overlay = new ContainerScreenOverlay(); + overlay = new ScreenOverlayImpl(); overlay.init(); getSearchField().setFocused(false); } @@ -200,8 +200,7 @@ public class REIHelperImpl implements REIHelper { Rectangle bounds = ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation().mirror(), Minecraft.getInstance().screen); int yOffset = 8; - if (ConfigObject.getInstance().doesShowUtilsButtons()) yOffset += 50; - else if (!ConfigObject.getInstance().isLowerConfigButton()) yOffset += 25; + if (!ConfigObject.getInstance().isLowerConfigButton()) yOffset += 25; return new Rectangle(bounds.x, bounds.y + yOffset, bounds.width, bounds.height - 3 - yOffset); } @@ -223,8 +222,9 @@ public class REIHelperImpl implements REIHelper { return InteractionResult.PASS; }); ClientTickEvent.CLIENT_POST.register(minecraft -> { - if (isOverlayVisible() && getSearchField() != null) - getSearchField().tick(); + if (isOverlayVisible()) { + ScreenOverlayImpl.getInstance().tick(); + } }); } } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java index a99affab6..03008b2e3 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigManagerImpl.java @@ -27,11 +27,8 @@ import com.google.common.collect.Lists; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.mojang.blaze3d.platform.InputConstants; -import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.brigadier.exceptions.CommandSyntaxException; -import com.mojang.math.Matrix4f; import me.shedaniel.architectury.hooks.ScreenHooks; -import me.shedaniel.architectury.platform.Platform; import me.shedaniel.autoconfig.AutoConfig; import me.shedaniel.autoconfig.annotation.ConfigEntry; import me.shedaniel.autoconfig.gui.ConfigScreenProvider; @@ -47,13 +44,13 @@ import me.shedaniel.clothconfig2.api.ConfigEntryBuilder; import me.shedaniel.clothconfig2.api.Modifier; import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.clothconfig2.gui.entries.KeyCodeEntry; -import me.shedaniel.clothconfig2.impl.EasingMethod; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.client.REIHelper; import me.shedaniel.rei.api.client.config.ConfigManager; import me.shedaniel.rei.api.client.favorites.FavoriteEntry; import me.shedaniel.rei.api.client.gui.config.DisplayScreenType; import me.shedaniel.rei.api.client.gui.config.SyntaxHighlightingMode; +import me.shedaniel.rei.api.client.overlay.ScreenOverlay; import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.common.entry.EntryStack; import me.shedaniel.rei.api.common.util.CollectionUtils; @@ -61,34 +58,23 @@ import me.shedaniel.rei.impl.client.REIHelperImpl; import me.shedaniel.rei.impl.client.config.entries.*; import me.shedaniel.rei.impl.client.entry.filtering.FilteringRule; import me.shedaniel.rei.impl.client.entry.filtering.rules.ManualFilteringRule; -import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; +import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.credits.CreditsScreen; -import me.shedaniel.rei.impl.client.gui.screen.TransformingScreen; -import me.shedaniel.rei.impl.client.gui.screen.WarningAndErrorScreen; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.Util; import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.Font; import net.minecraft.client.gui.components.Button; import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.renderer.MultiBufferSource; -import net.minecraft.client.resources.language.I18n; import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.nbt.TagParser; -import net.minecraft.network.chat.CommonComponents; -import net.minecraft.network.chat.Component; import net.minecraft.network.chat.TextComponent; import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.util.Mth; -import net.minecraft.util.Tuple; import net.minecraft.world.InteractionResult; import org.apache.commons.lang3.mutable.MutableLong; import org.jetbrains.annotations.ApiStatus; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -309,25 +295,7 @@ public class ConfigManagerImpl implements ConfigManager { @Override public Screen getConfigScreen(Screen parent) { try { - if (Platform.isFabric() && !detectWorkingOptifabric()) { - List> warnings = Lists.newArrayList(); - warnings.add(new Tuple<>(I18n.get("text.rei.config.optifine.title"), null)); - warnings.add(new Tuple<>(I18n.get("text.rei.config.optifine.description"), null)); - WarningAndErrorScreen screen = new WarningAndErrorScreen("config screen", warnings, Collections.emptyList(), Minecraft.getInstance()::setScreen); - screen.setParent(parent); - return screen; - } - TransformingScreen parentTranslated; - { - MutableLong current = new MutableLong(0); - parentTranslated = new TransformingScreen(true, parent, - null, - () -> current.setValue(current.getValue() == 0 ? Util.getMillis() + (!getConfig().isConfigScreenAnimated() ? -3000 : 0) : current.getValue()), - () -> 0, () -> (EasingMethod.EasingMethodImpl.EXPO.apply(Mth.clamp((Util.getMillis() - current.getValue()) / 750.0, 0, 1))) - * Minecraft.getInstance().getWindow().getGuiScaledHeight(), () -> Util.getMillis() - current.getValue() > 800); - parentTranslated.setInitAfter(true); - } - ConfigScreenProvider provider = (ConfigScreenProvider) AutoConfig.getConfigScreen(ConfigObjectImpl.class, parentTranslated); + ConfigScreenProvider provider = (ConfigScreenProvider) AutoConfig.getConfigScreen(ConfigObjectImpl.class, parent); provider.setI13nFunction(manager -> "config.roughlyenoughitems"); provider.setOptionFunction((baseI13n, field) -> field.isAnnotationPresent(ConfigObjectImpl.DontApplyFieldName.class) ? baseI13n : String.format("%s.%s", baseI13n, field.getName())); provider.setCategoryFunction((baseI13n, categoryName) -> String.format("%s.%s", baseI13n, categoryName)); @@ -341,74 +309,21 @@ public class ConfigManagerImpl implements ConfigManager { ScreenHooks.addButton(screen, new Button(screen.width - 104, 4, 100, 20, new TranslatableComponent("text.rei.credits"), button -> { MutableLong current = new MutableLong(0); CreditsScreen creditsScreen = new CreditsScreen(screen); - Minecraft.getInstance().setScreen(new TransformingScreen(false, creditsScreen, - screen, - () -> current.setValue(current.getValue() == 0 ? Util.getMillis() + (!getConfig().isCreditsScreenAnimated() ? -3000 : 0) : current.getValue()), - () -> (1 - EasingMethod.EasingMethodImpl.EXPO.apply(Mth.clamp((Util.getMillis() - current.getValue()) / 750.0, 0, 1))) - * Minecraft.getInstance().getWindow().getGuiScaledWidth() * 1.3, - () -> 0, - () -> Util.getMillis() - current.getValue() > 800)); + Minecraft.getInstance().setScreen(creditsScreen); })); }).setSavingRunnable(() -> { saveConfig(); EntryRegistry.getInstance().refilter(); + REIHelper.getInstance().getOverlay().ifPresent(ScreenOverlay::queueReloadOverlay); if (REIHelperImpl.getSearchField() != null) { - ContainerScreenOverlay.getEntryListWidget().updateSearch(REIHelperImpl.getSearchField().getText(), true); + ScreenOverlayImpl.getEntryListWidget().updateSearch(REIHelperImpl.getSearchField().getText(), true); } }).build(); }); - Screen configScreen = provider.get(); - parentTranslated.setLastScreen(configScreen); - MutableLong current = new MutableLong(0); - return new TransformingScreen(false, configScreen, - parent, - () -> current.setValue(current.getValue() == 0 ? Util.getMillis() + (!getConfig().isConfigScreenAnimated() ? -3000 : 0) : current.getValue()), - () -> 0, () -> (1 - EasingMethod.EasingMethodImpl.EXPO.apply(Mth.clamp((Util.getMillis() - current.getValue()) / 750.0, 0, 1))) - * Minecraft.getInstance().getWindow().getGuiScaledHeight() * 1.3, () -> Util.getMillis() - current.getValue() > 800); + return provider.get(); } catch (Exception e) { e.printStackTrace(); } return null; } - - private boolean detectWorkingOptifabric() { - try { - String renderText = FabricLoader.getInstance().getMappingResolver().mapMethodName("intermediary", "net.minecraft.class_327", "method_1724", "(Ljava/lang/String;FFIZLnet/minecraft/class_1159;Lnet/minecraft/class_4597;ZII)F"); - Method method = Font.class.getDeclaredMethod(renderText, String.class, Float.TYPE, Float.TYPE, Integer.TYPE, Boolean.TYPE, Matrix4f.class, MultiBufferSource.class, Boolean.TYPE, Integer.TYPE, Integer.TYPE); - return !java.lang.reflect.Modifier.isPrivate(method.getModifiers()); - } catch (Throwable ignored) { - return false; - } - } - - public static class ConfigErrorScreen extends Screen { - private final Component message; - private final Screen parent; - - public ConfigErrorScreen(Screen parent, Component title, Component message) { - super(title); - this.parent = parent; - this.message = message; - } - - @Override - public void init() { - super.init(); - this.addButton(new Button(this.width / 2 - 100, 140, 200, 20, CommonComponents.GUI_CANCEL, button -> this.minecraft.setScreen(parent))); - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - this.renderBackground(matrices); - drawCenteredString(matrices, this.font, this.title, this.width / 2, 90, 16777215); - drawCenteredString(matrices, this.font, this.message, this.width / 2, 110, 16777215); - super.render(matrices, mouseX, mouseY, delta); - } - - @Override - public boolean shouldCloseOnEsc() { - return false; - } - } - } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java index f5b637ba4..e4b855e1e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/ConfigObjectImpl.java @@ -101,16 +101,6 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return basics.cheatingStyle == ItemCheatingStyle.GRAB; } - @Override - public boolean isConfigScreenAnimated() { - return basics.motion.configScreenAnimation; - } - - @Override - public boolean isCreditsScreenAnimated() { - return basics.motion.creditsScreenAnimation; - } - @Override public boolean isFavoritesAnimated() { return basics.motion.favoritesAnimation; @@ -176,11 +166,6 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { return advanced.layout.maxRecipesPerPage; } - @Override - public boolean doesShowUtilsButtons() { - return appearance.layout.showUtilsButtons; - } - @Override public boolean doesDisableRecipeBook() { return functionality.disableRecipeBook; @@ -430,8 +415,6 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { } public static class Motion { - private boolean configScreenAnimation = false; - private boolean creditsScreenAnimation = true; private boolean favoritesAnimation = true; } @@ -463,7 +446,6 @@ public class ConfigObjectImpl implements ConfigObject, ConfigData { @Comment("Declares the position of the config button.") @ConfigEntry.Gui.EnumHandler(option = ConfigEntry.Gui.EnumHandler.EnumDisplayOption.BUTTON) private ConfigButtonPosition configButtonLocation = ConfigButtonPosition.LOWER; @Comment("Declares whether the craftable filter button is enabled.") private boolean enableCraftableOnlyButton = false; - @Comment("Declares whether the utils buttons are shown.") private boolean showUtilsButtons = false; } @UsePercentage(min = 0.1, max = 1.0, prefix = "Limit: ") private double horizontalEntriesBoundaries = 1.0; diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java index cd18448e9..0081ae36e 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/config/entries/FilteringScreen.java @@ -45,7 +45,7 @@ import me.shedaniel.rei.api.client.registry.entry.EntryRegistry; import me.shedaniel.rei.api.client.search.SearchFilter; import me.shedaniel.rei.api.client.search.SearchProvider; import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.impl.client.gui.ContainerScreenOverlay; +import me.shedaniel.rei.impl.client.gui.ScreenOverlayImpl; import me.shedaniel.rei.impl.client.gui.widget.BatchedEntryRendererManager; import me.shedaniel.rei.impl.client.gui.widget.EntryWidget; import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; @@ -269,7 +269,7 @@ public class FilteringScreen extends Screen { this.backButton.render(matrices, mouseX, mouseY, delta); if (tooltip != null) { - ((ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get()).renderTooltip(matrices, tooltip); + ((ScreenOverlayImpl) REIHelper.getInstance().getOverlay().get()).renderTooltip(matrices, tooltip); } this.font.drawShadow(matrices, this.title.getVisualOrderText(), this.width / 2.0F - this.font.width(this.title) / 2.0F, 12.0F, -1); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java deleted file mode 100644 index f25bb13da..000000000 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/gui/ContainerScreenOverlay.java +++ /dev/null @@ -1,850 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020, 2021 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.impl.client.gui; - -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; -import com.mojang.blaze3d.platform.Window; -import com.mojang.blaze3d.systems.RenderSystem; -import com.mojang.blaze3d.vertex.PoseStack; -import com.mojang.math.Vector4f; -import me.shedaniel.math.Point; -import me.shedaniel.math.Rectangle; -import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.api.client.ClientHelper; -import me.shedaniel.rei.api.client.REIHelper; -import me.shedaniel.rei.api.client.overlay.OverlayListWidget; -import me.shedaniel.rei.api.client.overlay.ScreenOverlay; -import me.shedaniel.rei.api.client.config.ConfigManager; -import me.shedaniel.rei.api.client.config.ConfigObject; -import me.shedaniel.rei.api.client.favorites.FavoriteEntry; -import me.shedaniel.rei.api.client.gui.config.SearchFieldLocation; -import me.shedaniel.rei.api.client.gui.drag.DraggableStackProvider; -import me.shedaniel.rei.api.client.gui.drag.DraggableStackVisitor; -import me.shedaniel.rei.api.client.gui.drag.DraggingContext; -import me.shedaniel.rei.api.client.gui.widgets.Button; -import me.shedaniel.rei.api.client.gui.widgets.Tooltip; -import me.shedaniel.rei.api.client.gui.widgets.Widget; -import me.shedaniel.rei.api.client.gui.widgets.Widgets; -import me.shedaniel.rei.api.client.registry.category.CategoryRegistry; -import me.shedaniel.rei.api.client.registry.screen.ClickArea; -import me.shedaniel.rei.api.client.registry.screen.OverlayDecider; -import me.shedaniel.rei.api.client.registry.screen.ScreenRegistry; -import me.shedaniel.rei.api.client.view.ViewSearchBuilder; -import me.shedaniel.rei.api.common.category.CategoryIdentifier; -import me.shedaniel.rei.api.common.entry.EntryStack; -import me.shedaniel.rei.api.common.util.CollectionUtils; -import me.shedaniel.rei.api.common.util.EntryStacks; -import me.shedaniel.rei.api.common.util.ImmutableTextComponent; -import me.shedaniel.rei.impl.client.ClientHelperImpl; -import me.shedaniel.rei.impl.client.REIHelperImpl; -import me.shedaniel.rei.impl.client.gui.dragging.CurrentDraggingStack; -import me.shedaniel.rei.impl.client.gui.modules.Menu; -import me.shedaniel.rei.impl.client.gui.modules.entries.GameModeMenuEntry; -import me.shedaniel.rei.impl.client.gui.modules.entries.WeatherMenuEntry; -import me.shedaniel.rei.impl.client.gui.screen.DefaultDisplayViewingScreen; -import me.shedaniel.rei.impl.client.gui.widget.EntryListWidget; -import me.shedaniel.rei.impl.client.gui.widget.FavoritesListWidget; -import me.shedaniel.rei.impl.client.gui.widget.InternalWidgets; -import me.shedaniel.rei.impl.client.gui.widget.LateRenderable; -import me.shedaniel.rei.impl.client.gui.widget.search.OverlaySearchField; -import me.shedaniel.rei.impl.client.search.argument.Argument; -import me.shedaniel.rei.impl.common.util.Weather; -import net.minecraft.client.Minecraft; -import net.minecraft.client.gui.chat.NarratorChatListener; -import net.minecraft.client.gui.components.events.GuiEventListener; -import net.minecraft.client.gui.screens.Screen; -import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; -import net.minecraft.client.multiplayer.ClientLevel; -import net.minecraft.client.multiplayer.PlayerInfo; -import net.minecraft.client.renderer.entity.ItemRenderer; -import net.minecraft.client.resources.language.I18n; -import net.minecraft.client.resources.sounds.SimpleSoundInstance; -import net.minecraft.locale.Language; -import net.minecraft.network.chat.*; -import net.minecraft.resources.ResourceLocation; -import net.minecraft.sounds.SoundEvents; -import net.minecraft.util.FormattedCharSequence; -import net.minecraft.world.InteractionResult; -import net.minecraft.world.inventory.Slot; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.level.GameType; -import net.minecraft.world.level.block.Blocks; -import org.jetbrains.annotations.ApiStatus; -import org.jetbrains.annotations.Nullable; - -import java.util.*; -import java.util.function.Consumer; -import java.util.function.Predicate; -import java.util.stream.Collectors; - -@ApiStatus.Internal -public class ContainerScreenOverlay extends ScreenOverlay { - private static final ResourceLocation CHEST_GUI_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/recipecontainer.png"); - private static final List TOOLTIPS = Lists.newArrayList(); - private static final List AFTER_RENDER = Lists.newArrayList(); - private static final EntryListWidget ENTRY_LIST_WIDGET = new EntryListWidget(); - private static FavoritesListWidget favoritesListWidget = null; - private final List widgets = Lists.newLinkedList(); - public boolean shouldReload = false; - private Rectangle bounds; - private Window window; - private Button leftButton, rightButton; - private Widget configButton; - private CurrentDraggingStack draggingStack = new CurrentDraggingStack(); - - @Nullable - private ContainerScreenOverlay.OverlayMenu overlayMenu = null; - - public Set> inventoryStacks = Sets.newHashSet(); - - public static EntryListWidget getEntryListWidget() { - return ENTRY_LIST_WIDGET; - } - - @Nullable - public static FavoritesListWidget getFavoritesListWidget() { - return favoritesListWidget; - } - - public static ContainerScreenOverlay getInstance() { - return (ContainerScreenOverlay) REIHelper.getInstance().getOverlay().get(); - } - - private static class OverlayMenu { - private UUID uuid; - private Menu menu; - private Widget wrappedMenu; - private Predicate inBounds; - - public OverlayMenu(UUID uuid, Menu menu, Widget wrappedMenu, Predicate or, Predicate and) { - this.uuid = uuid; - this.menu = menu; - this.wrappedMenu = wrappedMenu; - this.inBounds = or.or(point -> menu.getBounds().contains(point)).and(and); - } - } - - public boolean isMenuOpened(UUID uuid) { - return overlayMenu != null && overlayMenu.uuid.equals(uuid); - } - - public boolean isAnyMenuOpened() { - return overlayMenu != null; - } - - public boolean isMenuInBounds(UUID uuid) { - return isMenuOpened(uuid) && overlayMenu.inBounds.test(PointHelper.ofMouse()); - } - - private void proceedOpenMenu(UUID uuid, Runnable runnable) { - proceedOpenMenuOrElse(uuid, runnable, menu -> {}); - } - - private void proceedOpenMenuOrElse(UUID uuid, Runnable runnable, Consumer orElse) { - if (overlayMenu == null || !overlayMenu.uuid.equals(uuid)) { - closeOverlayMenu(); - runnable.run(); - } else { - orElse.accept(this.overlayMenu); - } - } - - public void openMenu(UUID uuid, Menu menu) { - openMenu(uuid, menu, point -> false, point -> true); - } - - public void openMenu(UUID uuid, Menu menu, Predicate or, Predicate and) { - this.overlayMenu = new OverlayMenu(uuid, menu, Widgets.withTranslate(menu, 0, 0, 400), or, and); - } - - @ApiStatus.Internal - @Nullable - public Menu getOverlayMenu() { - if (isMenuOpened(Menu.SUBSETS)) - return this.overlayMenu.menu; - throw new IllegalStateException("Subsets menu accessed when subsets are not opened!"); - } - - @ApiStatus.Internal - @Override - public void closeOverlayMenu() { - OverlayMenu tmpOverlayMenu = this.overlayMenu; - if (tmpOverlayMenu != null) - AFTER_RENDER.add(() -> this.widgets.remove(tmpOverlayMenu.wrappedMenu)); - this.overlayMenu = null; - } - - @Override - public void queueReloadOverlay() { - shouldReload = true; - } - - @Override - public DraggingContext getDraggingContext() { - return draggingStack; - } - - public void init(boolean useless) { - init(); - } - - public void init() { - Argument.SEARCH_CACHE.clear(); - draggingStack.set(DraggableStackProvider.from(() -> ScreenRegistry.getInstance().getDraggableProviders()), - DraggableStackVisitor.from(() -> ScreenRegistry.getInstance().getDraggableVisitors())); - - this.shouldReload = false; - //Update Variables - this.children().clear(); - this.closeOverlayMenu(); - this.window = Minecraft.getInstance().getWindow(); - this.bounds = ScreenRegistry.getInstance().getOverlayBounds(ConfigObject.getInstance().getDisplayPanelLocation(), Minecraft.getInstance().screen); - widgets.add(ENTRY_LIST_WIDGET); - if (ConfigObject.getInstance().isFavoritesEnabled()) { - if (favoritesListWidget == null) { - favoritesListWidget = new FavoritesListWidget(); - } - favoritesListWidget.favoritePanel.resetRows(); - widgets.add(favoritesListWidget); - } - ENTRY_LIST_WIDGET.updateArea(REIHelperImpl.getSearchField() == null ? "" : REIHelperImpl.getSearchField().getText()); - REIHelperImpl.getSearchField().getBounds().setBounds(getSearchFieldArea()); - this.widgets.add(REIHelperImpl.getSearchField()); - REIHelperImpl.getSearchField().setResponder(s -> ENTRY_LIST_WIDGET.updateSearch(s, false)); - if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { - widgets.add(leftButton = Widgets.createButton(new Rectangle(bounds.x, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableComponent("text.rei.left_arrow")) - .onClick(button -> { - ENTRY_LIST_WIDGET.previousPage(); - if (ENTRY_LIST_WIDGET.getPage() < 0) - ENTRY_LIST_WIDGET.setPage(ENTRY_LIST_WIDGET.getTotalPages() - 1); - ENTRY_LIST_WIDGET.updateEntriesPosition(); - }) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) - .tooltipLine(new TranslatableComponent("text.rei.previous_page")) - .focusable(false)); - widgets.add(rightButton = Widgets.createButton(new Rectangle(bounds.x + bounds.width - 18, bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16), new TranslatableComponent("text.rei.right_arrow")) - .onClick(button -> { - ENTRY_LIST_WIDGET.nextPage(); - if (ENTRY_LIST_WIDGET.getPage() >= ENTRY_LIST_WIDGET.getTotalPages()) - ENTRY_LIST_WIDGET.setPage(0); - ENTRY_LIST_WIDGET.updateEntriesPosition(); - }) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) - .tooltipLine(new TranslatableComponent("text.rei.next_page")) - .focusable(false)); - } - - final Rectangle configButtonArea = getConfigButtonArea(); - widgets.add(configButton = InternalWidgets.wrapLateRenderable( - Widgets.withTranslate( - InternalWidgets.concatWidgets( - Widgets.createButton(configButtonArea, NarratorChatListener.NO_TITLE) - .onClick(button -> { - if (Screen.hasShiftDown() || Screen.hasControlDown()) { - ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); - return; - } - ConfigManager.getInstance().openConfigScreen(REIHelper.getInstance().getPreviousScreen()); - }) - .onRender((matrices, button) -> { - if (ClientHelper.getInstance().isCheating() && ClientHelperImpl.getInstance().hasOperatorPermission()) { - button.setTint(ClientHelperImpl.getInstance().hasPermissionToUsePackets() ? 721354752 : 1476440063); - } else { - button.removeTint(); - } - }) - .focusable(false) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) - .tooltipSupplier(button -> { - List tooltips = new ArrayList<>(); - tooltips.add(new TranslatableComponent("text.rei.config_tooltip")); - tooltips.add(new ImmutableTextComponent(" ")); - if (!ClientHelper.getInstance().isCheating()) - tooltips.add(new TranslatableComponent("text.rei.cheating_disabled")); - else if (!ClientHelperImpl.getInstance().hasOperatorPermission()) { - if (minecraft.gameMode.hasInfiniteItems()) - tooltips.add(new TranslatableComponent("text.rei.cheating_limited_creative_enabled")); - else tooltips.add(new TranslatableComponent("text.rei.cheating_enabled_no_perms")); - } else if (ClientHelperImpl.getInstance().hasPermissionToUsePackets()) - tooltips.add(new TranslatableComponent("text.rei.cheating_enabled")); - else - tooltips.add(new TranslatableComponent("text.rei.cheating_limited_enabled")); - return tooltips.toArray(new Component[0]); - }), - Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { - helper.setBlitOffset(helper.getBlitOffset() + 1); - Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); - helper.blit(matrices, configButtonArea.x + 3, configButtonArea.y + 3, 0, 0, 14, 14); - }) - ), - 0, 0, 600 - ) - )); - if (ConfigObject.getInstance().doesShowUtilsButtons()) { - widgets.add(Widgets.createButton(ConfigObject.getInstance().isLowerConfigButton() ? new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 30 : 10, 10, 20, 20) : new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 55 : 35, 10, 20, 20), NarratorChatListener.NO_TITLE) - .onRender((matrices, button) -> { - boolean isOpened = isMenuOpened(Menu.GAME_TYPE); - if (isOpened || !isAnyMenuOpened()) { - boolean inBounds = (button.isFocused() || button.containsMouse(PointHelper.ofMouse())) || isMenuInBounds(Menu.GAME_TYPE); - if (isOpened != inBounds) { - if (inBounds) { - Menu menu = new Menu(new Point(button.getBounds().x, button.getBounds().getMaxY()), - CollectionUtils.map(GameType.values(), GameModeMenuEntry::new)); - if (ConfigObject.getInstance().isLeftHandSidePanel()) - menu.menuStartPoint.x -= menu.getBounds().width - button.getBounds().width; - openMenu(Menu.GAME_TYPE, menu, point -> button.isFocused() && button.containsMouse(PointHelper.ofMouse()), point -> true); - } else { - closeOverlayMenu(); - } - } - } - button.setText(new TextComponent(getGameModeShortText(getCurrentGameMode()))); - }) - .focusable(false) - .tooltipLine(new TranslatableComponent("text.rei.gamemode_button.tooltip.all")) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y))); - Button weatherButton; - widgets.add(weatherButton = Widgets.createButton(new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 30 : 10, 35, 20, 20), NarratorChatListener.NO_TITLE) - .onRender((matrices, button) -> { - boolean isOpened = isMenuOpened(Menu.WEATHER); - if (isOpened || !isAnyMenuOpened()) { - boolean inBounds = (button.isFocused() || button.containsMouse(PointHelper.ofMouse())) || isMenuInBounds(Menu.WEATHER); - if (isOpened != inBounds) { - if (inBounds) { - Menu menu = new Menu(new Point(button.getBounds().x, button.getBounds().getMaxY()), - CollectionUtils.map(Weather.values(), WeatherMenuEntry::new)); - if (ConfigObject.getInstance().isLeftHandSidePanel()) - menu.menuStartPoint.x -= menu.getBounds().width - button.getBounds().width; - openMenu(Menu.WEATHER, menu, point -> button.isFocused() && button.containsMouse(PointHelper.ofMouse()), point -> true); - } else { - closeOverlayMenu(); - } - } - } - }) - .tooltipLine(new TranslatableComponent("text.rei.weather_button.tooltip.all")) - .focusable(false) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y))); - widgets.add(Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { - Minecraft.getInstance().getTextureManager().bind(CHEST_GUI_TEXTURE); - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - helper.blit(matrices, weatherButton.getBounds().x + 3, weatherButton.getBounds().y + 3, getCurrentWeather().getId() * 14, 14, 14, 14); - })); - } - Rectangle subsetsButtonBounds = getSubsetsButtonBounds(); - if (ConfigObject.getInstance().isSubsetsEnabled()) { - widgets.add(InternalWidgets.wrapLateRenderable(Widgets.withTranslate(Widgets.createButton(subsetsButtonBounds, ClientHelperImpl.getInstance().isAprilFools.get() ? new TranslatableComponent("text.rei.tiny_potato") : new TranslatableComponent("text.rei.subsets")) - .onClick(button -> { - proceedOpenMenuOrElse(Menu.SUBSETS, () -> { - openMenu(Menu.SUBSETS, Menu.createSubsetsMenuFromRegistry(new Point(subsetsButtonBounds.x, subsetsButtonBounds.getMaxY())), point -> true, point -> true); - }, menu -> { - closeOverlayMenu(); - }); - }), 0, 0, 600))); - } - if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { - widgets.add(Widgets.createClickableLabel(new Point(bounds.x + (bounds.width / 2), bounds.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), NarratorChatListener.NO_TITLE, label -> { - ENTRY_LIST_WIDGET.setPage(0); - ENTRY_LIST_WIDGET.updateEntriesPosition(); - }).tooltipLine(I18n.get("text.rei.go_back_first_page")).focusable(false).onRender((matrices, label) -> { - label.setClickable(ENTRY_LIST_WIDGET.getTotalPages() > 1); - label.setMessage(new TextComponent(String.format("%s/%s", ENTRY_LIST_WIDGET.getPage() + 1, Math.max(ENTRY_LIST_WIDGET.getTotalPages(), 1)))); - }).rainbow(new Random().nextFloat() < 1.0E-4D || ClientHelperImpl.getInstance().isAprilFools.get())); - } - if (ConfigObject.getInstance().isCraftableFilterEnabled()) { - Rectangle area = getCraftableToggleArea(); - ItemRenderer itemRenderer = Minecraft.getInstance().getItemRenderer(); - ItemStack icon = new ItemStack(Blocks.CRAFTING_TABLE); - this.widgets.add(Widgets.withTranslate(InternalWidgets.wrapLateRenderable(InternalWidgets.concatWidgets( - Widgets.createButton(area, NarratorChatListener.NO_TITLE) - .focusable(false) - .onClick(button -> { - ConfigManager.getInstance().toggleCraftableOnly(); - ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); - }) - .onRender((matrices, button) -> button.setTint(ConfigManager.getInstance().isCraftableOnlyEnabled() ? 939579655 : 956235776)) - .containsMousePredicate((button, point) -> button.getBounds().contains(point) && isNotInExclusionZones(point.x, point.y)) - .tooltipLineSupplier(button -> new TranslatableComponent(ConfigManager.getInstance().isCraftableOnlyEnabled() ? "text.rei.showing_craftable" : "text.rei.showing_all")), - Widgets.createDrawableWidget((helper, matrices, mouseX, mouseY, delta) -> { - Vector4f vector = new Vector4f(area.x + 2, area.y + 2, helper.getBlitOffset() - 10, 1.0F); - vector.transform(matrices.last().pose()); - itemRenderer.blitOffset = vector.z(); - itemRenderer.renderGuiItem(icon, (int) vector.x(), (int) vector.y()); - itemRenderer.blitOffset = 0.0F; - })) - ), 0, 0, 600)); - } - - widgets.add(draggingStack); - } - - private Rectangle getSubsetsButtonBounds() { - if (ConfigObject.getInstance().isSubsetsEnabled()) { - ScreenRegistry registry = ScreenRegistry.getInstance(); - Rectangle screenBounds = registry.getScreenBounds(minecraft.screen); - return new Rectangle(screenBounds.x, 3, screenBounds.width, 18); - } - return null; - } - - private Weather getNextWeather() { - try { - Weather current = getCurrentWeather(); - int next = current.getId() + 1; - if (next >= 3) - next = 0; - return Weather.byId(next); - } catch (Exception e) { - return Weather.CLEAR; - } - } - - private Weather getCurrentWeather() { - ClientLevel world = Minecraft.getInstance().level; - if (world.isThundering()) - return Weather.THUNDER; - if (world.getLevelData().isRaining()) - return Weather.RAIN; - return Weather.CLEAR; - } - - private String getGameModeShortText(GameType gameMode) { - return I18n.get("text.rei.short_gamemode." + gameMode.getName()); - } - - private String getGameModeText(GameType gameMode) { - return I18n.get("selectWorld.gameMode." + gameMode.getName()); - } - - private GameType getCurrentGameMode() { - PlayerInfo info = Minecraft.getInstance().getConnection().getPlayerInfo(Minecraft.getInstance().player.getGameProfile().getId()); - return info == null ? GameType.SURVIVAL : info.getGameMode(); - } - - private Rectangle getSearchFieldArea() { - int widthRemoved = 1; - if (ConfigObject.getInstance().isCraftableFilterEnabled()) widthRemoved += 22; - if (ConfigObject.getInstance().isLowerConfigButton()) widthRemoved += 22; - SearchFieldLocation searchFieldLocation = REIHelper.getInstance().getContextualSearchFieldLocation(); - switch (searchFieldLocation) { - case TOP_SIDE: - return getTopSideSearchFieldArea(widthRemoved); - case BOTTOM_SIDE: - return getBottomSideSearchFieldArea(widthRemoved); - default: - case CENTER: - return getCenterSearchFieldArea(widthRemoved); - } - } - - private Rectangle getTopSideSearchFieldArea(int widthRemoved) { - return new Rectangle(bounds.x + 2, 4, bounds.width - 6 - widthRemoved, 18); - } - - private Rectangle getBottomSideSearchFieldArea(int widthRemoved) { - return new Rectangle(bounds.x + 2, window.getGuiScaledHeight() - 22, bounds.width - 6 - widthRemoved, 18); - } - - private Rectangle getCenterSearchFieldArea(int widthRemoved) { - Rectangle screenBounds = ScreenRegistry.getInstance().getScreenBounds(minecraft.screen); - return getBottomCenterSearchFieldArea(screenBounds, widthRemoved); - } - - private Rectangle getBottomCenterSearchFieldArea(Rectangle containerBounds, int widthRemoved) { - return new Rectangle(containerBounds.x, window.getGuiScaledHeight() - 22, containerBounds.width - widthRemoved, 18); - } - - private Rectangle getCraftableToggleArea() { - Rectangle area = getSearchFieldArea(); - area.setLocation(area.x + area.width + 4, area.y - 1); - area.setSize(20, 20); - return area; - } - - private Rectangle getConfigButtonArea() { - if (ConfigObject.getInstance().isLowerConfigButton()) { - Rectangle area = getSearchFieldArea(); - area.setLocation(area.x + area.width + (ConfigObject.getInstance().isCraftableFilterEnabled() ? 26 : 4), area.y - 1); - area.setSize(20, 20); - return area; - } - return new Rectangle(ConfigObject.getInstance().isLeftHandSidePanel() ? window.getGuiScaledWidth() - 30 : 10, 10, 20, 20); - } - - private String getCheatModeText() { - return I18n.get(String.format("%s%s", "text.rei.", ClientHelper.getInstance().isCheating() ? "cheat" : "nocheat")); - } - - @Override - public Rectangle getBounds() { - return bounds; - } - - @Override - public void render(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (shouldReload) { - ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); - init(); - } else { - for (OverlayDecider decider : ScreenRegistry.getInstance().getDeciders(minecraft.screen)) { - if (decider != null && decider.shouldRecalculateArea(ConfigObject.getInstance().getDisplayPanelLocation(), bounds)) { - init(); - break; - } - } - } - if (ConfigManager.getInstance().isCraftableOnlyEnabled()) { - Set> currentStacks = ClientHelperImpl.getInstance()._getInventoryItemsTypes(); - if (!currentStacks.equals(this.inventoryStacks)) { - this.inventoryStacks = currentStacks; - ENTRY_LIST_WIDGET.updateSearch(REIHelperImpl.getSearchField().getText(), true); - } - } - if (OverlaySearchField.isHighlighting) { - matrices.pushPose(); - matrices.translate(0, 0, 200f); - if (Minecraft.getInstance().screen instanceof AbstractContainerScreen) { - AbstractContainerScreen containerScreen = (AbstractContainerScreen) Minecraft.getInstance().screen; - int x = containerScreen.leftPos, y = containerScreen.topPos; - for (Slot slot : containerScreen.getMenu().slots) { - if (!slot.hasItem() || !ENTRY_LIST_WIDGET.matches(EntryStacks.of(slot.getItem()))) { - fillGradient(matrices, x + slot.x, y + slot.y, x + slot.x + 16, y + slot.y + 16, -601874400, -601874400); - } - } - } - matrices.popPose(); - } - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - this.renderWidgets(matrices, mouseX, mouseY, delta); - if (ConfigObject.getInstance().areClickableRecipeArrowsEnabled()) { - Screen screen = Minecraft.getInstance().screen; - ClickArea.ClickAreaContext context = new ClickArea.ClickAreaContext() { - @Override - public Screen getScreen() { - return screen; - } - - @Override - public Point getMousePosition() { - return new Point(mouseX, mouseY); - } - }; - Set> categories = ScreenRegistry.getInstance().handleClickArea((Class) screen.getClass(), context); - if (categories != null && !categories.isEmpty()) { - Component collect = CollectionUtils.mapAndJoinToComponent(categories, identifier -> CategoryRegistry.getInstance().get(identifier).getCategory().getTitle(), new ImmutableTextComponent(", ")); - Tooltip.create(new TranslatableComponent("text.rei.view_recipes_for", collect)).queue(); - } - } - } - - public void lateRender(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (REIHelper.getInstance().isOverlayVisible()) { - REIHelperImpl.getSearchField().laterRender(matrices, mouseX, mouseY, delta); - for (Widget widget : widgets) { - if (widget instanceof LateRenderable && (overlayMenu == null || overlayMenu.wrappedMenu != widget)) - widget.render(matrices, mouseX, mouseY, delta); - } - if (overlayMenu != null) { - if (!overlayMenu.inBounds.test(PointHelper.ofMouse())) { - closeOverlayMenu(); - } else { - if (overlayMenu.wrappedMenu.containsMouse(mouseX, mouseY)) { - TOOLTIPS.clear(); - } - overlayMenu.wrappedMenu.render(matrices, mouseX, mouseY, delta); - } - } - } - Screen currentScreen = Minecraft.getInstance().screen; - if (!(currentScreen instanceof DefaultDisplayViewingScreen) || !((DefaultDisplayViewingScreen) currentScreen).choosePageActivated) { - for (Tooltip tooltip : TOOLTIPS) { - if (tooltip != null) - renderTooltip(matrices, tooltip); - } - } - TOOLTIPS.clear(); - if (REIHelper.getInstance().isOverlayVisible()) { - for (Runnable runnable : AFTER_RENDER) { - runnable.run(); - } - AFTER_RENDER.clear(); - } - } - - public void renderTooltip(PoseStack matrices, Tooltip tooltip) { - renderTooltip(matrices, tooltip.getText().stream() - .flatMap(component -> Minecraft.getInstance().font.getSplitter().splitLines(component, 100000, Style.EMPTY).stream()) - .collect(Collectors.toList()), tooltip.getX(), tooltip.getY()); - } - - public void renderTooltip(PoseStack matrices, List lines, int mouseX, int mouseY) { - if (lines.isEmpty()) { - return; - } - List orderedTexts = CollectionUtils.map(lines, Language.getInstance()::getVisualOrder); - renderTooltipInner(matrices, orderedTexts, mouseX, mouseY); - } - - public void renderTooltipInner(PoseStack matrices, List lines, int mouseX, int mouseY) { - if (lines.isEmpty()) { - return; - } - matrices.pushPose(); - matrices.translate(0, 0, 500); - minecraft.screen.renderTooltip(matrices, lines, mouseX, mouseY); - matrices.popPose(); - } - - public void addTooltip(@Nullable Tooltip tooltip) { - if (tooltip != null) - TOOLTIPS.add(tooltip); - } - - public void renderWidgets(PoseStack matrices, int mouseX, int mouseY, float delta) { - if (!REIHelper.getInstance().isOverlayVisible()) - return; - if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) { - leftButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1); - rightButton.setEnabled(ENTRY_LIST_WIDGET.getTotalPages() > 1); - } - for (Widget widget : widgets) { - if (!(widget instanceof LateRenderable)) - widget.render(matrices, mouseX, mouseY, delta); - } - } - - @Override - public boolean mouseScrolled(double mouseX, double mouseY, double amount) { - if (!REIHelper.getInstance().isOverlayVisible()) - return false; - if (overlayMenu != null && overlayMenu.wrappedMenu.mouseScrolled(mouseX, mouseY, amount)) - return true; - if (isInside(PointHelper.ofMouse())) { - if (ENTRY_LIST_WIDGET.mouseScrolled(mouseX, mouseY, amount)) { - return true; - } - if (!Screen.hasControlDown() && !ConfigObject.getInstance().isEntryListWidgetScrolled()) { - if (amount > 0 && leftButton.isEnabled()) - leftButton.onClick(); - else if (amount < 0 && rightButton.isEnabled()) - rightButton.onClick(); - else - return false; - return true; - } - } - if (isNotInExclusionZones(PointHelper.getMouseX(), PointHelper.getMouseY())) { - if (favoritesListWidget != null && favoritesListWidget.mouseScrolled(mouseX, mouseY, amount)) - return true; - } - for (Widget widget : widgets) - if (widget != ENTRY_LIST_WIDGET && (favoritesListWidget == null || widget != favoritesListWidget) - && (overlayMenu == null || widget != overlayMenu.wrappedMenu) - && widget.mouseScrolled(mouseX, mouseY, amount)) - return true; - return false; - } - - @Override - public boolean keyPressed(int keyCode, int scanCode, int modifiers) { - if (REIHelper.getInstance().isOverlayVisible()) { - if (REIHelperImpl.getSearchField().keyPressed(keyCode, scanCode, modifiers)) - return true; - for (GuiEventListener listener : widgets) - if (listener != REIHelperImpl.getSearchField() && listener.keyPressed(keyCode, scanCode, modifiers)) - return true; - } - if (ConfigObject.getInstance().getHideKeybind().matchesKey(keyCode, scanCode)) { - REIHelper.getInstance().toggleOverlayVisible(); - return true; - } - EntryStack stack = ScreenRegistry.getInstance().getFocusedStack(Minecraft.getInstance().screen, PointHelper.ofMouse()); - if (stack != null && !stack.isEmpty()) { - stack = stack.copy(); - if (ConfigObject.getInstance().getRecipeKeybind().matchesKey(keyCode, scanCode)) { - return ViewSearchBuilder.builder().addRecipesFor(stack).open(); - } else if (ConfigObject.getInstance().getUsageKeybind().matchesKey(keyCode, scanCode)) { - return ViewSearchBuilder.builder().addUsagesFor(stack).open(); - } else if (ConfigObject.getInstance().getFavoriteKeyCode().matchesKey(keyCode, scanCode)) { - FavoriteEntry favoriteEntry = FavoriteEntry.fromEntryStack(stack); - if (!ConfigObject.getInstance().getFavoriteEntries().contains(favoriteEntry)) { - ConfigObject.getInstance().getFavoriteEntries().add(favoriteEntry); - } - ConfigManager.getInstance().saveConfig(); - FavoritesListWidget favoritesListWidget = ContainerScreenOverlay.getFavoritesListWidget(); - if (favoritesListWidget != null) - favoritesListWidget.updateSearch(); - return true; - } - } - if (!REIHelper.getInstance().isOverlayVisible()) - return false; - if (ConfigObject.getInstance().getFocusSearchFieldKeybind().matchesKey(keyCode, scanCode)) { - REIHelperImpl.getSearchField().setFocused(true); - setFocused(REIHelperImpl.getSearchField()); - REIHelperImpl.getSearchField().keybindFocusTime = System.currentTimeMillis(); - REIHelperImpl.getSearchField().keybindFocusKey = keyCode; - return true; - } - return false; - } - - @Override - public boolean charTyped(char char_1, int int_1) { - if (!REIHelper.getInstance().isOverlayVisible()) - return false; - if (REIHelperImpl.getSearchField().charTyped(char_1, int_1)) - return true; - for (GuiEventListener listener : widgets) - if (listener != REIHelperImpl.getSearchField() && listener.charTyped(char_1, int_1)) - return true; - return false; - } - - @Override - public List children() { - return widgets; - } - - @Override - public boolean mouseClicked(doubl