2022-09-18 15:15:30 +02:00
|
|
|
package io.gitlab.jfronny.inceptum.launcher.system.export;
|
|
|
|
|
|
|
|
import io.gitlab.jfronny.commons.io.JFiles;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.InstanceMeta;
|
2022-10-19 21:26:06 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.rt.Instance;
|
2022-09-18 15:15:30 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.multimc.MMCPackMeta;
|
2022-10-19 21:26:06 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.model.inceptum.rt.Mod;
|
2022-09-18 15:15:30 +02:00
|
|
|
import io.gitlab.jfronny.inceptum.launcher.system.source.ModSource;
|
|
|
|
import io.gitlab.jfronny.inceptum.launcher.util.ModPath;
|
|
|
|
|
|
|
|
import java.io.FileNotFoundException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Files;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.time.Instant;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class MultiMCExporter extends Exporter<MMCPackMeta> {
|
|
|
|
public MultiMCExporter() {
|
|
|
|
super("MultiMC", "zip", ".minecraft");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-10-19 21:26:06 +02:00
|
|
|
protected MMCPackMeta generateManifests(Path root, Instance instance, String version) throws IOException {
|
2022-09-18 15:15:30 +02:00
|
|
|
{
|
|
|
|
Files.writeString(root.resolve("instance.cfg"), String.format("""
|
|
|
|
ForgeVersion=
|
|
|
|
InstanceType=OneSix
|
|
|
|
IntendedVersion=
|
|
|
|
JoinServerOnLaunch=false
|
|
|
|
LWJGLVersion=
|
|
|
|
LiteloaderVersion=
|
|
|
|
LogPrePostOutput=true
|
|
|
|
MCLaunchMethod=LauncherPart
|
|
|
|
OverrideCommands=false
|
|
|
|
OverrideConsole=false
|
|
|
|
OverrideGameTime=false
|
|
|
|
OverrideJavaArgs=false
|
|
|
|
OverrideJavaLocation=false
|
|
|
|
OverrideMCLaunchMethod=false
|
|
|
|
OverrideMemory=false
|
|
|
|
OverrideNativeWorkarounds=false
|
|
|
|
OverrideWindow=false
|
|
|
|
iconKey=default
|
|
|
|
lastLaunchTime=%s
|
|
|
|
lastTimePlayed=0
|
|
|
|
name=%s
|
|
|
|
notes=
|
|
|
|
totalTimePlayed=0
|
2022-10-19 21:26:06 +02:00
|
|
|
""", Instant.now().toEpochMilli(), instance.getName()));
|
2022-09-18 15:15:30 +02:00
|
|
|
}
|
|
|
|
{
|
|
|
|
MMCPackMeta manifest = new MMCPackMeta();
|
|
|
|
manifest.formatVersion = 1;
|
|
|
|
manifest.components = new ArrayList<>();
|
|
|
|
MMCPackMeta.Component lwjgl = new MMCPackMeta.Component();
|
|
|
|
lwjgl.dependencyOnly = true;
|
|
|
|
lwjgl.uid = "org.lwjgl3";
|
|
|
|
lwjgl.version = "3.2.2"; //TODO get automatically
|
|
|
|
manifest.components.add(lwjgl);
|
|
|
|
MMCPackMeta.Component minecraft = new MMCPackMeta.Component();
|
|
|
|
minecraft.important = true;
|
|
|
|
minecraft.uid = "net.minecraft";
|
2022-10-19 21:26:06 +02:00
|
|
|
minecraft.version = instance.meta().getMinecraftVersion();
|
2022-09-18 15:15:30 +02:00
|
|
|
manifest.components.add(minecraft);
|
|
|
|
if (instance.isFabric()) {
|
|
|
|
MMCPackMeta.Component intermediary = new MMCPackMeta.Component();
|
|
|
|
intermediary.dependencyOnly = true;
|
|
|
|
intermediary.uid = "net.fabricmc.intermediary";
|
2022-10-19 21:26:06 +02:00
|
|
|
intermediary.version = instance.meta().getMinecraftVersion();
|
2022-09-18 15:15:30 +02:00
|
|
|
manifest.components.add(intermediary);
|
|
|
|
MMCPackMeta.Component fabric = new MMCPackMeta.Component();
|
|
|
|
fabric.uid = "net.fabricmc.fabric-loader";
|
2022-10-19 21:26:06 +02:00
|
|
|
fabric.version = instance.meta().getLoaderVersion();
|
2022-09-18 15:15:30 +02:00
|
|
|
manifest.components.add(fabric);
|
|
|
|
}
|
|
|
|
JFiles.writeObject(root.resolve("mmc-pack.json"), manifest);
|
|
|
|
return manifest;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2022-10-19 21:26:06 +02:00
|
|
|
protected void addMods(Path root, Instance instance, Iterable<Mod> mods, MMCPackMeta mmcPackMeta, Path modsOverrides) throws IOException {
|
|
|
|
modsLoop: for (Mod mod : mods) {
|
2022-09-18 15:15:30 +02:00
|
|
|
if (ModPath.isImod(mod.path())) {
|
|
|
|
Set<ModSource> sources = mod.mod().orElseThrow().sources.keySet();
|
|
|
|
for (ModSource source : sources) {
|
|
|
|
Files.createDirectories(modsOverrides);
|
|
|
|
Files.copy(source.getJarPath(), modsOverrides.resolve(mod.path().getFileName().toString()));
|
|
|
|
continue modsLoop;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Files.createDirectories(modsOverrides);
|
|
|
|
Files.copy(mod.path(), modsOverrides.resolve(mod.path().getFileName().toString()));
|
|
|
|
continue modsLoop;
|
|
|
|
}
|
|
|
|
throw new FileNotFoundException("Could not find mod file for " + mod.path());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|