From b537a2600394d7027fcf20178ef26af14008cb41 Mon Sep 17 00:00:00 2001 From: koolkrafter5 Date: Sun, 15 Mar 2026 17:51:30 -0400 Subject: [PATCH] Migrate to GTNHLib config system (#29) Co-authored-by: Nikolay S. --- README.md | 20 ++- dependencies.gradle | 1 + src/main/java/com/gtnh/findit/FindIt.java | 9 +- .../java/com/gtnh/findit/FindItConfig.java | 137 +++++++----------- .../itemfinder/ClientItemFindService.java | 10 +- 5 files changed, 90 insertions(+), 87 deletions(-) diff --git a/README.md b/README.md index 66d2d15..b2beb27 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,22 @@ # FindIt ##### For those times when you just can't remember where you placed your EV Mixer! -This is inspired by the "Search in nearby inventories" feature from 1.7.10 Extra Utilities, and from 1.12+ [FindMe](https://github.com/Buuz135/FindMe). Instead of searching inventories, FindIt will search the world for placed tile entities! +This is inspired by the "Search in nearby inventories" feature from 1.7.10 Extra Utilities, and from 1.12+ [FindMe](https://github.com/Buuz135/FindMe). As well as searching for items and fluids in inventories, FindIt will also search the world for placed tile entities! -Did you forget where you placed your EV Mixer? +Did you forget where you placed your EV Mixer? -Well no problem now! Locate the item in NEI; however over it and hit 'Y' (the default keybind); if it's within range (+/-16 blocks) it will flash particle effects for you to locate it! +Well, no problem now! Locate the item in NEI, hover over it, and hit 'Y' (the default keybind). If it's within range (+/-16 blocks), an outline will flash around it for you to locate it! + +Dependencies: +[NotEnoughItems](https://github.com/GTNewHorizons/NotEnoughItems) +[GTNHLib](https://github.com/GTNewHorizons/GTNHLib) + +FindIt has special support for the following mods' containers: +* [AdventureBackpack](https://github.com/GTNewHorizons/AdventureBackpack2): Finds items and fluids inside backpacks when inside another container. +* [Minecraft Backpack Mod](https://github.com/GTNewHorizons/Minecraft-Backpack-Mod/): Finds items inside backpacks when inside another container. +* [Forestry](https://github.com/GTNewHorizons/ForestryMC): Finds items inside backpacks when inside another container. +* [ProjectRedExploration](https://github.com/GTNewHorizons/ProjectRed): Finds items inside backpacks when inside another container. +* [Draconic Evolution](https://github.com/GTNewHorizons/Draconic-Evolution/): Finds placed items. +* [Thaumcraft 4](https://www.curseforge.com/minecraft/mc-mods/thaumcraft/files/2227552): Finds essentia in placed containers. + * [Aspect Recipe Index](https://github.com/GTNewHorizons/AspectRecipeIndex): Also finds essentia when trying to "find" its aspect items. + * [Thaumcraft NEI Plugin](https://www.curseforge.com/minecraft/mc-mods/thaumcraft-nei-plugin) Also finds essentia when trying to "find" its aspect items. \ No newline at end of file diff --git a/dependencies.gradle b/dependencies.gradle index c57ce7a..f06ac9c 100644 --- a/dependencies.gradle +++ b/dependencies.gradle @@ -2,6 +2,7 @@ dependencies { implementation("com.github.GTNewHorizons:NotEnoughItems:2.8.75-GTNH:dev") + implementation("com.github.GTNewHorizons:GTNHLib:0.9.42:dev") compileOnly("com.github.GTNewHorizons:GT5-Unofficial:5.09.52.348:dev") compileOnly("com.github.GTNewHorizons:EnderIO:2.10.21:dev") diff --git a/src/main/java/com/gtnh/findit/FindIt.java b/src/main/java/com/gtnh/findit/FindIt.java index 5935ead..19ab097 100644 --- a/src/main/java/com/gtnh/findit/FindIt.java +++ b/src/main/java/com/gtnh/findit/FindIt.java @@ -3,6 +3,8 @@ package com.gtnh.findit; import java.util.ArrayList; import java.util.List; +import com.gtnewhorizon.gtnhlib.config.ConfigException; +import com.gtnewhorizon.gtnhlib.config.ConfigurationManager; import com.gtnh.findit.IStackFilter.IStackFilterProvider; import com.gtnh.findit.handler.AdventureBackpackProvider; import com.gtnh.findit.handler.BackpackProvider; @@ -55,8 +57,11 @@ public class FindIt { this.isGregTechLoaded = Loader.isModLoaded("gregtech") && !Loader.isModLoaded("gregapi"); this.isEnderIOLoaded = Loader.isModLoaded("EnderIO"); this.cooldownService = new SearchCooldownService(); - - FindItConfig.setup(event.getSuggestedConfigurationFile()); + try { + ConfigurationManager.registerConfig(FindItConfig.class); + } catch (ConfigException e) { + throw new RuntimeException(e); + } if (event.getSide() == Side.CLIENT) { this.blockFindService = new ClientBlockFindService(); diff --git a/src/main/java/com/gtnh/findit/FindItConfig.java b/src/main/java/com/gtnh/findit/FindItConfig.java index cc6ede6..9527ab7 100644 --- a/src/main/java/com/gtnh/findit/FindItConfig.java +++ b/src/main/java/com/gtnh/findit/FindItConfig.java @@ -1,98 +1,73 @@ package com.gtnh.findit; -import java.io.File; - -import net.minecraftforge.common.config.Configuration; +import com.gtnewhorizon.gtnhlib.config.Config; +@Config(modid = "findit") public class FindItConfig { - public static int SEARCH_RADIUS = 16; - public static int SEARCH_COOLDOWN = 10; - public static int MAX_RESPONSE_SIZE = 20; - public static boolean ENABLE_ROTATE_VIEW = false; - public static boolean USE_PARTICLE_HIGHLIGHTER = false; - public static boolean SEARCH_ITEMS_ON_GROUND = true; - public static boolean SEARCH_IN_GT_PIPES = false; - public static boolean SEARCH_IN_ENDERIO_CONDUITS = false; - public static int ITEM_HIGHLIGHTING_DURATION = 10; - public static int BLOCK_HIGHLIGHTING_DURATION = 8; - public static int ITEM_HIGHLIGHTING_COLOR = 0xFFFF8726; - public static boolean ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = true; + @Config.Comment("Radius to search within") + @Config.DefaultInt(16) + @Config.RangeInt(min = 1) + @Config.Name("SearchRadius") + public static int SEARCH_RADIUS; - public static void setup(final File file) { - final Configuration config = new Configuration(file); - try { - config.load(); + @Config.Comment("Search cooldown in ticks") + @Config.DefaultInt(10) + @Config.RangeInt(min = 0) + @Config.Name("SearchCooldown") + public static int SEARCH_COOLDOWN; - SEARCH_RADIUS = config.get(Configuration.CATEGORY_GENERAL, "SearchRadius", "16", "Radius to search within") - .getInt(); + @Config.Comment("Maximum number of positions that can be displayed by item/block search") + @Config.DefaultInt(20) + @Config.RangeInt(min = 0) + @Config.Name("MaxResponseSize") + public static int MAX_RESPONSE_SIZE; - SEARCH_COOLDOWN = config - .get(Configuration.CATEGORY_GENERAL, "SearchCooldown", "10", "Search cooldown in ticks").getInt(); + @Config.Comment("Rotate the player's view to face found items/blocks after searching") + @Config.DefaultBoolean(false) + @Config.Name("EnableRotateView") + public static boolean ENABLE_ROTATE_VIEW; - MAX_RESPONSE_SIZE = config.get( - Configuration.CATEGORY_GENERAL, - "MaxResponseSize", - "20", - "Maximum number of positions that can be displayed by item/block search").getInt(); + @Config.Comment("Use particles for the block highlighter instead of outlining found blocks") + @Config.DefaultBoolean(false) + @Config.Name("UseParticleHighlighter") + public static boolean USE_PARTICLE_HIGHLIGHTER; - USE_PARTICLE_HIGHLIGHTER = config.get( - Configuration.CATEGORY_GENERAL, - "UseParticleHighlighter", - "false", - "Use Particle for Block Highlighter").getBoolean(); + @Config.Comment("Search items dropped on the ground") + @Config.DefaultBoolean(true) + @Config.Name("SearchItemsOnGround") + public static boolean SEARCH_ITEMS_ON_GROUND; - SEARCH_IN_GT_PIPES = config.get( - Configuration.CATEGORY_GENERAL, - "SearchInGregTechPipes", - "false", - "Search items & fluids in GT pipes").getBoolean(); + @Config.Comment("Search items and fluids in GT pipes") + @Config.DefaultBoolean(false) + @Config.Name("SearchInGregTechPipes") + public static boolean SEARCH_IN_GT_PIPES; - SEARCH_IN_ENDERIO_CONDUITS = config.get( - Configuration.CATEGORY_GENERAL, - "SearchInEnderIOConduits", - "false", - "Search items & fluids in EnderIO conduits").getBoolean(); + @Config.Comment("Search items and fluids in EnderIO conduits") + @Config.DefaultBoolean(false) + @Config.Name("SearchInEnderIOConduits") + public static boolean SEARCH_IN_ENDERIO_CONDUITS; - SEARCH_ITEMS_ON_GROUND = config.get( - Configuration.CATEGORY_GENERAL, - "SearchItemsOnGround", - "true", - "Search items dropped on ground").getBoolean(); + @Config.Comment("Item highlighting duration in seconds") + @Config.DefaultInt(10) + @Config.RangeInt(min = 1) + @Config.Name("ItemHighlightingDuration") + public static int ITEM_HIGHLIGHTING_DURATION; - ITEM_HIGHLIGHTING_DURATION = config - .get(Configuration.CATEGORY_GENERAL, "ItemHighlightingDuration", "10", "Item highlighting duration") - .getInt(); + @Config.Comment("Block highlighting duration in seconds") + @Config.DefaultInt(8) + @Config.RangeInt(min = 1) + @Config.Name("BlockHighlightingDuration") + public static int BLOCK_HIGHLIGHTING_DURATION; - BLOCK_HIGHLIGHTING_DURATION = config.get( - Configuration.CATEGORY_GENERAL, - "BlockHighlightingDuration", - "8", - "Block highlighting duration in seconds").getInt(); + @Config.Comment("Item highlighting color as an ARGB hexadecimal color code.\nDo not prefix with \"0x\"") + @Config.DefaultString("FFFF8726") + @Config.Name("ItemHighlightingColor") + public static String ITEM_HIGHLIGHTING_COLOR; - ENABLE_ROTATE_VIEW = config.get( - Configuration.CATEGORY_GENERAL, - "EnableRotateView", - "false", - "Rotate player's view when searched").getBoolean(); - - ITEM_HIGHLIGHTING_COLOR = Integer.parseUnsignedInt( - config.get( - Configuration.CATEGORY_GENERAL, - "ItemHighlightingColor", - "FFFF8726", - "Item highlighting color as a hexadecimal color code. For example 0xFFFF8726").getString(), - 16); - - ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS = config.get( - Configuration.CATEGORY_GENERAL, - "ItemHighlightingEmptyItemStacks", - "true", - "If true, the item stack size is ignored. If false, items are only highlighted if their stack size is greater than zero.\n" - + "This is useful when working with barrels or storage drawers.") - .getBoolean(); - } catch (Exception ignore) {} finally { - if (config.hasChanged()) config.save(); - } - } + @Config.Comment("If true, the item stack size is ignored. If false, items are only highlighted if their stack size is greater than zero.\n" + + "This is useful when working with barrels or storage drawers.") + @Config.DefaultBoolean(true) + @Config.Name("ItemHighlightingEmptyItemStacks") + public static boolean ITEM_HIGHLIGHTING_EMPTY_ITEMSTACKS; } diff --git a/src/main/java/com/gtnh/findit/service/itemfinder/ClientItemFindService.java b/src/main/java/com/gtnh/findit/service/itemfinder/ClientItemFindService.java index 8a8cc82..90ec2df 100644 --- a/src/main/java/com/gtnh/findit/service/itemfinder/ClientItemFindService.java +++ b/src/main/java/com/gtnh/findit/service/itemfinder/ClientItemFindService.java @@ -138,7 +138,15 @@ public class ClientItemFindService extends ItemFindService { } } - slotHighlighter.highlightSlots(gui, highlightedSlots, FindItConfig.ITEM_HIGHLIGHTING_COLOR); + slotHighlighter.highlightSlots(gui, highlightedSlots, getItemHighlightingColor()); + } + } + + private static int getItemHighlightingColor() { + try { + return Integer.parseUnsignedInt(FindItConfig.ITEM_HIGHLIGHTING_COLOR, 16); + } catch (NumberFormatException e) { + return 0xFFFF8726; } }