From 8cd1f1a9804f980c1666079c99bafb6330c77723 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 7 Mar 2019 22:21:06 +0800 Subject: Config with comments --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 8 +- .../java/me/shedaniel/rei/api/ConfigManager.java | 19 ++++ .../java/me/shedaniel/rei/client/ClientHelper.java | 8 +- .../java/me/shedaniel/rei/client/ConfigHelper.java | 75 -------------- .../me/shedaniel/rei/client/ConfigManager.java | 111 +++++++++++++++++++++ .../java/me/shedaniel/rei/client/ConfigObject.java | 49 +++++++++ .../me/shedaniel/rei/client/ItemListOrdering.java | 17 ++++ .../java/me/shedaniel/rei/client/REIConfig.java | 26 ----- .../shedaniel/rei/client/REIItemListOrdering.java | 19 ---- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 30 +++--- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 4 +- .../me/shedaniel/rei/gui/config/ConfigScreen.java | 102 ++++++++++--------- .../gui/widget/CraftableToggleButtonWidget.java | 4 +- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 18 ++-- .../rei/gui/widget/RecipeChoosePageWidget.java | 10 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 2 +- 16 files changed, 291 insertions(+), 211 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/ConfigManager.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ConfigHelper.java create mode 100644 src/main/java/me/shedaniel/rei/client/ConfigManager.java create mode 100644 src/main/java/me/shedaniel/rei/client/ConfigObject.java create mode 100644 src/main/java/me/shedaniel/rei/client/ItemListOrdering.java delete mode 100644 src/main/java/me/shedaniel/rei/client/REIConfig.java delete mode 100644 src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java (limited to 'src/main/java') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 0dd3ed0d2..dddb955e0 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -35,14 +35,14 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali private static final PluginDisabler PLUGIN_DISABLER = new PluginDisablerImpl(); private static final ItemRegistry ITEM_REGISTRY = new ItemRegistryImpl(); private static final Map plugins = Maps.newHashMap(); - private static ConfigHelper configHelper; + private static ConfigManager configManager; public static RecipeHelper getRecipeHelper() { return RECIPE_HELPER; } - public static ConfigHelper getConfigHelper() { - return configHelper; + public static me.shedaniel.rei.api.ConfigManager getConfigManager() { + return configManager; } public static ItemRegistry getItemRegisterer() { @@ -74,7 +74,7 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer, ModInitiali @SuppressWarnings("deprecation") @Override public void onInitializeClient() { - configHelper = new ConfigHelper(); + configManager = new ConfigManager(); // If pluginloader is not installed, base functionality should still remain if (!FabricLoader.getInstance().isModLoaded("pluginloader")) { diff --git a/src/main/java/me/shedaniel/rei/api/ConfigManager.java b/src/main/java/me/shedaniel/rei/api/ConfigManager.java new file mode 100644 index 000000000..2e951f103 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -0,0 +1,19 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.client.ConfigObject; + +import java.io.IOException; + +public interface ConfigManager { + + void saveConfig() throws IOException; + + void loadConfig() throws IOException; + + ConfigObject getConfig(); + + boolean isCraftableOnlyEnabled(); + + void toggleCraftableOnly(); + +} diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelper.java b/src/main/java/me/shedaniel/rei/client/ClientHelper.java index b91d43f32..ad14db62f 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelper.java @@ -64,13 +64,13 @@ public class ClientHelper implements ClientModInitializer { } public static boolean isCheating() { - return RoughlyEnoughItemsCore.getConfigHelper().getConfig().cheating; + return RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating; } public static void setCheating(boolean cheating) { - RoughlyEnoughItemsCore.getConfigHelper().getConfig().cheating = cheating; + RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = cheating; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); } @@ -95,7 +95,7 @@ public class ClientHelper implements ClientModInitializer { } else { Identifier identifier = Registry.ITEM.getId(cheatedStack.getItem()); String tagMessage = cheatedStack.copy().getTag() != null && !cheatedStack.copy().getTag().isEmpty() ? cheatedStack.copy().getTag().asString() : ""; - String og = cheatedStack.getAmount() != 1 ? RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand.replaceAll(" \\{count}", "").replaceAll("\\{count}", "") : RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand; + String og = cheatedStack.getAmount() != 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand.replaceAll(" \\{count}", "").replaceAll("\\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand; String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); if (madeUpCommand.length() > 256) { madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getAmount())); diff --git a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java b/src/main/java/me/shedaniel/rei/client/ConfigHelper.java deleted file mode 100644 index 38f00a804..000000000 --- a/src/main/java/me/shedaniel/rei/client/ConfigHelper.java +++ /dev/null @@ -1,75 +0,0 @@ -package me.shedaniel.rei.client; - -import me.shedaniel.rei.RoughlyEnoughItemsCore; -import net.fabricmc.loader.api.FabricLoader; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.io.InputStreamReader; -import java.nio.file.Files; - -public class ConfigHelper { - - private final File configFile; - private REIConfig config; - private boolean craftableOnly; - - public ConfigHelper() { - this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json"); - this.craftableOnly = false; - try { - loadConfig(); - RoughlyEnoughItemsCore.LOGGER.info("REI: Config is loaded."); - } catch (IOException e) { - e.printStackTrace(); - } - } - - public void saveConfig() throws IOException { - configFile.getParentFile().mkdirs(); - if (!configFile.exists() && !configFile.createNewFile()) { - RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config."); - config = new REIConfig(); - return; - } - FileWriter writer = new FileWriter(configFile, false); - try { - REIConfig.GSON.toJson(config, writer); - } finally { - writer.close(); - } - } - - public void loadConfig() throws IOException { - if (!configFile.exists() || !configFile.canRead()) { - config = new REIConfig(); - saveConfig(); - return; - } - boolean failed = false; - try { - config = REIConfig.GSON.fromJson(new InputStreamReader(Files.newInputStream(configFile.toPath())), REIConfig.class); - } catch (Exception e) { - failed = true; - } - if (failed || config == null) { - RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load config! Overwriting with default config."); - config = new REIConfig(); - } - saveConfig(); - } - - public REIConfig getConfig() { - return config; - } - - public boolean craftableOnly() { - return craftableOnly; - } - - public void toggleCraftableOnly() { - craftableOnly = !craftableOnly; - } - -} diff --git a/src/main/java/me/shedaniel/rei/client/ConfigManager.java b/src/main/java/me/shedaniel/rei/client/ConfigManager.java new file mode 100644 index 000000000..c05442b41 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/ConfigManager.java @@ -0,0 +1,111 @@ +package me.shedaniel.rei.client; + +import blue.endless.jankson.Jankson; +import blue.endless.jankson.JsonObject; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import net.fabricmc.loader.api.FabricLoader; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.StandardCopyOption; + +public class ConfigManager implements me.shedaniel.rei.api.ConfigManager { + + private static final Gson GSON = new GsonBuilder().create(); + private static final Jankson JANKSON = Jankson.builder().build(); + private final File configFile, oldConfigFile; + private ConfigObject config; + private boolean craftableOnly; + + public ConfigManager() { + this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json"); + this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json"); + this.craftableOnly = false; + try { + loadConfig(); + RoughlyEnoughItemsCore.LOGGER.info("REI: Config is loaded."); + } catch (IOException e) { + e.printStackTrace(); + } + } + + @Override + public void saveConfig() throws IOException { + configFile.getParentFile().mkdirs(); + if (!configFile.exists() && !configFile.createNewFile()) { + RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config."); + config = new ConfigObject(); + return; + } + try { + String result = JANKSON.toJson(config).toJson(true, true, 0); + if (!configFile.exists()) + configFile.createNewFile(); + FileOutputStream out = new FileOutputStream(configFile, false); + + out.write(result.getBytes()); + out.flush(); + out.close(); + } catch (Exception e) { + e.printStackTrace(); + RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to save config! Overwriting with default config."); + config = new ConfigObject(); + return; + } + } + + @Override + public void loadConfig() throws IOException { + configFile.getParentFile().mkdirs(); + if (!configFile.exists() && oldConfigFile.exists()) { + RoughlyEnoughItemsCore.LOGGER.info("REI: Detected old config file, trying to move it."); + try { + Files.move(oldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); + } catch (Exception e) { + e.printStackTrace(); + RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to move config file."); + } + } + if (!configFile.exists() || !configFile.canRead()) { + RoughlyEnoughItemsCore.LOGGER.warn("REI: Config not found! Creating one."); + config = new ConfigObject(); + saveConfig(); + return; + } + boolean failed = false; + try { + JsonObject configJson = JANKSON.load(configFile); + String regularized = configJson.toJson(false, false, 0); + + config = GSON.fromJson(regularized, ConfigObject.class); + } catch (Exception e) { + e.printStackTrace(); + failed = true; + } + if (failed || config == null) { + RoughlyEnoughItemsCore.LOGGER.error("REI: Failed to load config! Overwriting with default config."); + config = new ConfigObject(); + } + saveConfig(); + } + + @Override + public ConfigObject getConfig() { + return config; + } + + @Override + public boolean isCraftableOnlyEnabled() { + return craftableOnly; + } + + @Override + public void toggleCraftableOnly() { + craftableOnly = !craftableOnly; + } + +} diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java new file mode 100644 index 000000000..ba697d99a --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/ConfigObject.java @@ -0,0 +1,49 @@ +package me.shedaniel.rei.client; + +import blue.endless.jankson.Comment; +import me.shedaniel.rei.api.RelativePoint; + +public class ConfigObject { + + public boolean cheating = false; + + @Comment("The ordering of the items on the item panel.") + public ItemListOrdering itemListOrdering = ItemListOrdering.registry; + + @Comment("The ordering of the items on the item panel.") + public boolean isAscending = true; + + @Comment("To toggle the craftable button next to the search field.") + public boolean enableCraftableOnlyButton = true; + + @Comment("True: search field will be on the side (left / right), false: in the middle") + public boolean sideSearchField = false; + + @Comment("The command used in servers to cheat items") + public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; + + @Comment("The command used to change gamemode") + public String gamemodeCommand = "/gamemode {gamemode}"; + + @Comment("The command used to change weather") + public String weatherCommand = "/weather {weather}"; + + @Comment("True: item panel on the left, false: on the right") + public boolean mirrorItemPanel = false; + + @Comment("To disable REI's defualt plugin, don't change this unless you understand what you are doing") + public boolean loadDefaultPlugin = true; + + @Comment("Toggle the credits button") + public boolean disableCreditsButton = false; + + @Comment("Maximum recipes viewed at one time.") + public int maxRecipePerPage = 3; + + @Comment("Toggle utils buttons") + public boolean showUtilsButtons = false; + + @Comment("The location of choose page dialog") + public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); + +} diff --git a/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java new file mode 100644 index 000000000..b9ef1f874 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/ItemListOrdering.java @@ -0,0 +1,17 @@ +package me.shedaniel.rei.client; + +public enum ItemListOrdering { + + registry("ordering.rei.registry"), name("ordering.rei.name"), item_groups("ordering.rei.item_groups"); + + private String nameTranslationKey; + + ItemListOrdering(String nameTranslationKey) { + this.nameTranslationKey = nameTranslationKey; + } + + public String getNameTranslationKey() { + return nameTranslationKey; + } + +} diff --git a/src/main/java/me/shedaniel/rei/client/REIConfig.java b/src/main/java/me/shedaniel/rei/client/REIConfig.java deleted file mode 100644 index 90950fddb..000000000 --- a/src/main/java/me/shedaniel/rei/client/REIConfig.java +++ /dev/null @@ -1,26 +0,0 @@ -package me.shedaniel.rei.client; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import me.shedaniel.rei.api.RelativePoint; - -public class REIConfig { - - public static Gson GSON = new GsonBuilder().setPrettyPrinting().create(); - - public boolean cheating = false; - public REIItemListOrdering itemListOrdering = REIItemListOrdering.REGISTRY; - public boolean isAscending = true; - public boolean enableCraftableOnlyButton = true; - public boolean sideSearchField = false; - public String giveCommand = "/give {player_name} {item_identifier}{nbt} {count}"; - public String gamemodeCommand = "/gamemode {gamemode}"; - public String weatherCommand = "/weather {weather}"; - public boolean mirrorItemPanel = false; - public boolean loadDefaultPlugin = true; - public boolean disableCreditsButton = false; - public int maxRecipePerPage = 3; - public boolean showUtilsButtons = false; - public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); - -} diff --git a/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java b/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java deleted file mode 100644 index 8f9e317eb..000000000 --- a/src/main/java/me/shedaniel/rei/client/REIItemListOrdering.java +++ /dev/null @@ -1,19 +0,0 @@ -package me.shedaniel.rei.client; - -import com.google.gson.annotations.SerializedName; - -public enum REIItemListOrdering { - - @SerializedName("registry") REGISTRY("ordering.rei.registry"), @SerializedName("name") NAME("ordering.rei.name"), @SerializedName("item_groups") ITEM_GROUPS("ordering.rei.item_groups"); - - private String nameTranslationKey; - - REIItemListOrdering(String nameTranslationKey) { - this.nameTranslationKey = nameTranslationKey; - } - - public String getNameTranslationKey() { - return nameTranslationKey; - } - -} diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 3d8fcd654..015d9747a 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -73,7 +73,7 @@ public class ContainerScreenOverlay extends ScreenComponent { } }); page = MathHelper.clamp(page, 0, getTotalPage()); - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { @Override public void onPressed(int button, double mouseX, double mouseY) { if (Screen.isShiftPressed()) { @@ -103,18 +103,18 @@ public class ContainerScreenOverlay extends ScreenComponent { } } }); - if (!RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton) - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel ? window.getScaledWidth() - 50 : 10, window.getScaledHeight() - 30, 40, 20, I18n.translate("text.rei.credits")) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().disableCreditsButton) + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 50 : 10, window.getScaledHeight() - 30, 40, 20, I18n.translate("text.rei.credits")) { @Override public void onPressed(int button, double mouseX, double mouseY) { MinecraftClient.getInstance().openScreen(new CreditsScreen(GuiHelper.getLastContainerScreen())); } }); - if (RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons) { - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons) { + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { @Override public void onPressed(int button, double mouseX, double mouseY) { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigHelper().getConfig().gamemodeCommand.replaceAll("\\{gamemode}", getNextGameMode().getName())); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand.replaceAll("\\{gamemode}", getNextGameMode().getName())); } @Override @@ -125,10 +125,10 @@ public class ContainerScreenOverlay extends ScreenComponent { addTooltip(QueuedTooltip.create(I18n.translate("text.rei.gamemode_button.tooltip", getGameModeText(getNextGameMode())).split("\n"))); } }); - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel ? window.getScaledWidth() - 80 : 60, 10, 20, 20, "") { + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 80 : 60, 10, 20, 20, "") { @Override public void onPressed(int button, double mouseX, double mouseY) { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigHelper().getConfig().weatherCommand.replaceAll("\\{weather}", getNextWeather().getName().toLowerCase())); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", getNextWeather().getName().toLowerCase())); } @Override @@ -178,11 +178,11 @@ public class ContainerScreenOverlay extends ScreenComponent { GuiHelper.searchField.getBounds().setBounds(getTextFieldArea()); this.widgets.add(GuiHelper.searchField); GuiHelper.searchField.setText(searchTerm); - if (RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton) this.widgets.add(new CraftableToggleButtonWidget(getCraftableToggleArea()) { @Override public void onPressed(int button, double mouseX, double mouseY) { - RoughlyEnoughItemsCore.getConfigHelper().toggleCraftableOnly(); + RoughlyEnoughItemsCore.getConfigManager().toggleCraftableOnly(); itemListOverlay.updateList(getItemListArea(), page, searchTerm); } }); @@ -256,8 +256,8 @@ public class ContainerScreenOverlay extends ScreenComponent { } private Rectangle getTextFieldArea() { - int widthRemoved = RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton ? 22 : 2; - if (RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField) + int widthRemoved = RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton ? 22 : 2; + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField) return new Rectangle(rectangle.x + 2, window.getScaledHeight() - 22, rectangle.width - 6 - widthRemoved, 18); if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) { RecipeViewingScreen widget = (RecipeViewingScreen) MinecraftClient.getInstance().currentScreen; @@ -278,7 +278,7 @@ public class ContainerScreenOverlay extends ScreenComponent { } private Rectangle getItemListArea() { - return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField ? 27 + 22 : 27)); + return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField ? 27 + 22 : 27)); } public Rectangle getRectangle() { @@ -289,7 +289,7 @@ public class ContainerScreenOverlay extends ScreenComponent { List currentStacks = ClientHelper.getInventoryItemsTypes(); if (getLeft() != lastLeft) onInitialized(); - else if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && (!hasSameListContent(new LinkedList<>(GuiHelper.inventoryStacks), currentStacks) || (currentStacks.size() != GuiHelper.inventoryStacks.size()))) { + else if (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() && (!hasSameListContent(new LinkedList<>(GuiHelper.inventoryStacks), currentStacks) || (currentStacks.size() != GuiHelper.inventoryStacks.size()))) { GuiHelper.inventoryStacks = ClientHelper.getInventoryItemsTypes(); itemListOverlay.updateList(getItemListArea(), page, searchTerm); } @@ -336,7 +336,7 @@ public class ContainerScreenOverlay extends ScreenComponent { } private Rectangle calculateBoundary() { - if (!RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel) { int startX = GuiHelper.getLastContainerScreenHooks().rei_getContainerLeft() + GuiHelper.getLastContainerScreenHooks().rei_getContainerWidth() + 10; int width = window.getScaledWidth() - startX; if (MinecraftClient.getInstance().currentScreen instanceof RecipeViewingScreen) { diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 541940375..2948870f7 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -263,12 +263,12 @@ public class RecipeViewingScreen extends Screen { if (selectedCategory.getDisplaySettings().getFixedRecipesPerPage() > 0) return selectedCategory.getDisplaySettings().getFixedRecipesPerPage() - 1; int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } private int getRecipesPerPageByHeight() { int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java b/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java index d1383c377..4af12577b 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/config/ConfigScreen.java @@ -1,9 +1,11 @@ package me.shedaniel.rei.gui.config; +import com.google.common.collect.Lists; import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.client.REIItemListOrdering; +import me.shedaniel.rei.client.ItemListOrdering; +import me.shedaniel.rei.gui.widget.QueuedTooltip; import me.shedaniel.rei.gui.widget.TextFieldWidget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.InputListener; @@ -16,14 +18,17 @@ import net.minecraft.text.TranslatableTextComponent; import java.awt.*; import java.io.IOException; import java.util.Arrays; +import java.util.List; public class ConfigScreen extends Screen { + private final List tooltipList; private Screen parent; private ConfigEntryListWidget entryListWidget; public ConfigScreen(Screen parent) { this.parent = parent; + this.tooltipList = Lists.newArrayList(); } @Override @@ -60,9 +65,9 @@ public class ConfigScreen extends Screen { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField; + RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField = !RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -72,20 +77,20 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().sideSearchField); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField); } })); entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.list_ordering"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() { @Override public boolean onPressed(int button, double mouseX, double mouseY) { - int index = Arrays.asList(REIItemListOrdering.values()).indexOf(RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering) + 1; - if (index >= REIItemListOrdering.values().length) { + int index = Arrays.asList(ItemListOrdering.values()).indexOf(RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering) + 1; + if (index >= ItemListOrdering.values().length) { index = 0; - RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending; + RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending = !RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending; } - RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering = REIItemListOrdering.values()[index]; + RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering = ItemListOrdering.values()[index]; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -95,16 +100,16 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return I18n.translate("text.rei.config.list_ordering_button", I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering.getNameTranslationKey()), I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending ? "ordering.rei.ascending" : "ordering.rei.descending")); + return I18n.translate("text.rei.config.list_ordering_button", I18n.translate(RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering.getNameTranslationKey()), I18n.translate(RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending ? "ordering.rei.ascending" : "ordering.rei.descending")); } })); entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.mirror_rei"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel; + RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel = !RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -114,7 +119,7 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().mirrorItemPanel); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel); } })); entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.modules"))); @@ -122,9 +127,9 @@ public class ConfigScreen extends Screen { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton; + RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton = !RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -134,16 +139,16 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().enableCraftableOnlyButton); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton); } })); entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.load_default_plugin"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin; + RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin = !RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -153,26 +158,24 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin); } @Override public void draw(me.shedaniel.rei.gui.widget.ButtonWidget button, Point mouse, float delta) { button.draw(mouse.x, mouse.y, delta); - if (button.isHighlighted(mouse)) { - GuiLighting.disable(); - drawTooltip(Arrays.asList(I18n.translate("text.rei.config.load_default_plugin.restart_tooltip").split("\n")), mouse.x, mouse.y); - GuiLighting.disable(); - } + if (button.isHighlighted(mouse)) + tooltipList.add(QueuedTooltip.create(I18n.translate("text.rei.config.load_default_plugin.restart_tooltip").split("\n"))); + } })); entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.disable_credits_button"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton; + RoughlyEnoughItemsCore.getConfigManager().getConfig().disableCreditsButton = !RoughlyEnoughItemsCore.getConfigManager().getConfig().disableCreditsButton; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -182,16 +185,16 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().disableCreditsButton); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().disableCreditsButton); } })); entryListWidget.configAddEntry(new ConfigEntry.ButtonConfigEntry(new TranslatableTextComponent("text.rei.config.enable_util_buttons"), new ConfigEntry.ButtonConfigEntry.ConfigEntryButtonProvider() { @Override public boolean onPressed(int button, double mouseX, double mouseY) { if (button == 0) - RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons = !RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons; + RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons = !RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); return false; @@ -201,7 +204,7 @@ public class ConfigScreen extends Screen { @Override public String getText() { - return getTrueFalseText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().showUtilsButtons); + return getTrueFalseText(RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons); } })); entryListWidget.configAddEntry(new ConfigEntry.CategoryTitleConfigEntry(new TranslatableTextComponent("text.rei.config.advanced"))); @@ -209,15 +212,15 @@ public class ConfigScreen extends Screen { @Override public void onInitWidget(TextFieldWidget widget) { widget.setMaxLength(99999); - widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand); + widget.setText(RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand); widget.setSuggestion(I18n.translate("text.rei.give_command.suggestion")); } @Override public void onUpdateText(TextFieldWidget button, String text) { - RoughlyEnoughItemsCore.getConfigHelper().getConfig().giveCommand = text; + RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand = text; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); } @@ -226,25 +229,22 @@ public class ConfigScreen extends Screen { @Override public void draw(TextFieldWidget widget, Point mouse, float delta) { widget.draw(mouse.x, mouse.y, delta); - if (widget.isHighlighted(mouse)) { - GuiLighting.disable(); - drawTooltip(Arrays.asList(I18n.translate("text.rei.give_command.tooltip").split("\n")), mouse.x, mouse.y); - GuiLighting.disable(); - } + if (widget.isHighlighted(mouse)) + tooltipList.add(QueuedTooltip.create(I18n.translate("text.rei.give_command.tooltip").split("\n"))); } })); entryListWidget.configAddEntry(new ConfigEntry.TextFieldConfigEntry(new TranslatableTextComponent("text.rei.gamemode_command"), new ConfigEntry.TextFieldConfigEntry.ConfigEntryTextFieldProvider() { @Override public void onInitWidget(TextFieldWidget widget) { widget.setMaxLength(99999); - widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().gamemodeCommand); + widget.setText(RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand); } @Override public void onUpdateText(TextFieldWidget button, String text) { - RoughlyEnoughItemsCore.getConfigHelper().getConfig().gamemodeCommand = text; + RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand = text; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); } @@ -254,14 +254,14 @@ public class ConfigScreen extends Screen { @Override public void onInitWidget(TextFieldWidget widget) { widget.setMaxLength(99999); - widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().weatherCommand); + widget.setText(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand); } - + @Override public void onUpdateText(TextFieldWidget button, String text) { - RoughlyEnoughItemsCore.getConfigHelper().getConfig().weatherCommand = text; + RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand = text; try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); } @@ -271,7 +271,7 @@ public class ConfigScreen extends Screen { @Override public void onInitWidget(TextFieldWidget widget) { widget.setMaxLength(2); - widget.setText(RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage + ""); + widget.setText(RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage + ""); widget.stripInvaild = s -> { StringBuilder stringBuilder_1 = new StringBuilder(); char[] var2 = s.toCharArray(); @@ -291,8 +291,8 @@ public class ConfigScreen extends Screen { public void onUpdateText(TextFieldWidget button, String text) { if (isInvaildNumber(text)) try { - RoughlyEnoughItemsCore.getConfigHelper().getConfig().maxRecipePerPage = Integer.valueOf(text); - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().getConfig().maxRecipePerPage = Integer.valueOf(text); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (Exception e) { } } @@ -316,7 +316,7 @@ public class ConfigScreen extends Screen { @Override public void onPressed(double double_1, double double_2) { try { - RoughlyEnoughItemsCore.getConfigHelper().saveConfig(); + RoughlyEnoughItemsCore.getConfigManager().saveConfig(); } catch (IOException e) { e.printStackTrace(); } @@ -337,6 +337,10 @@ public class ConfigScreen extends Screen { this.entryListWidget.draw(int_1, int_2, float_1); this.drawStringCentered(this.fontRenderer, I18n.translate("text.rei.config"), this.screenWidth / 2, 16, 16777215); super.draw(int_1, int_2, float_1); + GuiLighting.disable(); + tooltipList.forEach(queuedTooltip -> drawTooltip(queuedTooltip.getText(), queuedTooltip.getLocation().x, queuedTooltip.getLocation().y)); + tooltipList.clear(); + GuiLighting.disable(); } @Override 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 211f8a7f0..8006d5846 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/CraftableToggleButtonWidget.java @@ -41,14 +41,14 @@ public abstract class CraftableToggleButtonWidget extends ButtonWidget { MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.zOffset = 100f; - this.drawTexturedRect(getBounds().x, getBounds().y, (56 + (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() ? 0 : 20)), 202, 20, 20); + this.drawTexturedRect(getBounds().x, getBounds().y, (56 + (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() ? 0 : 20)), 202, 20, 20); this.zOffset = 0f; if (getBounds().contains(mouseX, mouseY)) drawTooltip(); } private void drawTooltip() { - GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.translate(RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() ? "text.rei.showing_craftable" : "text.rei.showing_all")))); + GuiHelper.getLastOverlay().addTooltip(new QueuedTooltip(ClientHelper.getMouseLocation(), Arrays.asList(I18n.translate(RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() ? "text.rei.showing_craftable" : "text.rei.showing_all")))); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java index 14a2b1d60..129ef1051 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -5,7 +5,7 @@ import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.client.ClientHelper; import me.shedaniel.rei.client.GuiHelper; -import me.shedaniel.rei.client.REIItemListOrdering; +import me.shedaniel.rei.client.ItemListOrdering; import me.shedaniel.rei.client.SearchArgument; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.DrawableHelper; @@ -103,16 +103,16 @@ public class ItemListOverlay extends DrawableHelper implements IWidget { List os = new LinkedList<>(ol), stacks = Lists.newArrayList(), finalStacks = Lists.newArrayList(); List itemGroups = new LinkedList<>(Arrays.asList(ItemGroup.GROUPS)); itemGroups.add(null); - REIItemListOrdering ordering = RoughlyEnoughItemsCore.getConfigHelper().getConfig().itemListOrdering; - if (ordering != REIItemListOrdering.REGISTRY) + ItemListOrdering ordering = RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering; + if (ordering != ItemListOrdering.registry) Collections.sort(os, (itemStack, t1) -> { - if (ordering.equals(REIItemListOrdering.NAME)) + if (ordering.equals(ItemListOrdering.name)) return itemStack.getDisplayName().getFormattedText().compareToIgnoreCase(t1.getDisplayName().getFormattedText()); - if (ordering.equals(REIItemListOrdering.ITEM_GROUPS)) + if (ordering.equals(ItemListOrdering.item_groups)) return itemGroups.indexOf(itemStack.getItem().getItemGroup()) - itemGroups.indexOf(t1.getItem().getItemGroup()); return 0; }); - if (!RoughlyEnoughItemsCore.getConfigHelper().getConfig().isAscending) + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending) Collections.reverse(os); String[] splitSearchTerm = StringUtils.splitByWholeSeparatorPreserveAllTokens(searchTerm, "|"); Arrays.stream(splitSearchTerm).forEachOrdered(s -> { @@ -135,14 +135,14 @@ public class ItemListOverlay extends DrawableHelper implements IWidget { }); if (splitSearchTerm.length == 0) stacks.addAll(os); - List workingItems = RoughlyEnoughItemsCore.getConfigHelper().craftableOnly() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol); - if (RoughlyEnoughItemsCore.getConfigHelper().craftableOnly()) { + List workingItems = RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled() && inventoryItems.size() > 0 ? new ArrayList<>() : new LinkedList<>(ol); + if (RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled()) { RecipeHelper.getInstance().findCraftableByItems(inventoryItems).forEach(workingItems::add); workingItems.addAll(inventoryItems); } final List finalWorkingItems = workingItems; finalStacks.addAll(stacks.stream().filter(itemStack -> { - if (!RoughlyEnoughItemsCore.getConfigHelper().craftableOnly()) + if (!RoughlyEnoughItemsCore.getConfigManager().isCraftableOnlyEnabled()) return true; for(ItemStack workingItem : finalWorkingItems) if (itemStack.isEqualIgnoreTags(workingItem)) 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 8baa6c161..5b043caa4 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java @@ -3,8 +3,8 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.RelativePoint; -import me.shedaniel.rei.client.ConfigHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; @@ -38,7 +38,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { private static Point getPointFromConfig() { Window window = MinecraftClient.getInstance().window; - RelativePoint point = RoughlyEnoughItemsCore.getConfigHelper().getConfig().choosePageDialogPoint; + RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().choosePageDialogPoint; return new Point((int) point.getX(window.getScaledWidth()), (int) point.getY(window.getScaledHeight())); } @@ -175,11 +175,11 @@ public class RecipeChoosePageWidget extends DraggableWidget { @Override public void onMouseReleaseMidPoint(Point midPoint) { - ConfigHelper configHelper = RoughlyEnoughItemsCore.getConfigHelper(); + ConfigManager configManager = RoughlyEnoughItemsCore.getConfigManager(); Window window = MinecraftClient.getInstance().window; - configHelper.getConfig().choosePageDialogPoint = new RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight()); + configManager.getConfig().choosePageDialogPoint = new RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight()); try { - configHelper.saveConfig(); + configManager.saveConfig(); } catch (IOException e) { e.printStackTrace(); } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index c37150e59..b74f97911 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -48,7 +48,7 @@ public class DefaultPlugin implements REIPlugin { @Override public void onFirstLoad(PluginDisabler pluginDisabler) { - if (!RoughlyEnoughItemsCore.getConfigHelper().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_ITEMS); pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_CATEGORIES); pluginDisabler.disablePluginFunction(PLUGIN, PluginFunction.REGISTER_RECIPE_DISPLAYS); -- cgit