Skip to content

Commit

Permalink
Fix parent map issues (#775)
Browse files Browse the repository at this point in the history
  • Loading branch information
mt1006 authored Sep 15, 2024
1 parent 69e0bea commit e9d838c
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/main/java/com/terraformersmc/modmenu/ModMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,21 +127,46 @@ public void onInitializeClient() {
Map<String, Mod> dummyParents = new HashMap<>();

// Initialize parent map
HashSet<String> modParentSet = new HashSet<>();
for (Mod mod : MODS.values()) {
String parentId = mod.getParent();
if (parentId != null) {
Mod parent = MODS.getOrDefault(parentId, dummyParents.get(parentId));
if (parentId == null) {
ROOT_MODS.put(mod.getId(), mod);
continue;
}

Mod parent;
modParentSet.clear();
while (true) {
parent = MODS.getOrDefault(parentId, dummyParents.get(parentId));
if (parent == null) {
if (mod instanceof FabricMod) {
parent = new FabricDummyParentMod((FabricMod) mod, parentId);
dummyParents.put(parentId, parent);
}
}
PARENT_MAP.put(parent, mod);
} else {

parentId = parent != null ? parent.getParent() : null;
if (parentId == null) {
// It will most likely end here in the first iteration
break;
}

if (modParentSet.contains(parentId)) {
LOGGER.warn("Mods contain each other as parents: {}", modParentSet);
parent = null;
break;
}
modParentSet.add(parentId);
}

if (parent == null) {
ROOT_MODS.put(mod.getId(), mod);
continue;
}
PARENT_MAP.put(parent, mod);
}

MODS.putAll(dummyParents);
ModMenuEventHandler.register();
}
Expand Down

0 comments on commit e9d838c

Please sign in to comment.