-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add config file to hide Forge mod presence from Fabric mods
Help disable broken mod integrations of Fabric mods Relates to #449
- Loading branch information
Showing
4 changed files
with
76 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/main/java/dev/su5ed/sinytra/connector/locator/ConnectorConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters