59 lines
2.5 KiB
Java
59 lines
2.5 KiB
Java
package io.gitlab.jfronny.inceptum.launcher.system.exporter;
|
|
|
|
import io.gitlab.jfronny.commons.io.JFiles;
|
|
import io.gitlab.jfronny.inceptum.launcher.system.instance.Instance;
|
|
import io.gitlab.jfronny.inceptum.launcher.model.modrinth.ModrinthModpackManifest;
|
|
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 io.gitlab.jfronny.inceptum.launcher.system.instance.ModPath;
|
|
|
|
import java.io.FileNotFoundException;
|
|
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();
|
|
manifest.formatVersion = 1;
|
|
manifest.game = "minecraft";
|
|
manifest.versionId = version;
|
|
manifest.name = instance.getName();
|
|
manifest.files = new ArrayList<>();
|
|
manifest.dependencies = new ModrinthModpackManifest.Dependencies();
|
|
manifest.dependencies.minecraft = instance.meta().getMinecraftVersion();
|
|
if (instance.isFabric()) {
|
|
manifest.dependencies.fabricLoader = instance.meta().getLoaderVersion();
|
|
}
|
|
JFiles.writeObject(root.resolve("modrinth.index.json"), manifest);
|
|
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()) {
|
|
Set<ModSource> sources = mod.getMetadata().sources.keySet();
|
|
for (ModSource source : sources) {
|
|
if (source instanceof ModrinthModSource cms) {
|
|
manifest.files.add(cms.toManifest());
|
|
continue modsLoop;
|
|
}
|
|
}
|
|
}
|
|
// Not available on modrinth
|
|
Files.createDirectories(modsOverrides);
|
|
Files.copy(mod.getJarPath(), modsOverrides.resolve(mod.getJarPath().getFileName().toString()));
|
|
}
|
|
JFiles.writeObject(root.resolve("modrinth.index.json"), manifest);
|
|
}
|
|
}
|