Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parent map issues #775

Merged
merged 1 commit into from
Sep 15, 2024
Merged
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
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
Loading