Skip to content

Commit 8f0b1ed

Browse files
mt1006Prospector
authored andcommitted
Fix parent map issues (#775)
- Fixed issues with parent mods
1 parent 69e0bea commit 8f0b1ed

1 file changed

Lines changed: 29 additions & 4 deletions

File tree

src/main/java/com/terraformersmc/modmenu/ModMenu.java

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,21 +127,46 @@ public void onInitializeClient() {
127127
Map<String, Mod> dummyParents = new HashMap<>();
128128

129129
// Initialize parent map
130+
HashSet<String> modParentSet = new HashSet<>();
130131
for (Mod mod : MODS.values()) {
131132
String parentId = mod.getParent();
132-
if (parentId != null) {
133-
Mod parent = MODS.getOrDefault(parentId, dummyParents.get(parentId));
133+
if (parentId == null) {
134+
ROOT_MODS.put(mod.getId(), mod);
135+
continue;
136+
}
137+
138+
Mod parent;
139+
modParentSet.clear();
140+
while (true) {
141+
parent = MODS.getOrDefault(parentId, dummyParents.get(parentId));
134142
if (parent == null) {
135143
if (mod instanceof FabricMod) {
136144
parent = new FabricDummyParentMod((FabricMod) mod, parentId);
137145
dummyParents.put(parentId, parent);
138146
}
139147
}
140-
PARENT_MAP.put(parent, mod);
141-
} else {
148+
149+
parentId = parent != null ? parent.getParent() : null;
150+
if (parentId == null) {
151+
// It will most likely end here in the first iteration
152+
break;
153+
}
154+
155+
if (modParentSet.contains(parentId)) {
156+
LOGGER.warn("Mods contain each other as parents: {}", modParentSet);
157+
parent = null;
158+
break;
159+
}
160+
modParentSet.add(parentId);
161+
}
162+
163+
if (parent == null) {
142164
ROOT_MODS.put(mod.getId(), mod);
165+
continue;
143166
}
167+
PARENT_MAP.put(parent, mod);
144168
}
169+
145170
MODS.putAll(dummyParents);
146171
ModMenuEventHandler.register();
147172
}

0 commit comments

Comments
 (0)