Skip to content

Commit

Permalink
Add config file to hide Forge mod presence from Fabric mods
Browse files Browse the repository at this point in the history
Help disable broken mod integrations of Fabric mods

Relates to #449
  • Loading branch information
Su5eD committed Oct 29, 2023
1 parent 40e1feb commit 8d3c689
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 10 deletions.
24 changes: 23 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Here's a minimal configuration example:
"cloth_config": "cloth-config2",
"embeddium": [
"sodium",
"rubidium"
"magnesium"
]
}
}
Expand All @@ -151,3 +151,25 @@ Let's go over it line-by-line.
- Secondly, we have `aliases`. This JSON object contains all of our alises for various mods.
Keys inside the object represent mod IDs to be aliased. The value can be either a single **string**, or an **array** in case
we want to provide multiple aliases for one mod.

### Hiding Forge mods presence

Fabric mods tend to integrate with others based on their modid. If you happen to install a Forge version of a mod that
a Fabric mod wants to integrate with, it might result in a crash, as the two versions' code is different.
Most of the time, mods provide toggles for integrations in their config. If that's not the case, your other option is
hiding the Forge mod's presence from Fabric mods entirely, which might help in disabling the problematic integration.

This can be configured in the `connector.json` file, located in your config folder.
If it doesn't exist yet, Connector will create a new one with empty values.

Inside, the `hiddenMods` field is defined as a list of mod IDs (strings). Forge mod IDs found in this list will be
excluded from being added to `FabricLoader`, hiding their presence from Fabric mods.

Here's a minimal configuration example:
```json
{
"hiddenMods": [
"examplemod"
]
}
```
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.logging.LogUtils;
import dev.su5ed.sinytra.connector.ConnectorUtil;
import dev.su5ed.sinytra.connector.locator.ConnectorConfig;
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint;
import net.fabricmc.loader.impl.FabricLoaderImpl;
import net.fabricmc.loader.impl.entrypoint.EntrypointUtils;
Expand Down Expand Up @@ -91,14 +92,18 @@ public static void init() {
LOGGER.debug("Starting early connector loader setup");
ProgressMeter progress = StartupNotificationManager.addProgressBar("[Connector] Early Setup", 0);
try {
List<String> hiddenMods = ConnectorConfig.INSTANCE.get().hiddenMods();
// Find all connector loader mods
List<ModInfo> mods = LoadingModList.get().getMods();
for (ModInfo mod : mods) {
if (mod.getOwningFile().getFileProperties().containsKey(ConnectorUtil.CONNECTOR_MARKER)) {
CONNECTOR_MODIDS.add(mod.getModId());
CONNECTOR_MODS.add(mod);
}
}
List<ModInfo> mods = LoadingModList.get().getMods().stream()
.filter(mod -> {
if (mod.getOwningFile().getFileProperties().containsKey(ConnectorUtil.CONNECTOR_MARKER)) {
CONNECTOR_MODIDS.add(mod.getModId());
CONNECTOR_MODS.add(mod);
return true;
}
return !hiddenMods.contains(mod.getModId());
})
.toList();
// Propagate mods to fabric
FabricLoaderImpl.INSTANCE.addFmlMods(mods);
} catch (Throwable t) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package dev.su5ed.sinytra.connector.locator;

import com.google.common.base.Suppliers;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.mojang.logging.LogUtils;
import net.minecraftforge.fml.loading.FMLPaths;
import org.slf4j.Logger;

import java.io.Reader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.function.Supplier;

public record ConnectorConfig(List<String> hiddenMods) {
private static final ConnectorConfig DEFAULT = new ConnectorConfig(List.of());
private static final Logger LOGGER = LogUtils.getLogger();
public static final Supplier<ConnectorConfig> INSTANCE = Suppliers.memoize(() -> {
Path path = FMLPaths.CONFIGDIR.get().resolve("connector.json");
try {
if (Files.exists(path)) {
Gson gson = new Gson();
try (Reader reader = Files.newBufferedReader(path)) {
return gson.fromJson(reader, ConnectorConfig.class);
}
}
else {
Gson gson = new GsonBuilder().setPrettyPrinting().disableHtmlEscaping().create();
Files.writeString(path, gson.toJson(DEFAULT));
}
} catch (Throwable t) {
LOGGER.error("Error loading Connector configuration", t);
}
return DEFAULT;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,10 @@ private static void readMixinConfigPackages(File input, JarFile jarFile, ZipEntr
}
if (json.has("package")) {
String pkg = json.get("package").getAsString();
String pkgPath = pkg.replace('.', '/') + '/';
packages.add(pkgPath);
if (!pkg.isEmpty()) {
String pkgPath = pkg.replace('.', '/') + '/';
packages.add(pkgPath);
}
}
} catch (IOException e) {
LOGGER.error("Error reading mixin config entry {} in file {}", entry.getName(), input.getAbsolutePath());
Expand Down

0 comments on commit 8d3c689

Please sign in to comment.