diff --git a/src/main/java/com/chaosthedude/explorerscompass/config/ConfigHandler.java b/src/main/java/com/chaosthedude/explorerscompass/config/ConfigHandler.java index 95d6adb..573b47b 100644 --- a/src/main/java/com/chaosthedude/explorerscompass/config/ConfigHandler.java +++ b/src/main/java/com/chaosthedude/explorerscompass/config/ConfigHandler.java @@ -24,6 +24,7 @@ public static class General { public final ForgeConfigSpec.BooleanValue displayCoordinates; public final ForgeConfigSpec.IntValue maxRadius; public final ForgeConfigSpec.ConfigValue> structureBlacklist; + public final ForgeConfigSpec.ConfigValue> structureWhitelist; public final ForgeConfigSpec.IntValue maxSamples; General(ForgeConfigSpec.Builder builder) { @@ -42,6 +43,9 @@ public static class General { desc = "A list of structures that the compass will not display in the GUI and will not be able to search for. Wildcard character * can be used to match any number of characters, and ? can be used to match one character. Ex: [\"minecraft:stronghold\", \"minecraft:endcity\", \"minecraft:*village*\"]"; structureBlacklist = builder.comment(desc).define("structureBlacklist", new ArrayList()); + desc = "A list of the only structures that the compass will display in the GUI and will be able to search for, if empty all structures (except for black listed ones) are enabled. Wildcard character * can be used to match any number of characters, and ? can be used to match one character. Ex: [\"minecraft:stronghold\", \"minecraft:endcity\", \"minecraft:*village*\"]"; + structureWhitelist = builder.comment(desc).define("structureWhitelist", new ArrayList()); + desc = "The maximum number of samples to be taken when searching for a structure."; maxSamples = builder.comment(desc).defineInRange("maxSamples", 100000, 0, 100000000); diff --git a/src/main/java/com/chaosthedude/explorerscompass/util/StructureUtils.java b/src/main/java/com/chaosthedude/explorerscompass/util/StructureUtils.java index 0bf4c1e..5518562 100644 --- a/src/main/java/com/chaosthedude/explorerscompass/util/StructureUtils.java +++ b/src/main/java/com/chaosthedude/explorerscompass/util/StructureUtils.java @@ -86,7 +86,11 @@ public static Holder getHolderForStructure(ServerLevel level, Structu public static List getAllowedStructureKeys(ServerLevel level) { final List structures = new ArrayList(); for (Structure structure : getStructureRegistry(level)) { - if (structure != null && getKeyForStructure(level, structure) != null && !structureIsBlacklisted(level, structure) && !structureIsHidden(level, structure)) { + if (structure != null && + getKeyForStructure(level, structure) != null && + !structureIsBlacklisted(level, structure) && + structureIsWhitelisted(level, structure) && + !structureIsHidden(level, structure)) { structures.add(getKeyForStructure(level, structure)); } } @@ -102,6 +106,22 @@ public static boolean structureIsBlacklisted(ServerLevel level, Structure struct } return false; } + + public static boolean structureIsWhitelisted(ServerLevel level, Structure structure) { + final List structureWhitelist = ConfigHandler.GENERAL.structureWhitelist.get(); + + if (structureWhitelist.isEmpty()) { + return true; + } + + for (String structureKey : structureWhitelist) { + if (getKeyForStructure(level, structure).toString().matches(convertToRegex(structureKey))) { + return true; + } + } + + return false; + } public static boolean structureIsHidden(ServerLevel level, Structure structure) { final Registry structureRegistry = getStructureRegistry(level);