59 lines
2.4 KiB
Java
59 lines
2.4 KiB
Java
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
|
|
|
|
import gsoncompile.extensions.io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest.GC_ModrinthModpackManifest;
|
|
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.Mod;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.source.ModSource;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.source.ModrinthModSource;
|
|
|
|
import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Path;
|
|
import java.util.ArrayList;
|
|
import java.util.Set;
|
|
|
|
public class ModrinthExporter extends Exporter<ModrinthModpackManifest> {
|
|
public ModrinthExporter() {
|
|
super("Modrinth", "mrpack", "overrides");
|
|
}
|
|
|
|
@Override
|
|
protected ModrinthModpackManifest generateManifests(Path root, Instance instance, String version) throws IOException {
|
|
ModrinthModpackManifest manifest = new ModrinthModpackManifest(
|
|
1,
|
|
"minecraft",
|
|
version,
|
|
instance.name,
|
|
null, // summary
|
|
new ArrayList<>(),
|
|
new ModrinthModpackManifest.Dependencies(
|
|
instance.gameVersion,
|
|
null,
|
|
instance.isFabric ? instance.loaderVersion : null,
|
|
null
|
|
)
|
|
);
|
|
GC_ModrinthModpackManifest.write(manifest, root.resolve("modrinth.index.json"));
|
|
return manifest;
|
|
}
|
|
|
|
@Override
|
|
protected void addMods(Path root, Instance instance, Iterable<Mod> mods, ModrinthModpackManifest manifest, Path modsOverrides) throws IOException {
|
|
modsLoop: for (Mod mod : mods) {
|
|
if (mod.needsInject) {
|
|
for (ModSource source : mod.metadata.sources.keySet()) {
|
|
if (source instanceof ModrinthModSource cms) {
|
|
manifest.files.add(cms.toManifest());
|
|
continue modsLoop;
|
|
}
|
|
}
|
|
}
|
|
// Not available on modrinth
|
|
Files.createDirectories(modsOverrides);
|
|
Files.copy(mod.jarPath, modsOverrides.resolve(mod.jarPath.fileName.toString()));
|
|
}
|
|
GC_ModrinthModpackManifest.write(manifest, root.resolve("modrinth.index.json"));
|
|
}
|
|
}
|