From 60b008c27bff6d62fa334ffcfe887d86f5a76a15 Mon Sep 17 00:00:00 2001 From: RawDiamondMC Date: Sat, 3 Aug 2024 20:25:10 +0800 Subject: [PATCH] more api for platform --- .../kessoku/lib/platform/api/ModLoader.java | 6 +++++ .../lib/platform/impl/ModLoaderImpl.java | 21 ++++++++++++++++ .../lib/platform/impl/ModLoaderImpl.java | 24 +++++++++++++++++++ 3 files changed, 51 insertions(+) diff --git a/platform-common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java b/platform-common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java index 2818abc8..195c0972 100644 --- a/platform-common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java +++ b/platform-common/src/main/java/band/kessoku/lib/platform/api/ModLoader.java @@ -2,6 +2,8 @@ import band.kessoku.lib.platform.impl.KessokuPlatformServices; +import java.nio.file.Path; + public interface ModLoader { static ModLoader getInstance() { return KessokuPlatformServices.getModLoader(); @@ -11,4 +13,8 @@ static ModLoader getInstance() { boolean isFabric(); boolean isNeoForge(); Env getEnv(); + Path getGameFolder(); + Path getConfigFolder(); + Path getModsFolder(); + boolean isModLoaded(String id); } diff --git a/platform-fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java b/platform-fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java index 88d08389..bbae6c8f 100644 --- a/platform-fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java +++ b/platform-fabric/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java @@ -7,6 +7,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.loader.api.FabricLoader; +import java.nio.file.Path; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -33,4 +34,24 @@ public boolean isNeoForge() { public Env getEnv() { return FabricLoader.getInstance().getEnvironmentType() == EnvType.CLIENT ? Env.CLIENT : Env.SERVER; } + + @Override + public Path getGameFolder() { + return FabricLoader.getInstance().getGameDir(); + } + + @Override + public Path getConfigFolder() { + return FabricLoader.getInstance().getConfigDir(); + } + + @Override + public Path getModsFolder() { + return getGameFolder().resolve("mods"); + } + + @Override + public boolean isModLoaded(String id) { + return FabricLoader.getInstance().isModLoaded(id); + } } diff --git a/platform-neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java b/platform-neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java index 794de59f..a3fbacdb 100644 --- a/platform-neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java +++ b/platform-neo/src/main/java/band/kessoku/lib/platform/impl/ModLoaderImpl.java @@ -4,8 +4,12 @@ import band.kessoku.lib.platform.api.ModData; import band.kessoku.lib.platform.api.ModLoader; import com.google.auto.service.AutoService; +import net.minecraft.MinecraftVersion; +import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLLoader; +import net.neoforged.fml.loading.FMLPaths; +import java.nio.file.Path; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -32,4 +36,24 @@ public boolean isNeoForge() { public Env getEnv() { return FMLLoader.getDist().isClient() ? Env.CLIENT : Env.SERVER; } + + @Override + public Path getGameFolder() { + return FMLPaths.GAMEDIR.get(); + } + + @Override + public Path getConfigFolder() { + return FMLPaths.CONFIGDIR.get(); + } + + @Override + public Path getModsFolder() { + return FMLPaths.MODSDIR.get(); + } + + @Override + public boolean isModLoaded(String id) { + return ModList.get().isLoaded(id); + } }