Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public static class General {
public final ForgeConfigSpec.BooleanValue displayCoordinates;
public final ForgeConfigSpec.IntValue maxRadius;
public final ForgeConfigSpec.ConfigValue<List<String>> structureBlacklist;
public final ForgeConfigSpec.ConfigValue<List<String>> structureWhitelist;
public final ForgeConfigSpec.IntValue maxSamples;

General(ForgeConfigSpec.Builder builder) {
Expand All @@ -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<String>());

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<String>());

desc = "The maximum number of samples to be taken when searching for a structure.";
maxSamples = builder.comment(desc).defineInRange("maxSamples", 100000, 0, 100000000);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ public static Holder<Structure> getHolderForStructure(ServerLevel level, Structu
public static List<ResourceLocation> getAllowedStructureKeys(ServerLevel level) {
final List<ResourceLocation> structures = new ArrayList<ResourceLocation>();
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));
}
}
Expand All @@ -102,6 +106,22 @@ public static boolean structureIsBlacklisted(ServerLevel level, Structure struct
}
return false;
}

public static boolean structureIsWhitelisted(ServerLevel level, Structure structure) {
final List<String> 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<Structure> structureRegistry = getStructureRegistry(level);
Expand Down