From b7246fa0016888fd52c45f9c77df46f9d791e326 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Fri, 15 Nov 2019 20:09:15 +0800 Subject: Using more of the API instead of the Impl --- .../me/shedaniel/rei/REIModMenuEntryPoint.java | 3 +- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 11 ++- .../java/me/shedaniel/rei/api/ConfigManager.java | 1 + .../java/me/shedaniel/rei/api/ConfigObject.java | 31 ------- .../java/me/shedaniel/rei/api/DisplayHelper.java | 3 +- .../java/me/shedaniel/rei/api/EntryRegistry.java | 1 - src/main/java/me/shedaniel/rei/api/EntryStack.java | 2 +- .../me/shedaniel/rei/api/LiveRecipeGenerator.java | 11 --- .../java/me/shedaniel/rei/api/RecipeHelper.java | 14 ++-- .../shedaniel/rei/api/TransferRecipeDisplay.java | 4 - .../me/shedaniel/rei/api/plugins/REIPluginV0.java | 2 - .../shedaniel/rei/gui/ContainerScreenOverlay.java | 91 ++++++++++----------- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 6 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 7 +- .../rei/gui/VillagerRecipeViewingScreen.java | 5 +- .../me/shedaniel/rei/gui/entries/RecipeEntry.java | 1 + .../rei/gui/entries/SimpleRecipeEntry.java | 26 +----- .../rei/gui/widget/AutoCraftingButtonWidget.java | 3 +- .../gui/widget/CraftableToggleButtonWidget.java | 6 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 37 ++++----- .../me/shedaniel/rei/gui/widget/PanelWidget.java | 6 +- .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 4 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 16 +--- .../shedaniel/rei/impl/BaseBoundsHandlerImpl.java | 6 +- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 19 +++-- .../me/shedaniel/rei/impl/ConfigManagerImpl.java | 3 + .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 20 +---- .../me/shedaniel/rei/impl/DisplayHelperImpl.java | 3 + .../me/shedaniel/rei/impl/EmptyEntryStack.java | 5 ++ .../me/shedaniel/rei/impl/EntryRegistryImpl.java | 3 + .../me/shedaniel/rei/impl/FluidEntryStack.java | 14 +++- .../java/me/shedaniel/rei/impl/ItemEntryStack.java | 15 +++- .../me/shedaniel/rei/impl/ObjectHolderImpl.java | 1 + .../me/shedaniel/rei/impl/RecipeHelperImpl.java | 95 ++++++++++++---------- .../java/me/shedaniel/rei/impl/ScreenHelper.java | 9 +- .../java/me/shedaniel/rei/impl/SearchArgument.java | 4 + .../rei/plugin/DefaultAutoCraftingPlugin.java | 4 +- .../autocrafting/DefaultRecipeBookHandler.java | 3 - .../shedaniel/rei/utils/ClothScreenRegistry.java | 3 +- .../me/shedaniel/rei/utils/CollectionUtils.java | 9 +- 40 files changed, 224 insertions(+), 283 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java b/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java index 6f69001a9..fdb0ec1d9 100644 --- a/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java +++ b/src/main/java/me/shedaniel/rei/REIModMenuEntryPoint.java @@ -6,6 +6,7 @@ package me.shedaniel.rei; import io.github.prospector.modmenu.api.ModMenuApi; +import me.shedaniel.rei.api.ConfigManager; import net.minecraft.client.gui.screen.Screen; import java.util.Optional; @@ -25,7 +26,7 @@ public class REIModMenuEntryPoint implements ModMenuApi { } public Screen getScreen(Screen parent) { - return RoughlyEnoughItemsCore.getConfigManager().getConfigScreen(parent); + return ConfigManager.getInstance().getConfigScreen(parent); } } diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 05588262e..e4c79a060 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -134,6 +134,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.CREATE_ITEMS_PACKET) && ClientSidePacketRegistry.INSTANCE.canServerReceive(RoughlyEnoughItemsNetwork.DELETE_ITEMS_PACKET); } + @SuppressWarnings("deprecation") @Override public void onInitializeClient() { configManager = new ConfigManagerImpl(); @@ -215,14 +216,16 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return; } lastSync.set(System.currentTimeMillis()); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesRegisterRecipesInAnotherThread()) { - CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager), SYNC_RECIPES); + if (ConfigManager.getInstance().getConfig().doesRegisterRecipesInAnotherThread()) { + //noinspection deprecation + CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RecipeHelper.getInstance()).recipesLoaded(recipeManager), SYNC_RECIPES); } else { - ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager); + //noinspection deprecation + ((RecipeHelperImpl) RecipeHelper.getInstance()).recipesLoaded(recipeManager); } }); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesDisableRecipeBook() && screen instanceof AbstractContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) + if (ConfigManager.getInstance().getConfig().doesDisableRecipeBook() && screen instanceof AbstractContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) if (((RecipeBookButtonWidgetHooks) abstractButtonWidget).rei_getTexture().equals(recipeButtonTex)) return ActionResult.FAIL; return ActionResult.PASS; diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java index bd9ea38cb..a1ccecbdb 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -14,6 +14,7 @@ import java.io.IOException; public interface ConfigManager { static ConfigManager getInstance() { + //noinspection deprecation return RoughlyEnoughItemsCore.getConfigManager(); } diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java index e87662de3..fb5d0e66d 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -72,35 +72,4 @@ public interface ConfigObject { boolean doesRegisterRecipesInAnotherThread(); - RelativePoint getChoosePageDialogPoint(); - - void setChoosePageDialogPoint(RelativePoint choosePageDialogPoint); - - public static class RelativePoint { - - private double relativeX, relativeY; - - public RelativePoint(double relativeX, double relativeY) { - this.relativeX = relativeX; - this.relativeY = relativeY; - } - - public double getRelativeX() { - return relativeX; - } - - public double getRelativeY() { - return relativeY; - } - - public double getX(double width) { - return width * relativeX; - } - - public double getY(double height) { - return height * relativeY; - } - - } - } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java index be6ed6a2f..de01337ea 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -17,6 +17,7 @@ import static net.minecraft.util.ActionResult.PASS; public interface DisplayHelper { static DisplayHelper getInstance() { + //noinspection deprecation return RoughlyEnoughItemsCore.getDisplayHelper(); } @@ -117,7 +118,7 @@ public interface DisplayHelper { * @return the item list bounds */ default Rectangle getItemListArea(Rectangle rectangle) { - return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() ? 0 : 22)); + return new Rectangle(rectangle.x + 1, rectangle.y + 2 + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + (ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled() ? 0 : 22), rectangle.width - 2, rectangle.height - (ConfigManager.getInstance().getConfig().getSearchFieldLocation() != SearchFieldLocation.CENTER ? 27 + 22 : 27) + (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled() ? 0 : 22)); } /** diff --git a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java index 03cf0c21e..e2c66bf94 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryRegistry.java +++ b/src/main/java/me/shedaniel/rei/api/EntryRegistry.java @@ -6,7 +6,6 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.annotations.ToBeRemoved; import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; diff --git a/src/main/java/me/shedaniel/rei/api/EntryStack.java b/src/main/java/me/shedaniel/rei/api/EntryStack.java index 905540d56..7d94fb27c 100644 --- a/src/main/java/me/shedaniel/rei/api/EntryStack.java +++ b/src/main/java/me/shedaniel/rei/api/EntryStack.java @@ -10,7 +10,6 @@ import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.impl.EmptyEntryStack; import me.shedaniel.rei.impl.FluidEntryStack; import me.shedaniel.rei.impl.ItemEntryStack; -import net.minecraft.block.Block; import net.minecraft.client.resource.language.I18n; import net.minecraft.fluid.Fluid; import net.minecraft.item.Item; @@ -25,6 +24,7 @@ import java.util.Optional; import java.util.function.Function; import java.util.function.Supplier; +@SuppressWarnings("deprecation") public interface EntryStack { static EntryStack empty() { diff --git a/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java b/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java index 8200fcdc0..588010042 100644 --- a/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java +++ b/src/main/java/me/shedaniel/rei/api/LiveRecipeGenerator.java @@ -5,7 +5,6 @@ package me.shedaniel.rei.api; -import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import java.util.List; @@ -15,20 +14,10 @@ public interface LiveRecipeGenerator { Identifier getCategoryIdentifier(); - @Deprecated - default Optional> getRecipeFor(ItemStack stack) { - return Optional.empty(); - } - default Optional> getRecipeFor(EntryStack entry) { return Optional.empty(); } - @Deprecated - default Optional> getUsageFor(ItemStack stack) { - return Optional.empty(); - } - default Optional> getUsageFor(EntryStack entry) { return Optional.empty(); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index 30915a794..3ddfdf7a4 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -20,10 +20,8 @@ import java.util.function.Predicate; public interface RecipeHelper { - /** - * @return the api instance of {@link me.shedaniel.rei.impl.RecipeHelperImpl} - */ static RecipeHelper getInstance() { + //noinspection deprecation return RoughlyEnoughItemsCore.getRecipeHelper(); } @@ -56,7 +54,7 @@ public interface RecipeHelper { * * @param category the category to register */ - void registerCategory(RecipeCategory category); + void registerCategory(RecipeCategory category); /** * Registers the working stations of a category @@ -106,7 +104,7 @@ public interface RecipeHelper { * * @return the list of categories */ - List getAllCategories(); + List> getAllCategories(); /** * Gets a map of usages for an entry @@ -122,7 +120,7 @@ public interface RecipeHelper { * @param category the category of the display * @return the optional of speed crafting button area */ - Optional getAutoCraftButtonArea(RecipeCategory category); + Optional getAutoCraftButtonArea(RecipeCategory category); /** * Registers a speed crafting button area @@ -155,7 +153,7 @@ public interface RecipeHelper { */ Map, List> getAllRecipes(); - List getAllRecipesFromCategory(RecipeCategory category); + List getAllRecipesFromCategory(RecipeCategory category); /** * Registers a recipe visibility handler @@ -207,7 +205,7 @@ public interface RecipeHelper { */ void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); - void registerScreenClickArea(Rectangle rectangle, Class screenClass, Identifier... categories); + void registerScreenClickArea(Rectangle rectangle, Class> screenClass, Identifier... categories); > void registerRecipes(Identifier category, Class recipeClass, Function mappingFunction); diff --git a/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java index 94f337bc5..40b65488f 100644 --- a/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/TransferRecipeDisplay.java @@ -5,13 +5,9 @@ package me.shedaniel.rei.api; -import com.google.common.collect.Lists; import me.shedaniel.rei.server.ContainerInfo; import net.minecraft.container.Container; -import net.minecraft.item.ItemStack; -import java.util.ArrayList; -import java.util.Collections; import java.util.List; public interface TransferRecipeDisplay extends RecipeDisplay { diff --git a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java index 1c4a5c2a4..2b89abab1 100644 --- a/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java +++ b/src/main/java/me/shedaniel/rei/api/plugins/REIPluginV0.java @@ -10,8 +10,6 @@ import me.shedaniel.rei.api.EntryRegistry; import me.shedaniel.rei.api.REIPluginEntry; import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.api.annotations.ToBeRemoved; -import net.fabricmc.loader.api.SemanticVersion; -import net.fabricmc.loader.util.version.VersionParsingException; public interface REIPluginV0 extends REIPluginEntry { diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index ee35a42a3..d33b38a67 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -11,13 +11,9 @@ import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.ClientHelper; -import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.config.SearchFieldLocation; import me.shedaniel.rei.gui.widget.*; -import me.shedaniel.rei.impl.RecipeHelperImpl; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.Weather; import me.shedaniel.rei.listeners.ContainerScreenHooks; @@ -109,13 +105,14 @@ public class ContainerScreenOverlay extends Widget { //Update Variables this.children().clear(); this.window = MinecraftClient.getInstance().getWindow(); - DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - this.rectangle = RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); + @SuppressWarnings({"RawTypeCanBeGeneric", "rawtypes"}) + DisplayHelper.DisplayBoundsHandler boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); + this.rectangle = ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); widgets.add(entryListWidget = new EntryListWidget(page)); entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false); - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) { - widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.left_arrow")) { + if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { + widgets.add(buttonLeft = new ButtonWidget(rectangle.x, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.left_arrow")) { @Override public void onPressed() { page--; @@ -139,7 +136,7 @@ public class ContainerScreenOverlay extends Widget { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } }); - widgets.add(buttonRight = new ButtonWidget(rectangle.x + rectangle.width - 18, rectangle.y + (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.right_arrow")) { + widgets.add(buttonRight = new ButtonWidget(rectangle.x + rectangle.width - 18, rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 5, 16, 16, new TranslatableText("text.rei.right_arrow")) { @Override public void onPressed() { page++; @@ -168,14 +165,14 @@ public class ContainerScreenOverlay extends Widget { if (setPage) page = MathHelper.clamp(page, 0, getTotalPage()); - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { + widgets.add(new ButtonWidget(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { @Override public void onPressed() { if (Screen.hasShiftDown()) { ClientHelper.getInstance().setCheating(!ClientHelper.getInstance().isCheating()); return; } - RoughlyEnoughItemsCore.getConfigManager().openConfigScreen(ScreenHelper.getLastContainerScreen()); + ConfigManager.getInstance().openConfigScreen(ScreenHelper.getLastContainerScreen()); } @Override @@ -218,11 +215,11 @@ public class ContainerScreenOverlay extends Widget { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } }); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesShowUtilsButtons()) { - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { + if (ConfigManager.getInstance().getConfig().doesShowUtilsButtons()) { + widgets.add(new ButtonWidget(ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { @Override public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); + MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); } @Override @@ -246,12 +243,12 @@ public class ContainerScreenOverlay extends Widget { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } }); - int xxx = RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10; + int xxx = ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10; for (Weather weather : Weather.values()) { widgets.add(new ButtonWidget(xxx, 35, 20, 20, "") { @Override public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); + MinecraftClient.getInstance().player.sendChatMessage(ConfigManager.getInstance().getConfig().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); } @Override @@ -278,11 +275,11 @@ public class ContainerScreenOverlay extends Widget { return isNotInExclusionZones(mouseX, mouseY) && super.containsMouse(mouseX, mouseY); } }); - xxx += RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? -25 : 25; + xxx += ConfigManager.getInstance().getConfig().isLeftHandSidePanel() ? -25 : 25; } } - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) { - widgets.add(new ClickableLabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + (RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10, "", getTotalPage() > 0) { + if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { + widgets.add(new ClickableLabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + (ConfigManager.getInstance().getConfig().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10, "", getTotalPage() > 0) { @Override public void render(int mouseX, int mouseY, float delta) { page = MathHelper.clamp(page, 0, getTotalPage()); @@ -309,20 +306,22 @@ public class ContainerScreenOverlay extends Widget { }); buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0; } - if (ScreenHelper.searchField == null) + if (ScreenHelper.getSearchField() == null) { + //noinspection deprecation ScreenHelper.setSearchField(new OverlaySearchField(0, 0, 0, 0)); - ScreenHelper.searchField.getBounds().setBounds(getTextFieldArea()); - this.widgets.add(ScreenHelper.searchField); - ScreenHelper.searchField.setText(searchTerm); - ScreenHelper.searchField.setChangedListener(s -> { + } + ScreenHelper.getSearchField().getBounds().setBounds(getTextFieldArea()); + this.widgets.add(ScreenHelper.getSearchField()); + ScreenHelper.getSearchField().setText(searchTerm); + ScreenHelper.getSearchField().setChangedListener(s -> { searchTerm = s; entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); }); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isCraftableFilterEnabled()) + if (ConfigManager.getInstance().getConfig().isCraftableFilterEnabled()) this.widgets.add(toggleButtonWidget = new CraftableToggleButtonWidget(getCraftableToggleArea()) { @Override public void onPressed() { - RoughlyEnoughItemsCore.getConfigManager().toggleCraftableOnly(); + ConfigManager.getInstance().toggleCraftableOnly(); entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); } @@ -392,8 +391,8 @@ public class ContainerScreenOverlay extends Widget { } private Rectangle getTextFieldArea() { - int widthRemoved = RoughlyEnoughItemsCore.getConfigManager().getConfig().isCraftableFilterEnabled() ? 22 : 2; - SearchFieldLocation searchFieldLocation = RoughlyEnoughItemsCore.getConfigManager().getConfig().getSearchFieldLocation(); + int widthRemoved = ConfigManager.getInstance().getConfig().isCraftableFilterEnabled() ? 22 : 2; + SearchFieldLocation searchFieldLocation = ConfigManager.getInstance().getConfig().getSearchFieldLocation(); if (searchFieldLocation == SearchFieldLocation.BOTTOM_SIDE) return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18); if (searchFieldLocation == SearchFieldLocation.TOP_SIDE) @@ -427,13 +426,13 @@ public class ContainerScreenOverlay extends Widget { @Override public void render(int mouseX, int mouseY, float delta) { List currentStacks = ClientHelper.getInstance().getInventoryItemsTypes(); - if (RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler() != null && RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler().shouldRecalculateArea(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), rectangle)) + if (DisplayHelper.getInstance().getBaseBoundsHandler() != null && DisplayHelper.getInstance().getBaseBoundsHandler().shouldRecalculateArea(!ConfigManager.getInstance().getConfig().isLeftHandSidePanel(), rectangle)) shouldReInit = true; if (shouldReInit) init(true); - else if (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() && ((currentStacks.size() != ScreenHelper.inventoryStacks.size()) || !hasSameListContent(new LinkedList<>(ScreenHelper.inventoryStacks), currentStacks))) { + else if (ConfigManager.getInstance().isCraftableOnlyEnabled() && ((currentStacks.size() != ScreenHelper.inventoryStacks.size()) || !hasSameListContent(new LinkedList<>(ScreenHelper.inventoryStacks), currentStacks))) { ScreenHelper.inventoryStacks = currentStacks; - DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); + DisplayHelper.DisplayBoundsHandler boundsHandler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); entryListWidget.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); } if (OverlaySearchField.isSearching) { @@ -451,9 +450,9 @@ public class ContainerScreenOverlay extends Widget { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); GuiLighting.disable(); this.renderWidgets(mouseX, mouseY, delta); - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && RoughlyEnoughItemsCore.getConfigManager().getConfig().areClickableRecipeArrowsEnabled()) { + if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigManager.getInstance().getConfig().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; - for (RecipeHelperImpl.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) + for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) if (area.getRectangle().contains(mouseX - hooks.rei_getContainerLeft(), mouseY - hooks.rei_getContainerTop())) { String collect = CollectionUtils.mapAndJoinToString(area.getCategories(), identifier -> RecipeHelper.getInstance().getCategory(identifier).getCategoryName(), ", "); @@ -465,7 +464,7 @@ public class ContainerScreenOverlay extends Widget { public void lateRender(int mouseX, int mouseY, float delta) { if (ScreenHelper.isOverlayVisible()) { - ScreenHelper.searchField.laterRender(mouseX, mouseY, delta); + ScreenHelper.getSearchField().laterRender(mouseX, mouseY, delta); if (toggleButtonWidget != null) toggleButtonWidget.lateRender(mouseX, mouseY, delta); Screen currentScreen = MinecraftClient.getInstance().currentScreen; @@ -509,7 +508,7 @@ public class ContainerScreenOverlay extends Widget { public void renderWidgets(int int_1, int int_2, float float_1) { if (!ScreenHelper.isOverlayVisible()) return; - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) + if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) buttonLeft.enabled = buttonRight.enabled = getTotalPage() > 0; widgets.forEach(widget -> { GuiLighting.disable(); @@ -527,7 +526,7 @@ public class ContainerScreenOverlay extends Widget { if (!ScreenHelper.isOverlayVisible()) return false; if (isInside(PointHelper.fromMouse())) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) { + if (!ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { if (amount > 0 && buttonLeft.enabled) buttonLeft.onPressed(); else if (amount < 0 && buttonRight.enabled) @@ -568,10 +567,10 @@ public class ContainerScreenOverlay extends Widget { if (!ScreenHelper.isOverlayVisible()) return false; if (ClientHelper.getInstance().getFocusSearchFieldKeyBinding().matchesKey(int_1, int_2)) { - ScreenHelper.searchField.setFocused(true); - setFocused(ScreenHelper.searchField); - ScreenHelper.searchField.keybindFocusTime = System.currentTimeMillis(); - ScreenHelper.searchField.keybindFocusKey = int_1; + ScreenHelper.getSearchField().setFocused(true); + setFocused(ScreenHelper.getSearchField()); + ScreenHelper.getSearchField().keybindFocusTime = System.currentTimeMillis(); + ScreenHelper.getSearchField().keybindFocusKey = int_1; return true; } return false; @@ -596,9 +595,9 @@ public class ContainerScreenOverlay extends Widget { public boolean mouseClicked(double double_1, double double_2, int int_1) { if (!ScreenHelper.isOverlayVisible()) return false; - if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && RoughlyEnoughItemsCore.getConfigManager().getConfig().areClickableRecipeArrowsEnabled()) { + if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && ConfigManager.getInstance().getConfig().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; - for (RecipeHelperImpl.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) + for (RecipeHelper.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) if (area.getRectangle().contains(double_1 - hooks.rei_getContainerLeft(), double_2 - hooks.rei_getContainerTop())) { ClientHelper.getInstance().executeViewAllRecipesFromCategories(Arrays.asList(area.getCategories())); @@ -626,8 +625,8 @@ public class ContainerScreenOverlay extends Widget { public boolean isInside(double mouseX, double mouseY) { if (!rectangle.contains(mouseX, mouseY)) return false; - for (DisplayHelper.DisplayBoundsHandler handler : RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { - ActionResult in = handler.isInZone(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), mouseX, mouseY); + for (DisplayHelper.DisplayBoundsHandler handler : DisplayHelper.getInstance().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { + ActionResult in = handler.isInZone(!ConfigManager.getInstance().getConfig().isLeftHandSidePanel(), mouseX, mouseY); if (in != ActionResult.PASS) return in == ActionResult.SUCCESS; } @@ -635,7 +634,7 @@ public class ContainerScreenOverlay extends Widget { } public boolean isNotInExclusionZones(double mouseX, double mouseY) { - for (DisplayHelper.DisplayBoundsHandler handler : RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { + for (DisplayHelper.DisplayBoundsHandler handler : DisplayHelper.getInstance().getSortedBoundsHandlers(MinecraftClient.getInstance().currentScreen.getClass())) { ActionResult in = handler.isInZone(true, mouseX, mouseY); if (in != ActionResult.PASS) return in == ActionResult.SUCCESS; diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index 435920486..fda8ce246 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -7,8 +7,8 @@ package me.shedaniel.rei.gui; import com.google.common.collect.Lists; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.RecipeCategory; import me.shedaniel.rei.api.RecipeDisplay; import me.shedaniel.rei.gui.config.RecipeScreenType; @@ -54,9 +54,9 @@ public class PreRecipeViewingScreen extends Screen { this.widgets.add(new ButtonWidget(width / 2 - 100, height - 40, 200, 20, I18n.translate("text.rei.select")) { @Override public void onPressed() { - RoughlyEnoughItemsCore.getConfigManager().getConfig().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); + ConfigManager.getInstance().getConfig().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); try { - RoughlyEnoughItemsCore.getConfigManager().saveConfig(); + ConfigManager.getInstance().saveConfig(); } catch (IOException | FiberException e) { e.printStackTrace(); } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 3c840d676..4e1e98700 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -9,7 +9,6 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ScreenHelper; @@ -294,7 +293,7 @@ public class RecipeViewingScreen extends Screen { else recipeChoosePageWidget = null; - List> workingStations = RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(selectedCategory.getIdentifier()); + List> workingStations = RecipeHelper.getInstance().getWorkingStations(selectedCategory.getIdentifier()); if (!workingStations.isEmpty()) { int hh = MathHelper.floor((bounds.height - 16) / 18f); int actualHeight = Math.min(hh, workingStations.size()); @@ -353,12 +352,12 @@ public class RecipeViewingScreen extends Screen { if (selectedCategory.getFixedRecipesPerPage() > 0) return selectedCategory.getFixedRecipesPerPage() - 1; int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().getConfig().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(ConfigManager.getInstance().getConfig().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } private int getRecipesPerPageByHeight() { int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)), 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().getConfig().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)), 0, Math.min(ConfigManager.getInstance().getConfig().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 773374bf5..2abae2b1f 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -14,7 +14,6 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWi import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget.Precision; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.widget.*; @@ -101,7 +100,7 @@ public class VillagerRecipeViewingScreen extends Screen { int guiHeight = MathHelper.clamp(category.getDisplayHeight() + 40, 166, largestHeight); this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); - List> workingStations = RoughlyEnoughItemsCore.getRecipeHelper().getWorkingStations(category.getIdentifier()); + List> workingStations = RecipeHelper.getInstance().getWorkingStations(category.getIdentifier()); if (!workingStations.isEmpty()) { int ww = MathHelper.floor((bounds.width - 16) / 18f); int w = Math.min(ww, workingStations.size()); @@ -324,7 +323,7 @@ public class VillagerRecipeViewingScreen extends Screen { @Override public void render(int mouseX, int mouseY, float delta) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesVillagerScreenHavePermanentScrollBar()) { + if (ConfigManager.getInstance().getConfig().doesVillagerScreenHavePermanentScrollBar()) { scrollBarAlphaFutureTime = System.currentTimeMillis(); scrollBarAlphaFuture = 0; scrollBarAlpha = 1; diff --git a/src/main/java/me/shedaniel/rei/gui/entries/RecipeEntry.java b/src/main/java/me/shedaniel/rei/gui/entries/RecipeEntry.java index 58ff880f7..6939837cb 100644 --- a/src/main/java/me/shedaniel/rei/gui/entries/RecipeEntry.java +++ b/src/main/java/me/shedaniel/rei/gui/entries/RecipeEntry.java @@ -106,6 +106,7 @@ public abstract class RecipeEntry extends DrawableHelper implements EntryStack { @Override public ObjectHolder getSetting(Settings settings) { + //noinspection deprecation return new ObjectHolderImpl<>(settings.getDefaultValue()); } diff --git a/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java b/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java index 97d5aab97..f9b35ea3e 100644 --- a/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java +++ b/src/main/java/me/shedaniel/rei/gui/entries/SimpleRecipeEntry.java @@ -13,7 +13,6 @@ import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; -import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; import net.minecraft.util.Pair; import net.minecraft.util.math.MathHelper; @@ -28,30 +27,7 @@ import java.util.stream.Collectors; public class SimpleRecipeEntry extends RecipeEntry { - private static final Comparator ENTRY_COMPARATOR = (o1, o2) -> { - if (o1.getType() == EntryStack.Type.FLUID) { - if (o2.getType() == EntryStack.Type.ITEM) - return -1; - return o1.getFluid().hashCode() - o2.getFluid().hashCode(); - } else if (o2.getType() == EntryStack.Type.FLUID) { - if (o1.getType() == EntryStack.Type.ITEM) - return 1; - return o1.getFluid().hashCode() - o2.getFluid().hashCode(); - } - ItemStack i1 = o1.getItemStack(); - ItemStack i2 = o2.getItemStack(); - if (i1.getItem() == i2.getItem()) { - if (i1.getCount() != i2.getCount()) - return i1.getCount() - i2.getCount(); - int compare = Boolean.compare(i1.hasTag(), i2.hasTag()); - if (compare != 0) - return compare; - if (i1.getTag().getSize() != i2.getTag().getSize()) - return i1.getTag().getSize() - i2.getTag().getSize(); - return i1.getTag().hashCode() - i2.getTag().hashCode(); - } - return i1.getItem().hashCode() - i2.getItem().hashCode(); - }; + private static final Comparator ENTRY_COMPARATOR = Comparator.comparingLong(EntryStack::hashCode); private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); private List inputWidgets; private EntryWidget outputWidget; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java index fbb942235..dbc63d91c 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -11,7 +11,6 @@ import it.unimi.dsi.fastutil.ints.IntList; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.toast.CopyRecipeIdentifierToast; import me.shedaniel.rei.impl.ScreenHelper; @@ -178,7 +177,7 @@ public class AutoCraftingButtonWidget extends ButtonWidget { public boolean keyPressed(int int_1, int int_2, int int_3) { if (displaySupplier.get().getRecipeLocation().isPresent() && ClientHelper.getInstance().getCopyRecipeIdentifierKeyBinding().matchesKey(int_1, int_2) && containsMouse(PointHelper.fromMouse())) { minecraft.keyboard.setClipboard(displaySupplier.get().getRecipeLocation().get().toString()); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isToastDisplayedOnCopyIdentifier()) { + if (ConfigManager.getInstance().getConfig().isToastDisplayedOnCopyIdentifier()) { CopyRecipeIdentifierToast.addToast(I18n.translate("msg.rei.copied_recipe_id"), I18n.translate("msg.rei.recipe_id_details", displaySupplier.get().getRecipeLocation().get().toString())); } return true; diff --git a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java index 3fa7ff784..cc641f49e 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ConfigManager; import net.minecraft.block.Blocks; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; @@ -43,7 +43,7 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { GuiLighting.disable(); MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - int color = RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() ? 939579655 : 956235776; + int color = ConfigManager.getInstance().isCraftableOnlyEnabled() ? 939579655 : 956235776; setBlitOffset(getBlitOffset() + 10); this.fillGradient(getBounds().x, getBounds().y, getBounds().x + getBounds().width, getBounds().y + getBounds().height, color, color); setBlitOffset(0); @@ -60,6 +60,6 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { @Override public Optional getTooltips() { - return Optional.ofNullable(I18n.translate(RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() ? "text.rei.showing_craftable" : "text.rei.showing_all")); + return Optional.ofNullable(I18n.translate(ConfigManager.getInstance().isCraftableOnlyEnabled() ? "text.rei.showing_craftable" : "text.rei.showing_all")); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index d6b4457e5..24ae350b8 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -14,10 +14,7 @@ import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWi import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.ClientHelper; -import me.shedaniel.rei.api.DisplayHelper; -import me.shedaniel.rei.api.EntryStack; -import me.shedaniel.rei.api.RecipeHelper; +import me.shedaniel.rei.api.*; import me.shedaniel.rei.gui.config.ItemCheatingMode; import me.shedaniel.rei.gui.config.ItemListOrdering; import me.shedaniel.rei.impl.ScreenHelper; @@ -49,7 +46,7 @@ import java.util.function.Supplier; @SuppressWarnings({"deprecation", "rawtypes"}) public class EntryListWidget extends Widget { - private static final Supplier RENDER_EXTRA_CONFIG = () -> RoughlyEnoughItemsCore.getConfigManager().getConfig().doesRenderEntryExtraOverlay(); + private static final Supplier RENDER_EXTRA_CONFIG = () -> ConfigManager.getInstance().getConfig().doesRenderEntryExtraOverlay(); private static final String SPACE = " ", EMPTY = ""; private static final Comparator ASCENDING_COMPARATOR; private static List searchBlacklisted = Lists.newArrayList(); @@ -65,9 +62,9 @@ public class EntryListWidget extends Widget { static { ASCENDING_COMPARATOR = (entry, entry1) -> { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.name)) + if (ConfigManager.getInstance().getConfig().getItemListOrdering().equals(ItemListOrdering.name)) return tryGetEntryStackName(entry).compareToIgnoreCase(tryGetEntryStackName(entry1)); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.item_groups)) { + if (ConfigManager.getInstance().getConfig().getItemListOrdering().equals(ItemListOrdering.item_groups)) { if (entry.getType() == EntryStack.Type.ITEM && entry1.getType() == EntryStack.Type.ITEM) { ItemStack stack0 = entry.getItemStack(); ItemStack stack1 = entry1.getItemStack(); @@ -250,7 +247,7 @@ public class EntryListWidget extends Widget { @Override public boolean mouseScrolled(double double_1, double double_2, double double_3) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled() && rectangle.contains(double_1, double_2)) { + if (ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled() && rectangle.contains(double_1, double_2)) { if (scrollBarAlphaFuture == 0) scrollBarAlphaFuture = 1f; if (System.currentTimeMillis() - scrollBarAlphaFutureTime > 300f) @@ -263,7 +260,7 @@ public class EntryListWidget extends Widget { @Override public void render(int int_1, int int_2, float float_1) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesVillagerScreenHavePermanentScrollBar()) { + if (ConfigManager.getInstance().getConfig().doesVillagerScreenHavePermanentScrollBar()) { scrollBarAlphaFutureTime = System.currentTimeMillis(); scrollBarAlphaFuture = 0; scrollBarAlpha = 1; @@ -288,7 +285,7 @@ public class EntryListWidget extends Widget { GuiLighting.disable(); RenderSystem.pushMatrix(); - boolean widgetScrolled = RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled(); + boolean widgetScrolled = ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled(); if (!widgetScrolled) scroll = 0; else { @@ -349,13 +346,13 @@ public class EntryListWidget extends Widget { this.widgets = Lists.newCopyOnWriteArrayList(); calculateListSize(rectangle); if (currentDisplayed.isEmpty() || processSearchTerm) - currentDisplayed = processSearchTerm(searchTerm, RoughlyEnoughItemsCore.getEntryRegistry().getStacksList(), CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create)); + currentDisplayed = processSearchTerm(searchTerm, EntryRegistry.getInstance().getStacksList(), CollectionUtils.map(ScreenHelper.inventoryStacks, EntryStack::create)); int startX = rectangle.getCenterX() - width * 9; int startY = rectangle.getCenterY() - height * 9; this.listArea = new Rectangle(startX, startY, width * 18, height * 18); int fitSlotsPerPage = getTotalFitSlotsPerPage(startX, startY, listArea); int j = page * fitSlotsPerPage; - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) { + if (ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) { height = Integer.MAX_VALUE; j = 0; } @@ -381,7 +378,7 @@ public class EntryListWidget extends Widget { } public int getTotalPage() { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isEntryListWidgetScrolled()) + if (ConfigManager.getInstance().getConfig().isEntryListWidgetScrolled()) return 1; int fitSlotsPerPage = getTotalFitSlotsPerPage(listArea.x, listArea.y, listArea); if (fitSlotsPerPage > 0) @@ -399,8 +396,8 @@ public class EntryListWidget extends Widget { } public boolean canBeFit(int left, int top, Rectangle listArea) { - for (DisplayHelper.DisplayBoundsHandler sortedBoundsHandler : RoughlyEnoughItemsCore.getDisplayHelper().getSortedBoundsHandlers(minecraft.currentScreen.getClass())) { - ActionResult fit = sortedBoundsHandler.canItemSlotWidgetFit(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), left, top, minecraft.currentScreen, listArea); + for (DisplayHelper.DisplayBoundsHandler sortedBoundsHandler : DisplayHelper.getInstance().getSortedBoundsHandlers(minecraft.currentScreen.getClass())) { + ActionResult fit = sortedBoundsHandler.canItemSlotWidgetFit(!ConfigManager.getInstance().getConfig().isLeftHandSidePanel(), left, top, minecraft.currentScreen, listArea); if (fit != ActionResult.PASS) return fit == ActionResult.SUCCESS; } @@ -441,9 +438,9 @@ public class EntryListWidget extends Widget { private List processSearchTerm(String searchTerm, List ol, List inventoryItems) { lastSearchArgument.clear(); List os = new LinkedList<>(ol); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering() != ItemListOrdering.registry) + if (ConfigManager.getInstance().getConfig().getItemListOrdering() != ItemListOrdering.registry) os.sort(ASCENDING_COMPARATOR); - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isItemListAscending()) + if (!ConfigManager.getInstance().getConfig().isItemListAscending()) Collections.reverse(os); String[] splitSearchTerm = StringUtils.splitByWholeSeparatorPreserveAllTokens(searchTerm, "|"); for (String s : splitSearchTerm) { @@ -474,7 +471,7 @@ public class EntryListWidget extends Widget { stacks = os; else stacks = CollectionUtils.filter(os, entry -> filterEntry(entry, lastSearchArgument)); - if (!RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() || stacks.isEmpty() || inventoryItems.isEmpty()) + if (!ConfigManager.getInstance().isCraftableOnlyEnabled() || stacks.isEmpty() || inventoryItems.isEmpty()) return Collections.unmodifiableList(stacks); List workingItems = RecipeHelper.getInstance().findCraftableEntriesByItems(inventoryItems); List newList = Lists.newLinkedList(); @@ -586,9 +583,9 @@ public class EntryListWidget extends Widget { if (containsMouse(mouseX, mouseY) && ClientHelper.getInstance().isCheating()) { EntryStack entry = getCurrentEntry().copy(); if (entry.getType() == EntryStack.Type.ITEM) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.REI_LIKE) + if (ConfigManager.getInstance().getConfig().getItemCheatingMode() == ItemCheatingMode.REI_LIKE) entry.setAmount(button != 1 ? 1 : entry.getItemStack().getMaxCount()); - else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.JEI_LIKE) + else if (ConfigManager.getInstance().getConfig().getItemCheatingMode() == ItemCheatingMode.JEI_LIKE) entry.setAmount(button != 0 ? 1 : entry.getItemStack().getMaxCount()); else entry.setAmount(1); diff --git a/src/main/java/me/shedaniel/rei/gui/widget/PanelWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/PanelWidget.java index 6766bac22..4d8cf3b0c 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/PanelWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/PanelWidget.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.render.GuiLighting; @@ -86,7 +86,7 @@ public class PanelWidget extends WidgetWithBounds { } protected boolean isRendering() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() != RecipeScreenType.VILLAGER; + return ConfigManager.getInstance().getConfig().getRecipeScreenType() != RecipeScreenType.VILLAGER; } protected int getInnerColor() { @@ -98,7 +98,7 @@ public class PanelWidget extends WidgetWithBounds { } protected int getYTextureOffset() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().isUsingLightGrayRecipeBorder() ? 0 : 66; + return ConfigManager.getInstance().getConfig().isUsingLightGrayRecipeBorder() ? 0 : 66; } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java index cd59b513e..c7e95fd3b 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java @@ -6,7 +6,7 @@ package me.shedaniel.rei.gui.widget; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ConfigManager; public class RecipeBaseWidget extends PanelWidget { @@ -16,7 +16,7 @@ public class RecipeBaseWidget extends PanelWidget { @Override protected int getYTextureOffset() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().isUsingLightGrayRecipeBorder() ? 0 : 66; + return ConfigManager.getInstance().getConfig().isUsingLightGrayRecipeBorder() ? 0 : 66; } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java index 51ebbbe21..7d9ea24de 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java @@ -9,19 +9,14 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.api.Point; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.gui.RecipeViewingScreen; -import me.shedaniel.rei.impl.ConfigObjectImpl; import me.shedaniel.rei.impl.ScreenHelper; -import me.zeroeightsix.fiber.exception.FiberException; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.resource.language.I18n; import net.minecraft.client.util.Window; import net.minecraft.util.math.MathHelper; -import java.io.IOException; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -47,8 +42,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { private static Point getPointFromConfig() { Window window = MinecraftClient.getInstance().getWindow(); - ConfigObjectImpl.RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().getChoosePageDialogPoint(); - return new Point(point.getX(window.getScaledWidth()), point.getY(window.getScaledHeight())); + return new Point(window.getScaledWidth() * .5, window.getScaledHeight() * .5); } @Override @@ -185,14 +179,6 @@ public class RecipeChoosePageWidget extends DraggableWidget { @Override public void onMouseReleaseMidPoint(Point midPoint) { - ConfigManager configManager = RoughlyEnoughItemsCore.getConfigManager(); - Window window = minecraft.getWindow(); - configManager.getConfig().setChoosePageDialogPoint(new ConfigObjectImpl.RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight())); - try { - configManager.saveConfig(); - } catch (IOException | FiberException e) { - e.printStackTrace(); - } } } diff --git a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java index 69bd9dada..b47064f6e 100644 --- a/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/BaseBoundsHandlerImpl.java @@ -7,9 +7,9 @@ package me.shedaniel.rei.impl; import com.google.common.collect.Lists; import me.shedaniel.math.api.Rectangle; -import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.BaseBoundsHandler; import me.shedaniel.rei.api.DisplayHelper; +import me.shedaniel.rei.api.annotations.Internal; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; import net.minecraft.util.ActionResult; @@ -19,6 +19,8 @@ import java.util.Comparator; import java.util.List; import java.util.function.Function; +@Deprecated +@Internal public class BaseBoundsHandlerImpl implements BaseBoundsHandler { private static final Comparator RECTANGLE_COMPARER = Comparator.comparingLong(Rectangle::hashCode); @@ -64,7 +66,7 @@ public class BaseBoundsHandlerImpl implements BaseBoundsHandler { } private long currentHashCode(boolean isOnRightSide) { - DisplayHelper.DisplayBoundsHandler handler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); + DisplayHelper.DisplayBoundsHandler handler = DisplayHelper.getInstance().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); return areasHashCode(isOnRightSide ? handler.getRightBounds(MinecraftClient.getInstance().currentScreen) : handler.getLeftBounds(MinecraftClient.getInstance().currentScreen), getCurrentExclusionZones(MinecraftClient.getInstance().currentScreen.getClass(), isOnRightSide, false)); } diff --git a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java index 0115104fb..63a8e3424 100644 --- a/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/impl/ClientHelperImpl.java @@ -11,6 +11,7 @@ import io.netty.buffer.Unpooled; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.RoughlyEnoughItemsNetwork; import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.annotations.Internal; import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeVie