From 10fa4cea1da644efe5b3045d3159a3eebdb8c0a8 Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 8 Aug 2019 16:53:46 +0800 Subject: Using fiber as a config lib --- .../me/shedaniel/rei/RoughlyEnoughItemsCore.java | 4 +- .../java/me/shedaniel/rei/api/ConfigManager.java | 6 +- .../java/me/shedaniel/rei/api/ConfigObject.java | 89 ++++++ .../java/me/shedaniel/rei/api/DisplayHelper.java | 2 +- .../me/shedaniel/rei/client/ClientHelperImpl.java | 13 +- .../me/shedaniel/rei/client/ConfigManagerImpl.java | 62 +---- .../java/me/shedaniel/rei/client/ConfigObject.java | 98 ------- .../me/shedaniel/rei/client/ConfigObjectImpl.java | 307 +++++++++++++++++++++ .../java/me/shedaniel/rei/client/ScreenHelper.java | 2 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 32 +-- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 5 +- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 4 +- .../rei/gui/VillagerRecipeViewingScreen.java | 2 +- .../shedaniel/rei/gui/config/ItemCheatingMode.java | 9 + .../rei/gui/config/ItemListOrderingConfig.java | 2 +- .../shedaniel/rei/gui/config/RecipeScreenType.java | 2 +- .../shedaniel/rei/gui/widget/ItemListOverlay.java | 14 +- .../shedaniel/rei/gui/widget/RecipeBaseWidget.java | 4 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 9 +- .../me/shedaniel/rei/gui/widget/SlotWidget.java | 13 +- .../rei/plugin/DefaultAutoCraftingPlugin.java | 2 +- .../me/shedaniel/rei/plugin/DefaultPlugin.java | 17 +- .../shedaniel/rei/utils/ClothScreenRegistry.java | 177 +++--------- 23 files changed, 524 insertions(+), 351 deletions(-) create mode 100644 src/main/java/me/shedaniel/rei/api/ConfigObject.java delete mode 100644 src/main/java/me/shedaniel/rei/client/ConfigObject.java create mode 100644 src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java (limited to 'src/main/java/me/shedaniel') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 5a2a170c8..0f882570a 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -210,14 +210,14 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { return; } lastSync.set(System.currentTimeMillis()); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().registerRecipesInAnotherThread) { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesRegisterRecipesInAnotherThread()) { CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager), SYNC_RECIPES); } else { ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager); } }); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook && screen instanceof AbstractContainerScreen && abstractButtonWidget instanceof TexturedButtonWidget) + if (RoughlyEnoughItemsCore.getConfigManager().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 5f915dfff..e64d5df55 100644 --- a/src/main/java/me/shedaniel/rei/api/ConfigManager.java +++ b/src/main/java/me/shedaniel/rei/api/ConfigManager.java @@ -5,7 +5,7 @@ package me.shedaniel.rei.api; -import me.shedaniel.rei.client.ConfigObject; +import me.zeroeightsix.fiber.exception.FiberException; import net.minecraft.client.gui.screen.Screen; import java.io.IOException; @@ -17,14 +17,14 @@ public interface ConfigManager { * * @throws IOException when error */ - void saveConfig() throws IOException; + void saveConfig() throws IOException, FiberException; /** * Loads the config from the json file, creates the file if not found. * * @throws IOException when error */ - void loadConfig() throws IOException; + void loadConfig() throws IOException, FiberException; /** * Gets the config instance diff --git a/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/src/main/java/me/shedaniel/rei/api/ConfigObject.java new file mode 100644 index 000000000..de6911c96 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/api/ConfigObject.java @@ -0,0 +1,89 @@ +package me.shedaniel.rei.api; + +import me.shedaniel.rei.gui.config.ItemCheatingMode; +import me.shedaniel.rei.gui.config.ItemListOrdering; +import me.shedaniel.rei.gui.config.RecipeScreenType; +import me.zeroeightsix.fiber.tree.ConfigNode; + +public interface ConfigObject { + + ConfigNode getConfigNode(); + + void setCheating(boolean cheating); + + boolean isCheating(); + + ItemListOrdering getItemListOrdering(); + + boolean isItemListAscending(); + + boolean isUsingDarkTheme(); + + boolean shouldAppendModNames(); + + RecipeScreenType getRecipeScreenType(); + + void setRecipeScreenType(RecipeScreenType recipeScreenType); + + boolean isLoadingDefaultPlugin(); + + boolean isSideSearchField(); + + boolean isLeftHandSidePanel(); + + boolean isCraftableFilterEnabled(); + + String getGamemodeCommand(); + + String getGiveCommand(); + + String getWeatherCommand(); + + int getMaxRecipePerPage(); + + boolean doesShowUtilsButtons(); + + boolean doesDisableRecipeBook(); + + boolean areClickableRecipeArrowsEnabled(); + + ItemCheatingMode getItemCheatingMode(); + + boolean isUsingLightGrayRecipeBorder(); + + boolean doesVillagerScreenHavePermanentScrollBar(); + + 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 53d35a3dd..8b745f846 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayHelper.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayHelper.java @@ -112,7 +112,7 @@ public interface DisplayHelper { * @return the item list bounds */ default Rectangle getItemListArea(Rectangle rectangle) { - return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField ? 27 + 22 : 27)); + return new Rectangle(rectangle.x + 2, rectangle.y + 24, rectangle.width - 4, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27)); } /** diff --git a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java index b05f5d15e..700a0ab97 100644 --- a/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/ClientHelperImpl.java @@ -18,6 +18,7 @@ import me.shedaniel.rei.gui.PreRecipeViewingScreen; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.VillagerRecipeViewingScreen; import me.shedaniel.rei.gui.config.RecipeScreenType; +import me.zeroeightsix.fiber.exception.FiberException; import net.fabricmc.api.ClientModInitializer; import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.fabricmc.fabric.api.network.ClientSidePacketRegistry; @@ -124,15 +125,15 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public boolean isCheating() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating; + return RoughlyEnoughItemsCore.getConfigManager().getConfig().isCheating(); } @Override public void setCheating(boolean cheating) { - RoughlyEnoughItemsCore.getConfigManager().getConfig().cheating = cheating; + RoughlyEnoughItemsCore.getConfigManager().getConfig().setCheating(cheating); try { RoughlyEnoughItemsCore.getConfigManager().saveConfig(); - } catch (IOException e) { + } catch (IOException | FiberException e) { e.printStackTrace(); } } @@ -158,7 +159,7 @@ public class ClientHelperImpl implements ClientHelper, 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.getCount() == 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand.replaceAll(" \\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().giveCommand; + String og = cheatedStack.getCount() == 1 ? RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand().replaceAll(" \\{count}", "") : RoughlyEnoughItemsCore.getConfigManager().getConfig().getGiveCommand(); String madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", tagMessage).replaceAll("\\{count}", String.valueOf(cheatedStack.getCount())); if (madeUpCommand.length() > 256) { madeUpCommand = og.replaceAll("\\{player_name}", MinecraftClient.getInstance().player.getEntityName()).replaceAll("\\{item_name}", identifier.getPath()).replaceAll("\\{item_identifier}", identifier.toString()).replaceAll("\\{nbt}", "").replaceAll("\\{count}", String.valueOf(cheatedStack.getCount())); @@ -234,9 +235,9 @@ public class ClientHelperImpl implements ClientHelper, ClientModInitializer { @Override public void openRecipeViewingScreen(Map, List> map) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.VILLAGER) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.VILLAGER) MinecraftClient.getInstance().openScreen(new VillagerRecipeViewingScreen(map)); - else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType == RecipeScreenType.UNSET) + else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() == RecipeScreenType.UNSET) MinecraftClient.getInstance().openScreen(new PreRecipeViewingScreen(map)); else MinecraftClient.getInstance().openScreen(new RecipeViewingScreen(map)); diff --git a/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java b/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java index 587eae8ce..fe0a23101 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigManagerImpl.java @@ -5,12 +5,11 @@ 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 me.shedaniel.rei.api.ConfigManager; +import me.shedaniel.rei.api.ConfigObject; +import me.zeroeightsix.fiber.JanksonSettings; +import me.zeroeightsix.fiber.exception.FiberException; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.Screen; @@ -18,98 +17,65 @@ import net.minecraft.client.resource.language.I18n; import net.minecraft.text.LiteralText; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.nio.file.Files; -import java.nio.file.StandardCopyOption; import java.util.List; public class ConfigManagerImpl implements ConfigManager { - private static final Gson GSON = new GsonBuilder().create(); - private static final Jankson JANKSON = Jankson.builder().build(); - private final File configFile, veryOldConfigFile, oldConfigFile; + private final File configFile; private ConfigObject config; private boolean craftableOnly; public ConfigManagerImpl() { - this.veryOldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "rei.json"); - this.oldConfigFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json"); this.configFile = new File(FabricLoader.getInstance().getConfigDirectory(), "roughlyenoughitems/config.json5"); this.craftableOnly = false; try { loadConfig(); RoughlyEnoughItemsCore.LOGGER.info("[REI] Config is loaded."); - } catch (IOException e) { + } catch (IOException | FiberException e) { e.printStackTrace(); } } @Override - public void saveConfig() throws IOException { + public void saveConfig() throws IOException, FiberException { configFile.getParentFile().mkdirs(); if (!configFile.exists() && !configFile.createNewFile()) { RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObject(); + config = new ConfigObjectImpl(); 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(); + new JanksonSettings().serialize(config.getConfigNode(), Files.newOutputStream(configFile.toPath()), false); } catch (Exception e) { e.printStackTrace(); RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to save config! Overwriting with default config."); - config = new ConfigObject(); + config = new ConfigObjectImpl(); return; } } @Override - public void loadConfig() throws IOException { + public void loadConfig() throws IOException, FiberException { configFile.getParentFile().mkdirs(); - if (!configFile.exists() && veryOldConfigFile.exists()) { - RoughlyEnoughItemsCore.LOGGER.info("[REI] Detected old config file, trying to move it."); - try { - Files.move(veryOldConfigFile.toPath(), configFile.toPath(), StandardCopyOption.REPLACE_EXISTING); - } catch (Exception e) { - e.printStackTrace(); - RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to move config file."); - } - } - 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(); + config = new ConfigObjectImpl(); saveConfig(); return; } boolean failed = false; try { - JsonObject configJson = JANKSON.load(configFile); - String regularized = configJson.toJson(false, false, 0); - - config = GSON.fromJson(regularized, ConfigObject.class); + config = new ConfigObjectImpl(); + new JanksonSettings().deserialize(config.getConfigNode(), Files.newInputStream(configFile.toPath())); } 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(); + config = new ConfigObjectImpl(); } saveConfig(); } diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java deleted file mode 100644 index 5363e672c..000000000 --- a/src/main/java/me/shedaniel/rei/client/ConfigObject.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Roughly Enough Items by Danielshe. - * Licensed under the MIT License. - */ - -package me.shedaniel.rei.client; - -import blue.endless.jankson.Comment; -import me.shedaniel.rei.gui.config.ItemCheatingMode; -import me.shedaniel.rei.gui.config.ItemListOrdering; -import me.shedaniel.rei.gui.config.RecipeScreenType; - -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 = false; - - @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 = "/minecraft: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 default plugin, don't change this unless you understand what you are doing") - public boolean loadDefaultPlugin = true; - - @Comment("Maximum recipes viewed at one time.") - public int maxRecipePerPage = 3; - - @Comment("Toggle utils buttons") - public boolean showUtilsButtons = false; - - @Comment("Disable Recipe Book") - public boolean disableRecipeBook = false; - - public boolean clickableRecipeArrows = true; - - public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; - - public boolean lightGrayRecipeBorder = false; - - public boolean villagerScreenPermanentScrollBar = false; - - public boolean darkTheme = false; - - public boolean registerRecipesInAnotherThread = true; - - public RecipeScreenType screenType = RecipeScreenType.UNSET; - - @Comment( - "The location of choose page dialog, will automatically be set to your last location so there is no need to change this.") - public RelativePoint choosePageDialogPoint = new RelativePoint(.5, .5); - - 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/client/ConfigObjectImpl.java b/src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java new file mode 100644 index 000000000..8fac22090 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/client/ConfigObjectImpl.java @@ -0,0 +1,307 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.client; + +import me.shedaniel.rei.api.ConfigObject; +import me.shedaniel.rei.gui.config.ItemCheatingMode; +import me.shedaniel.rei.gui.config.ItemListOrdering; +import me.shedaniel.rei.gui.config.ItemListOrderingConfig; +import me.shedaniel.rei.gui.config.RecipeScreenType; +import me.zeroeightsix.fiber.exception.FiberException; +import me.zeroeightsix.fiber.tree.ConfigNode; +import me.zeroeightsix.fiber.tree.ConfigValue; +import me.zeroeightsix.fiber.tree.Node; + +public class ConfigObjectImpl implements ConfigObject { + + public ConfigNode configNode = new ConfigNode(); + + private Node general = configNode.fork("!general"); + private Node appearance = configNode.fork("appearance"); + private Node modules = configNode.fork("modules"); + private Node technical = configNode.fork("technical"); + + private ConfigValue cheating = ConfigValue.builder(Boolean.class) + .withParent(general) + .withDefaultValue(false) + .withComment("Declares whether cheating mode is on.") + .withName("cheating") + .build(); + + private ConfigValue itemListOrdering = ConfigValue.builder(ItemListOrderingConfig.class) + .withParent(appearance) + .withDefaultValue(ItemListOrderingConfig.REGISTRY_ASCENDING) + .withComment("The ordering of the items on the item panel.") + .withName("itemListOrdering") + .build(); + + private ConfigValue darkTheme = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares the appearance of REI windows.") + .withName("darkTheme") + .build(); + + private ConfigValue recipeScreenType = ConfigValue.builder(RecipeScreenType.class) + .withParent(appearance) + .withDefaultValue(RecipeScreenType.UNSET) + .withComment("The ordering of the items on the item panel.") + .withName("recipeScreenType") + .build(); + + private ConfigValue loadDefaultPlugin = ConfigValue.builder(Boolean.class) + .withParent(technical) + .withDefaultValue(true) + .withComment("To disable REI's default plugin.\nDon't change this unless you understand what you are doing") + .withName("loadDefaultPlugin") + .build(); + + private ConfigValue sideSearchField = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares the position of the search field.") + .withName("sideSearchField") + .build(); + + private ConfigValue mirrorItemPanel = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares the position of the item list panel.") + .withName("mirrorItemPanel") + .build(); + + private ConfigValue enableCraftableOnlyButton = ConfigValue.builder(Boolean.class) + .withParent(modules) + .withDefaultValue(true) + .withComment("Declares whether the craftable filter button is enabled.") + .withName("enableCraftableOnlyButton") + .build(); + + private ConfigValue gamemodeCommand = ConfigValue.builder(String.class) + .withParent(technical) + .withDefaultValue("/gamemode {gamemode}") + .withComment("Declares the command used to change gamemode.") + .withName("gamemodeCommand") + .build(); + + private ConfigValue giveCommand = ConfigValue.builder(String.class) + .withParent(technical) + .withDefaultValue("/give {player_name} {item_identifier}{nbt} {count}") + .withComment("Declares the command used in servers to cheat items.") + .withName("giveCommand") + .build(); + + private ConfigValue weatherCommand = ConfigValue.builder(String.class) + .withParent(technical) + .withDefaultValue("/weather {weather}") + .withComment("Declares the command used to change weather.") + .withName("weatherCommand") + .build(); + + private ConfigValue maxRecipePerPage = ConfigValue.builder(Integer.class) + .withParent(appearance) + .withDefaultValue(3) + .withComment("Declares the maximum amount of recipes displayed in a page if possible.") + .withName("maxRecipePerPage") + .constraints() + .minNumerical(2) + .maxNumerical(99) + .finish() + .build(); + + private ConfigValue showUtilsButtons = ConfigValue.builder(Boolean.class) + .withParent(modules) + .withDefaultValue(false) + .withComment("Declares whether the utils buttons are shown.") + .withName("showUtilsButtons") + .build(); + + private ConfigValue disableRecipeBook = ConfigValue.builder(Boolean.class) + .withParent(modules) + .withDefaultValue(false) + .withComment("Declares whether REI should remove the recipe book.") + .withName("disableRecipeBook") + .build(); + + private ConfigValue clickableRecipeArrows = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(true) + .withName("clickableRecipeArrows") + .build(); + + private ConfigValue itemCheatingMode = ConfigValue.builder(ItemCheatingMode.class) + .withParent(appearance) + .withDefaultValue(ItemCheatingMode.REI_LIKE) + .withName("itemCheatingMode") + .build(); + + private ConfigValue lightGrayRecipeBorder = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares the appearance of recipe's border.") + .withName("lightGrayRecipeBorder") + .build(); + + private ConfigValue appendModNames = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares whether REI should append mod names to item stacks.") + .withName("appendModNames") + .build(); + + private ConfigValue villagerScreenPermanentScrollBar = ConfigValue.builder(Boolean.class) + .withParent(appearance) + .withDefaultValue(false) + .withComment("Declares how the scrollbar in villager screen act.") + .withName("villagerScreenPermanentScrollBar") + .build(); + + private ConfigValue registerRecipesInAnotherThread = ConfigValue.builder(Boolean.class) + .withParent(technical) + .withDefaultValue(true) + .withName("registerRecipesInAnotherThread") + .build(); + + private ConfigValue choosePageDialogPoint = ConfigValue.builder(RelativePoint.class) + .withParent(technical) + .withDefaultValue(new RelativePoint(.5, .5)) + .withName("choosePageDialogPoint") + .build(); + + public ConfigObjectImpl() throws FiberException { + + } + + @Override + public ConfigNode getConfigNode() { + return configNode; + } + + @Override + public boolean isCheating() { + return cheating.getValue(); + } + + @Override + public void setCheating(boolean cheating) { + this.cheating.setValue(cheating); + } + + @Override + public ItemListOrdering getItemListOrdering() { + return itemListOrdering.getValue().getOrdering(); + } + + @Override + public boolean isItemListAscending() { + return itemListOrdering.getValue().isAscending(); + } + + @Override + public boolean isUsingDarkTheme() { + return darkTheme.getValue().booleanValue(); + } + + @Override + public boolean shouldAppendModNames() { + return appendModNames.getValue().booleanValue(); + } + + @Override + public RecipeScreenType getRecipeScreenType() { + return recipeScreenType.getValue(); + } + + @Override + public void setRecipeScreenType(RecipeScreenType recipeScreenType) { + this.recipeScreenType.setValue(recipeScreenType); + } + + @Override + public boolean isLoadingDefaultPlugin() { + return loadDefaultPlugin.getValue().booleanValue(); + } + + @Override + public boolean isSideSearchField() { + return sideSearchField.getValue().booleanValue(); + } + + @Override + public boolean isLeftHandSidePanel() { + return mirrorItemPanel.getValue().booleanValue(); + } + + @Override + public boolean isCraftableFilterEnabled() { + return enableCraftableOnlyButton.getValue().booleanValue(); + } + + @Override + public String getGamemodeCommand() { + return gamemodeCommand.getValue(); + } + + @Override + public String getGiveCommand() { + return giveCommand.getValue(); + } + + @Override + public String getWeatherCommand() { + return weatherCommand.getValue(); + } + + @Override + public int getMaxRecipePerPage() { + return maxRecipePerPage.getValue().intValue(); + } + + @Override + public boolean doesShowUtilsButtons() { + return showUtilsButtons.getValue().booleanValue(); + } + + @Override + public boolean doesDisableRecipeBook() { + return disableRecipeBook.getValue().booleanValue(); + } + + @Override + public boolean areClickableRecipeArrowsEnabled() { + return clickableRecipeArrows.getValue().booleanValue(); + } + + @Override + public ItemCheatingMode getItemCheatingMode() { + return itemCheatingMode.getValue(); + } + + @Override + public boolean isUsingLightGrayRecipeBorder() { + return lightGrayRecipeBorder.getValue().booleanValue(); + } + + @Override + public boolean doesVillagerScreenHavePermanentScrollBar() { + return villagerScreenPermanentScrollBar.getValue().booleanValue(); + } + + @Override + public boolean doesRegisterRecipesInAnotherThread() { + return registerRecipesInAnotherThread.getValue().booleanValue(); + } + + @Override + public RelativePoint getChoosePageDialogPoint() { + return choosePageDialogPoint.getValue(); + } + + @Override + public void setChoosePageDialogPoint(RelativePoint choosePageDialogPoint) { + this.choosePageDialogPoint.setValue(choosePageDialogPoint); + } +} diff --git a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java index 7f898cc49..a3173e478 100644 --- a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java @@ -82,7 +82,7 @@ public class ScreenHelper implements ClientModInitializer { } public static boolean isDarkModeEnabled() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().darkTheme; + return RoughlyEnoughItemsCore.getConfigManager().getConfig().isUsingDarkTheme(); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index f544e2472..4a9c5258a 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -43,7 +43,7 @@ import java.util.List; import java.util.*; import java.util.stream.Collectors; -public class ContainerScreenOverlay extends AbstractParentElement implements Drawable { +public class ContainerScreenOverlay extends Widget { private static final Identifier CHEST_GUI_TEXTURE = new Identifier("roughlyenoughitems", "textures/gui/recipecontainer.png"); private static final List QUEUED_TOOLTIPS = Lists.newArrayList(); @@ -71,7 +71,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra this.children().clear(); this.window = MinecraftClient.getInstance().window; DisplayHelper.DisplayBoundsHandler boundsHandler = RoughlyEnoughItemsCore.getDisplayHelper().getResponsibleBoundsHandler(MinecraftClient.getInstance().currentScreen.getClass()); - this.rectangle = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); + this.rectangle = RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? boundsHandler.getLeftBounds(MinecraftClient.getInstance().currentScreen) : boundsHandler.getRightBounds(MinecraftClient.getInstance().currentScreen); widgets.add(itemListOverlay = new ItemListOverlay(page)); itemListOverlay.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, false); @@ -117,7 +117,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra if (setPage) page = MathHelper.clamp(page, 0, getTotalPage()); - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 30 : 10, 10, 20, 20, "") { @Override public void onPressed() { if (Screen.hasShiftDown()) { @@ -162,11 +162,11 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } }); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().showUtilsButtons) { - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesShowUtilsButtons()) { + widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? window.getScaledWidth() - 55 : 35, 10, 20, 20, "") { @Override public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().gamemodeCommand.replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().getGamemodeCommand().replaceAll("\\{gamemode}", getNextGameMode(Screen.hasShiftDown()).getName())); } @Override @@ -185,12 +185,12 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } }); - int xxx = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 30 : 10; + int xxx = RoughlyEnoughItemsCore.getConfigManager().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().weatherCommand.replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().getWeatherCommand().replaceAll("\\{weather}", weather.name().toLowerCase(Locale.ROOT))); } @Override @@ -212,7 +212,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } }); - xxx += RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? -25 : 25; + xxx += RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel() ? -25 : 25; } } widgets.add(new ClickableLabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "", getTotalPage() > 0) { @@ -250,7 +250,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra searchTerm = s; itemListOverlay.updateList(boundsHandler, boundsHandler.getItemListArea(rectangle), page, searchTerm, true); }); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isCraftableFilterEnabled()) this.widgets.add(toggleButtonWidget = new CraftableToggleButtonWidget(getCraftableToggleArea()) { @Override public void onPressed() { @@ -319,8 +319,8 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra } private Rectangle getTextFieldArea() { - int widthRemoved = RoughlyEnoughItemsCore.getConfigManager().getConfig().enableCraftableOnlyButton ? 22 : 2; - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField) + int widthRemoved = RoughlyEnoughItemsCore.getConfigManager().getConfig().isCraftableFilterEnabled() ? 22 : 2; + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField()) 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; @@ -351,7 +351,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra @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().mirrorItemPanel, rectangle)) + if (RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler() != null && RoughlyEnoughItemsCore.getDisplayHelper().getBaseBoundsHandler().shouldRecalculateArea(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), rectangle)) shouldReInit = true; if (shouldReInit) init(true); @@ -373,7 +373,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra GlStateManager.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().clickableRecipeArrows) { + if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && RoughlyEnoughItemsCore.getConfigManager().getConfig().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; for (RecipeHelperImpl.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) @@ -532,7 +532,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra 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().clickableRecipeArrows) { + if (MinecraftClient.getInstance().currentScreen instanceof AbstractContainerScreen && RoughlyEnoughItemsCore.getConfigManager().getConfig().areClickableRecipeArrowsEnabled()) { ContainerScreenHooks hooks = (ContainerScreenHooks) MinecraftClient.getInstance().currentScreen; for (RecipeHelperImpl.ScreenClickArea area : RecipeHelper.getInstance().getScreenClickAreas()) if (area.getScreenClass().equals(MinecraftClient.getInstance().currentScreen.getClass())) @@ -556,7 +556,7 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra 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().mirrorItemPanel, mouseX, mouseY); + ActionResult in = handler.isInZone(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), 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 8a0b9c4e9..a39667f25 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -15,6 +15,7 @@ import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.gui.widget.ButtonWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.zeroeightsix.fiber.exception.FiberException; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; import net.minecraft.client.gui.screen.Screen; @@ -53,10 +54,10 @@ 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().screenType = original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER; + RoughlyEnoughItemsCore.getConfigManager().getConfig().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); try { RoughlyEnoughItemsCore.getConfigManager().saveConfig(); - } catch (IOException e) { + } catch (IOException | FiberException e) { e.printStackTrace(); } ClientHelper.getInstance().openRecipeViewingScreen(map); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index a34006240..bfe92d0d0 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -350,12 +350,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().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().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().maxRecipePerPage - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)), 0, Math.min(RoughlyEnoughItemsCore.getConfigManager().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 a9707f9f6..887915a50 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -293,7 +293,7 @@ public class VillagerRecipeViewingScreen extends Screen { @Override public void render(int mouseX, int mouseY, float delta) { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().villagerScreenPermanentScrollBar) { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().doesVillagerScreenHavePermanentScrollBar()) { scrollBarAlphaFutureTime = System.currentTimeMillis(); scrollBarAlphaFuture = 0; scrollBarAlpha = 1; diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java b/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java index e1348e615..6b5189193 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemCheatingMode.java @@ -5,7 +5,16 @@ package me.shedaniel.rei.gui.config; +import net.minecraft.client.resource.language.I18n; + +import java.util.Locale; + public enum ItemCheatingMode { REI_LIKE, JEI_LIKE; + + @Override + public String toString() { + return I18n.translate("config.roughlyenoughitems.itemCheatingMode." + name().toLowerCase(Locale.ROOT)); + } } diff --git a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java index b190ff90f..9d4a46ec2 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java +++ b/src/main/java/me/shedaniel/rei/gui/config/ItemListOrderingConfig.java @@ -38,6 +38,6 @@ public enum ItemListOrderingConfig { @Override public String toString() { - return I18n.translate("text.rei.config.list_ordering_button", I18n.translate(getOrdering().getNameTranslationKey()), I18n.translate(isAscending ? "ordering.rei.ascending" : "ordering.rei.descending")); + return I18n.translate("config.roughlyenoughitems.list_ordering_button", I18n.translate(getOrdering().getNameTranslationKey()), I18n.translate(isAscending ? "ordering.rei.ascending" : "ordering.rei.descending")); } } diff --git a/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java b/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java index 790a405ff..0c9233867 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java +++ b/src/main/java/me/shedaniel/rei/gui/config/RecipeScreenType.java @@ -16,6 +16,6 @@ public enum RecipeScreenType { @Override public String toString() { - return I18n.translate("text.rei.config.recipe_screen_type." + name().toLowerCase(Locale.ROOT)); + return I18n.translate("config.roughlyenoughitems.recipeScreenType." + name().toLowerCase(Locale.ROOT)); } } 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 e81a945cf..f417b87dc 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/ItemListOverlay.java @@ -44,9 +44,9 @@ public class ItemListOverlay extends Widget { static { ASCENDING_COMPARATOR = (itemStack, t1) -> { - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering.equals(ItemListOrdering.name)) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.name)) return tryGetItemStackName(itemStack).compareToIgnoreCase(tryGetItemStackName(t1)); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering.equals(ItemListOrdering.item_groups)) { + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering().equals(ItemListOrdering.item_groups)) { List itemGroups = Arrays.asList(ItemGroup.GROUPS); return itemGroups.indexOf(itemStack.getItem().getGroup()) - itemGroups.indexOf(t1.getItem().getGroup()); } @@ -191,9 +191,9 @@ public class ItemListOverlay extends Widget { if (ClientHelper.getInstance().isCheating()) { if (getCurrentItemStack() != null && !getCurrentItemStack().isEmpty()) { ItemStack cheatedStack = getCurrentItemStack().copy(); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemCheatingMode == ItemCheatingMode.REI_LIKE) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.REI_LIKE) cheatedStack.setCount(button != 1 ? 1 : cheatedStack.getMaxCount()); - else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemCheatingMode == ItemCheatingMode.JEI_LIKE) + else if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemCheatingMode() == ItemCheatingMode.JEI_LIKE) cheatedStack.setCount(button != 0 ? 1 : cheatedStack.getMaxCount()); else cheatedStack.setCount(1); @@ -231,7 +231,7 @@ public class ItemListOverlay 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().mirrorItemPanel, left, top, minecraft.currentScreen, listArea); + ActionResult fit = sortedBoundsHandler.canItemSlotWidgetFit(!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLeftHandSidePanel(), left, top, minecraft.currentScreen, listArea); if (fit != ActionResult.PASS) return fit == ActionResult.SUCCESS; } @@ -257,9 +257,9 @@ public class ItemListOverlay extends Widget { private List processSearchTerm(String searchTerm, List ol, List inventoryItems) { lastSearchArgument.clear(); List os = new LinkedList<>(ol); - if (RoughlyEnoughItemsCore.getConfigManager().getConfig().itemListOrdering != ItemListOrdering.registry) + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().getItemListOrdering() != ItemListOrdering.registry) os = ol.stream().sorted(ASCENDING_COMPARATOR).collect(Collectors.toList()); - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isAscending) + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isItemListAscending()) Collections.reverse(os); String[] splitSearchTerm = StringUtils.splitByWholeSeparatorPreserveAllTokens(searchTerm, "|"); Arrays.stream(splitSearchTerm).forEachOrdered(s -> { 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 830d34f79..04ef0e24d 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeBaseWidget.java @@ -80,7 +80,7 @@ public class RecipeBaseWidget extends WidgetWithBounds { } protected boolean isRendering() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().screenType != RecipeScreenType.VILLAGER; + return RoughlyEnoughItemsCore.getConfigManager().getConfig().getRecipeScreenType() != RecipeScreenType.VILLAGER; } protected int getInnerColor() { @@ -88,7 +88,7 @@ public class RecipeBaseWidget extends WidgetWithBounds { } protected int getTextureOffset() { - return RoughlyEnoughItemsCore.getConfigManager().getConfig().lightGrayRecipeBorder ? 0 : 66; + return RoughlyEnoughItemsCore.getConfigManager().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 152185f10..f56b1fe06 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/RecipeChoosePageWidget.java @@ -9,9 +9,10 @@ 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.client.ConfigObject; +import me.shedaniel.rei.client.ConfigObjectImpl; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; +import me.zeroeightsix.fiber.exception.FiberException; import net.minecraft.client.MinecraftClient; import net.minecraft.client.render.GuiLighting; import net.minecraft.client.resource.language.I18n; @@ -45,7 +46,7 @@ public class RecipeChoosePageWidget extends DraggableWidget { private static Point getPointFromConfig() { Window window = MinecraftClient.getInstance().window; - ConfigObject.RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().choosePageDialogPoint; + ConfigObjectImpl.RelativePoint point = RoughlyEnoughItemsCore.getConfigManager().getConfig().getChoosePageDialogPoint(); return new Point((int) point.getX(window.getScaledWidth()), (int) point.getY(window.getScaledHeight())); } @@ -185,10 +186,10 @@ public class RecipeChoosePageWidget extends DraggableWidget { public void onMouseReleaseMidPoint(Point midPoint) { ConfigManager configManager = RoughlyEnoughItemsCore.getConfigManager(); Window window = minecraft.window; - configManager.getConfig().choosePageDialogPoint = new ConfigObject.RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight()); + configManager.getConfig().setChoosePageDialogPoint(new ConfigObjectImpl.RelativePoint(midPoint.getX() / window.getScaledWidth(), midPoint.getY() / window.getScaledHeight())); try { configManager.saveConfig(); - } catch (IOException e) { + } catch (IOException | FiberException e) { e.printStackTrace(); } } diff --git a/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java index de573f3b2..f078e0b27 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/SlotWidget.java @@ -8,6 +8,7 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import com.mojang.blaze3d.platform.GlStateManager; import me.shedaniel.cloth.api.ClientUtils; +import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.api.ClientHelper; import me.shedaniel.rei.api.Renderer; import me.shedaniel.rei.client.ScreenHelper; @@ -151,13 +152,15 @@ public class SlotWidget extends WidgetWithBounds { } protected List getTooltip(ItemStack itemStack) { - final String modString = ClientHelper.getInstance().getFormattedModFromItem(itemStack.getItem()); List toolTip = Lists.newArrayList(ItemListOverlay.tryGetItemStackToolTip(itemStack, true)); - String s1 = ClientHelper.getInstance().getModFromItem(itemStack.getItem()).toLowerCase(Locale.ROOT); toolTip.addAll(getExtraToolTips(itemStack)); - if (!modString.isEmpty()) { - toolTip.removeIf(s -> s.toLowerCase(Locale.ROOT).contains(s1)); - toolTip.add(modString); + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().shouldAppendModNames()) { + final String modString = ClientHelper.getInstance().getFormattedModFromItem(itemStack.getItem()); + String s1 = ClientHelper.getInstance().getModFromItem(itemStack.getItem()).toLowerCase(Locale.ROOT); + if (!modString.isEmpty()) { + toolTip.removeIf(s -> s.toLowerCase(Locale.ROOT).contains(s1)); + toolTip.add(modString); + } } return toolTip; } diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java index d8719c0fa..07e8850e3 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultAutoCraftingPlugin.java @@ -29,7 +29,7 @@ public class DefaultAutoCraftingPlugin implements REIPluginV0 { @Override public void registerOthers(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerAutoCraftingHandler(new AutoCraftingTableBookHandler()); diff --git a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index b5b124291..5af245884 100644 --- a/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -8,7 +8,9 @@ package me.shedaniel.rei.plugin; import com.google.common.collect.Lists; import com.google.common.collect.Maps; import me.shedaniel.rei.RoughlyEnoughItemsCore; -import me.shedaniel.rei.api.*; +import me.shedaniel.rei.api.DisplayHelper; +import me.shedaniel.rei.api.ItemRegistry; +import me.shedaniel.rei.api.RecipeHelper; import me.shedaniel.rei.api.plugins.REIPluginV0; import me.shedaniel.rei.client.ScreenHelper; import me.shedaniel.rei.gui.RecipeViewingScreen; @@ -42,7 +44,6 @@ import net.minecraft.client.gui.screen.ingame.*; import net.minecraft.client.gui.screen.recipebook.RecipeBookProvider; import net.minecraft.enchantment.Enchantment; import net.minecraft.enchantment.EnchantmentHelper; -import net.minecraft.item.EnchantedBookItem; import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -92,7 +93,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerItems(ItemRegistry itemRegistry) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } Registry.ITEM.stream().forEach(item -> { @@ -115,7 +116,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerPluginCategories(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerCategory(new DefaultCraftingCategory()); @@ -131,7 +132,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerRecipeDisplays(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerRecipes(CRAFTING, ShapelessRecipe.class, DefaultShapelessDisplay::new); @@ -182,7 +183,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerBounds(DisplayHelper displayHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } displayHelper.getBaseBoundsHandler().registerExclusionZones(AbstractInventoryScreen.class, new DefaultPotionEffectExclusionZones()); @@ -272,7 +273,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public Rectangle getItemListArea(Rectangle rectangle) { - return new Rectangle(rectangle.x + 1, rectangle.y + 24, rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().sideSearchField ? 27 + 22 : 27)); + return new Rectangle(rectangle.x + 1, rectangle.y + 24, rectangle.width - 2, rectangle.height - (RoughlyEnoughItemsCore.getConfigManager().getConfig().isSideSearchField() ? 27 + 22 : 27)); } @Override @@ -284,7 +285,7 @@ public class DefaultPlugin implements REIPluginV0 { @Override public void registerOthers(RecipeHelper recipeHelper) { - if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().loadDefaultPlugin) { + if (!RoughlyEnoughItemsCore.getConfigManager().getConfig().isLoadingDefaultPlugin()) { return; } recipeHelper.registerWorkingStations(CRAFTING, new ItemStack(Items.CRAFTING_TABLE)); diff --git a/src/main/java/me/shedaniel/rei/utils/ClothScreenRegistry.java b/src/main/java/me/shedaniel/rei/utils/ClothScreenRegistry.java index d0937bae8..dfda85b2b 100644 --- a/src/main/java/me/shedaniel/rei/utils/ClothScreenRegi