diff options
Diffstat (limited to 'versions/src/main/java/cc/polyfrost/oneconfig')
-rw-r--r-- | versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java | 73 | ||||
-rw-r--r-- | versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java | 16 |
2 files changed, 72 insertions, 17 deletions
diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java index 68065fd..4c10997 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/LoaderPlatformImpl.java @@ -28,26 +28,33 @@ package cc.polyfrost.oneconfig.platform.impl; import cc.polyfrost.oneconfig.platform.LoaderPlatform; //#if MC>=11600 - //#if FORGE==1 - //$$ import net.minecraftforge.fml.ModList; - //#else - //$$ import net.fabricmc.loader.api.FabricLoader; - //#endif +//#if FORGE==1 +//$$ import net.minecraftforge.fml.ModList; +//#else +//$$ import net.fabricmc.loader.api.FabricLoader; +//$$ import net.fabricmc.loader.api.ModContainer; +//#endif //#endif //#if FORGE==1 import net.minecraftforge.fml.common.Loader; import net.minecraftforge.fml.common.ModContainer; //#endif +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Collections; +import java.util.List; +import java.util.stream.Collectors; public class LoaderPlatformImpl implements LoaderPlatform { @Override public boolean isModLoaded(String id) { //#if MC>=11600 - //#if FORGE==1 - //$$ return ModList.get().isLoaded(id); - //#else - //$$ return FabricLoader.getInstance().isModLoaded(id); - //#endif + //#if FORGE==1 + //$$ return ModList.get().isLoaded(id); + //#else + //$$ return FabricLoader.getInstance().isModLoaded(id); + //#endif //#else return Loader.isModLoaded(id); //#endif @@ -63,17 +70,49 @@ public class LoaderPlatformImpl implements LoaderPlatform { } @Override + public @NotNull List<ActiveMod> getLoadedMods() { + try { + return + //#if FORGE==1 + //#if MC<=11202 + Loader.instance().getActiveModList().stream().map + //#else + //$$ ModList.get().applyForEachModContainer + //#endif + //#else + //$$ FabricLoader.getInstance().getAllMods().stream().map + //#endif + (this::toActiveMod).collect(Collectors.toList()); + } catch (Exception e) { + return Collections.emptyList(); + } + } + + @Override public ActiveMod getActiveModContainer() { //#if FORGE==1 - ModContainer container = Loader.instance().activeModContainer(); - if (container == null) return null; - //#if MC==11202 - return new ActiveMod(container.getName(), container.getModId(), container.getVersion()); - //#else - //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier()); - //#endif + return toActiveMod(Loader.instance().activeModContainer()); //#else //$$ return null; //#endif } + + @Override + public ActiveMod toActiveMod(@Nullable Object in) { + try { + ModContainer container = (ModContainer) in; + if (container == null) return null; + //#if FORGE==1 + //#if MC==11202 + return new ActiveMod(container.getName(), container.getModId(), container.getVersion(), container.getSource()); + //#else + //$$ return new ActiveMod(container.getModInfo().getDisplayName(), container.getModId(), container.getModInfo().getVersion().getQualifier(), ModList.get().getModFileById(container.getModId()).getFile().getFilePath().toFile()); + //#endif + //#else + //$$ return new ActiveMod(container.getMetadata().getName(), container.getMetadata().getId(), container.getMetadata().getVersion().getFriendlyString(), container.getRootPaths().get(0).toFile()); + //#endif + } catch (Exception e) { + return null; + } + } } diff --git a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java index 85bf795..e6e96f0 100644 --- a/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java +++ b/versions/src/main/java/cc/polyfrost/oneconfig/platform/impl/PlatformImpl.java @@ -65,6 +65,22 @@ public class PlatformImpl implements Platform { } @Override + public boolean isDevelopmentEnvironment() { + //#if FORGE==1 && MC<=11202 + try { + Class.forName("net.minecraft.block.BlockDirt"); + return true; + } catch (Exception ignored) { + return false; + } + //#elseif FABRIC==1 + //$$ return net.fabricmc.loader.api.FabricLoader.getInstance().isDevelopmentEnvironment(); + //#else + //$$ return !net.minecraftforge.fml.loading.FMLLoader.isProduction(); + //#endif + } + + @Override public Loader getLoader() { //#if FORGE==1 return Loader.FORGE; |