diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-03-07 22:21:06 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-03-07 22:21:06 +0800 |
| commit | 8cd1f1a9804f980c1666079c99bafb6330c77723 (patch) | |
| tree | 449f74c31bf73a4106b2cb9bc7fb5635925b2328 /src/main/java | |
| parent | e5909b2fa40428d2a25a4f727a49a4f4fc47ad01 (diff) | |
| download | RoughlyEnoughItems-8cd1f1a9804f980c1666079c99bafb6330c77723.tar.gz RoughlyEnoughItems-8cd1f1a9804f980c1666079c99bafb6330c77723.tar.bz2 RoughlyEnoughItems-8cd1f1a9804f980c1666079c99bafb6330c77723.zip | |
Config with comments
Diffstat (limited to 'src/main/java')
16 files changed, 291 insertions, 211 deletions
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<Identifier, REIPlugin> 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<ItemStack> 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<QueuedTooltip> 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; |
