diff --git a/Common/src/main/java/dev/upcraft/sparkweave/client/render/RenderDocHelper.java b/Common/src/main/java/dev/upcraft/sparkweave/client/render/RenderDocHelper.java index 4cb5d77..fecc08d 100644 --- a/Common/src/main/java/dev/upcraft/sparkweave/client/render/RenderDocHelper.java +++ b/Common/src/main/java/dev/upcraft/sparkweave/client/render/RenderDocHelper.java @@ -1,6 +1,8 @@ package dev.upcraft.sparkweave.client.render; +import dev.upcraft.sparkweave.SparkweaveMod; import dev.upcraft.sparkweave.api.SparkweaveApi; +import dev.upcraft.sparkweave.api.annotation.Mod; import dev.upcraft.sparkweave.logging.SparkweaveLogging; import org.apache.logging.log4j.Logger; @@ -8,6 +10,7 @@ import java.nio.file.Files; import java.nio.file.Path; +@Mod.Context(SparkweaveMod.MODID) public class RenderDocHelper { private static final Logger LOGGER = SparkweaveLogging.getLogger(); diff --git a/Common/src/main/java/dev/upcraft/sparkweave/platform/SimpleModContainer.java b/Common/src/main/java/dev/upcraft/sparkweave/platform/SimpleModContainer.java new file mode 100644 index 0000000..fc9a57d --- /dev/null +++ b/Common/src/main/java/dev/upcraft/sparkweave/platform/SimpleModContainer.java @@ -0,0 +1,37 @@ +package dev.upcraft.sparkweave.platform; + +import dev.upcraft.sparkweave.api.platform.ModContainer; +import dev.upcraft.sparkweave.api.platform.ModMetadata; + +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.function.Function; + +public class SimpleModContainer implements ModContainer { + + private final ModMetadata metadata; + private final List rootPaths; + private final Function> pathFinder; + + public SimpleModContainer(ModMetadata metadata, List rootPaths, Function> pathFinder) { + this.metadata = metadata; + this.rootPaths = rootPaths; + this.pathFinder = pathFinder; + } + + @Override + public ModMetadata metadata() { + return metadata; + } + + @Override + public List rootPaths() { + return rootPaths; + } + + @Override + public Optional findPath(String path) { + return pathFinder.apply(path); + } +} diff --git a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoForgeModMetadata.java b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoForgeModMetadata.java index 761609f..72f691f 100644 --- a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoForgeModMetadata.java +++ b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoForgeModMetadata.java @@ -1,7 +1,6 @@ package dev.upcraft.sparkweave.neoforge.impl.mod; import dev.upcraft.sparkweave.api.platform.ModMetadata; -import net.neoforged.fml.ModContainer; import net.neoforged.fml.loading.moddiscovery.ModFileInfo; import net.neoforged.neoforgespi.language.IModInfo; import org.jetbrains.annotations.Nullable; @@ -13,8 +12,8 @@ public class NeoForgeModMetadata implements ModMetadata { private final IModInfo delegate; - public NeoForgeModMetadata(ModContainer modContainer) { - delegate = modContainer.getModInfo(); + public NeoForgeModMetadata(IModInfo delegate) { + this.delegate = delegate; } public IModInfo modInfo() { diff --git a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoforgeModContainer.java b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoforgeModContainer.java index 8182a6d..1260d5a 100644 --- a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoforgeModContainer.java +++ b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/impl/mod/NeoforgeModContainer.java @@ -10,7 +10,7 @@ public record NeoforgeModContainer(NeoForgeModMetadata metadata) implements ModContainer { public static NeoforgeModContainer of(net.neoforged.fml.ModContainer delegate) { - return new NeoforgeModContainer(new NeoForgeModMetadata(delegate)); + return new NeoforgeModContainer(new NeoForgeModMetadata(delegate.getModInfo())); } @Override diff --git a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/service/NeoPlatformService.java b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/service/NeoPlatformService.java index f40854d..2c5ce5f 100644 --- a/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/service/NeoPlatformService.java +++ b/NeoForge/src/main/java/dev/upcraft/sparkweave/neoforge/service/NeoPlatformService.java @@ -5,18 +5,23 @@ import dev.upcraft.sparkweave.api.platform.ModContainer; import dev.upcraft.sparkweave.api.platform.RuntimeEnvironmentType; import dev.upcraft.sparkweave.api.platform.services.PlatformService; +import dev.upcraft.sparkweave.neoforge.impl.mod.NeoForgeModMetadata; import dev.upcraft.sparkweave.neoforge.impl.mod.NeoforgeModContainer; import dev.upcraft.sparkweave.platform.BasePlatformService; +import dev.upcraft.sparkweave.platform.SimpleModContainer; import net.minecraft.SharedConstants; import net.neoforged.fml.ModList; import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.fml.loading.FMLPaths; +import net.neoforged.fml.loading.LoadingModList; import net.neoforged.neoforge.internal.versions.neoforge.NeoForgeVersion; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.util.JavaVersion; import oshi.SystemInfo; import java.nio.file.Path; import java.util.List; +import java.util.NoSuchElementException; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -86,7 +91,18 @@ public Path getConfigDir() { @Override public Optional getModContainer(String modid) { - return ModList.get().getModContainerById(modid).map(NeoforgeModContainer::of); + var modList = ModList.get(); + if(modList == null) { // ModList not loaded yet + @Nullable var modFile = LoadingModList.get().getModFileById(modid); + if(modFile == null) { + return Optional.empty(); + } + + var meta = new NeoForgeModMetadata(modFile.getMods().stream().filter(it -> modid.equals(it.getModId())).findFirst().orElseThrow(() -> new NoSuchElementException("LoadingModList did not contain mod with ID '%s'!".formatted(modid)))); + return Optional.of(new SimpleModContainer(meta, List.of(modFile.getFile().getSecureJar().getRootPath()), path -> Optional.ofNullable(modFile.getFile().getSecureJar().getPath(path)))); + } + + return modList.getModContainerById(modid).map(NeoforgeModContainer::of); } @Override