1.17
This commit is contained in:
parent
a2693f08ad
commit
44ce5f772b
|
@ -15,5 +15,5 @@ dependencies {
|
|||
|
||||
download("https://gitlab.com/jfmods/LibJF/-/jobs/artifacts/master/raw/latest-dev.jar?job=build_test", "libjf")
|
||||
|
||||
modImplementation "com.terraformersmc:modmenu:1.16.9"
|
||||
modImplementation "com.terraformersmc:modmenu:2.0.0-beta.5"
|
||||
}
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
org.gradle.jvmargs=-Xmx1G
|
||||
# Fabric Properties
|
||||
# check these on https://modmuss50.me/fabric.html
|
||||
minecraft_version=1.16.5
|
||||
yarn_mappings=1.16.5+build.9
|
||||
minecraft_version=1.17-pre1
|
||||
yarn_mappings=1.17-pre1+build.6
|
||||
loader_version=0.11.3
|
||||
# Mod Properties
|
||||
mod_version=2.2
|
||||
|
@ -12,7 +12,7 @@ archives_base_name=modsmod
|
|||
|
||||
modrinth_id=4GhX11Ed
|
||||
modrinth_required_dependencies=7a9qcRLy
|
||||
modrinth_optional_dependencies=Gz5wa6j2
|
||||
modrinth_optional_dependencies=EDbIonje
|
||||
curseforge_id=405095
|
||||
curseforge_required_dependencies=libjf
|
||||
curseforge_optional_dependencies=modmenu
|
||||
|
|
|
@ -1,14 +1,18 @@
|
|||
package io.gitlab.jfronny.modsmod;
|
||||
|
||||
import net.fabricmc.loader.util.FileSystemUtil;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public class ModMeta {
|
||||
public final FileSystem fs;
|
||||
public final URL url;
|
||||
|
||||
public ModMeta(FileSystem fs, URL url) {
|
||||
this.fs = fs;
|
||||
this.url = url;
|
||||
public ModMeta(Path f) throws IOException {
|
||||
this.fs = FileSystemUtil.getJarFileSystem(f, false).get();
|
||||
this.url = f.toUri().toURL();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@ import net.fabricmc.loader.util.FileSystemUtil;
|
|||
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
|
@ -22,12 +21,11 @@ import java.util.Collections;
|
|||
import java.util.HashSet;
|
||||
|
||||
public class ModsMod {
|
||||
static HashSet<ModMeta> m;
|
||||
static FabricLoader loader;
|
||||
static final HashSet<ModMeta> m = new HashSet<>();
|
||||
static final FabricLoader loader = FabricLoader.INSTANCE;
|
||||
public static final String MOD_ID = "modsmod";
|
||||
private static final String CACHE_NAME = MOD_ID + "cache";
|
||||
public static void prepare() throws IOException {
|
||||
loader = FabricLoader.INSTANCE;
|
||||
//Load config
|
||||
Libjf.registerConfig(MOD_ID, Cfg.class);
|
||||
Path configDir = loader.getConfigDir();
|
||||
|
@ -41,7 +39,7 @@ public class ModsMod {
|
|||
}
|
||||
//remove modsmodcache if the cache is outdated
|
||||
try {
|
||||
Path cfgCache = configDir.resolve(CACHE_NAME + "_basecfg");
|
||||
Path cfgCache = path.resolve("_basecfg");
|
||||
if (Files.exists(cfgCache)) {
|
||||
if (Files.isRegularFile(cfgCache)) {
|
||||
if (!IOUtil.contentEquals(modsmodCfgFile, cfgCache)) {
|
||||
|
@ -57,53 +55,59 @@ public class ModsMod {
|
|||
System.err.println("Failed to validate modsmod config cache, caching will not be available");
|
||||
e.printStackTrace();
|
||||
}
|
||||
m = new HashSet<>();
|
||||
m.clear();
|
||||
//Generate mods
|
||||
for (int i = 0; i < Cfg.modsCount; i++) {
|
||||
Path f = path.resolve("f" + (i + 1) + ".jar");
|
||||
boolean exists = Files.exists(f);
|
||||
FileSystem fs = FileSystemUtil.getJarFileSystem(f, !exists).get();
|
||||
m.add(new ModMeta(fs, f.toUri().toURL()));
|
||||
//Do not load if cached
|
||||
if (exists) {
|
||||
if (Cfg.cache) continue;
|
||||
else Files.delete(f);
|
||||
if (Cfg.cache) {
|
||||
m.add(new ModMeta(f));
|
||||
continue;
|
||||
} else Files.delete(f);
|
||||
}
|
||||
//META-INF/MANIFEST.MF (java jar file spec)
|
||||
Path inf = fs.getPath("META-INF");
|
||||
Files.createDirectory(inf);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Manifest-Version: 1.0\n");
|
||||
Files.write(inf.resolve("MANIFEST.MF"), sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
sb.delete(0, sb.length());
|
||||
//fabric.mod.json (fabric mod metadata)
|
||||
sb.append("{");
|
||||
sb.append("\"schemaVersion\": 1,");
|
||||
sb.append("\"id\": \"modmod_").append(i + 1).append("\",");
|
||||
sb.append("\"version\": \"1.0\",");
|
||||
sb.append("\"name\": \"ModsMod ").append(i + 1).append("\",");
|
||||
sb.append("\"entrypoints\": {},");
|
||||
sb.append("\"custom\": {");
|
||||
if (Cfg.parent) {
|
||||
sb.append("\"modmenu:parent\": \"modsmod\"");
|
||||
try (FileSystem fs = FileSystemUtil.getJarFileSystem(f, true).get()) {
|
||||
//META-INF/MANIFEST.MF (java jar file spec)
|
||||
Path inf = fs.getPath("META-INF");
|
||||
Files.createDirectory(inf);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("Manifest-Version: 1.0\n");
|
||||
Files.writeString(inf.resolve("MANIFEST.MF"), sb.toString());
|
||||
sb.delete(0, sb.length());
|
||||
//fabric.mod.json (fabric mod metadata)
|
||||
sb.append("{");
|
||||
sb.append("\"schemaVersion\": 1,");
|
||||
sb.append("\"id\": \"modmod_").append(i + 1).append("\",");
|
||||
sb.append("\"version\": \"1.0\",");
|
||||
sb.append("\"name\": \"ModsMod ").append(i + 1).append("\",");
|
||||
sb.append("\"entrypoints\": {},");
|
||||
sb.append("\"custom\": {");
|
||||
if (Cfg.parent) {
|
||||
sb.append("\"modmenu:parent\": \"modsmod\"");
|
||||
}
|
||||
sb.append("}");
|
||||
sb.append("}");
|
||||
Files.writeString(fs.getPath("fabric.mod.json"), sb.toString());
|
||||
sb.delete(0, sb.length());
|
||||
} catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
sb.append("}");
|
||||
sb.append("}");
|
||||
Files.write(fs.getPath("fabric.mod.json"), sb.toString().getBytes(StandardCharsets.UTF_8));
|
||||
sb.delete(0, sb.length());
|
||||
|
||||
System.gc();
|
||||
|
||||
m.add(new ModMeta(f));
|
||||
}
|
||||
FabricLoaderInterface.synchronize(loader);
|
||||
}
|
||||
|
||||
public static void init() {
|
||||
for (ModMeta f : m) {
|
||||
loadMod(loader, f);
|
||||
loadMod(f);
|
||||
}
|
||||
}
|
||||
|
||||
private static void loadMod(FabricLoader loader, ModMeta meta) {
|
||||
private static void loadMod(ModMeta meta) {
|
||||
ModCandidate candidate = parseMod(meta.fs.getPath("fabric.mod.json"), meta.url);
|
||||
|
||||
if (loader.isDevelopmentEnvironment()) {
|
||||
|
|
Loading…
Reference in New Issue