fix jij loading by extracting nested mods, update thyroxine
All checks were successful
Publish to snapshot maven / build (push) Successful in 34s

This commit is contained in:
moehreag 2024-06-13 19:54:37 +02:00
parent e67ee70cb5
commit 32a95ce9cb
5 changed files with 49 additions and 16 deletions

View file

@ -26,13 +26,13 @@ dependencies {
implementation(libs.thyroxine){ implementation(libs.thyroxine){
isTransitive = false isTransitive = false
} }
compileOnly("org.apache.logging.log4j:log4j-slf4j2-impl:3.0.0-beta2") compileOnly("org.apache.logging.log4j:log4j-slf4j2-impl:2.22.1")
compileOnly("org.apache.logging.log4j:log4j-api:3.0.0-beta2") compileOnly("org.apache.logging.log4j:log4j-api:2.22.1")
compileOnly("org.apache.logging.log4j:log4j-core:3.0.0-beta2") compileOnly("org.apache.logging.log4j:log4j-core:2.22.1")
api(libs.mixin) api(libs.mixin)
api(libs.mixinextras) api(libs.mixinextras)
implementation(libs.nightconfig) api(libs.nightconfig)
api(libs.annotations) api(libs.annotations)
} }

View file

@ -1,6 +1,6 @@
[versions] [versions]
thyroxine = "1.0.0-SNAPSHOT" thyroxine = "0.0.1-alpha.2"
nightconfig = "3.7.2" nightconfig = "3.7.2"
mixin = "0.14.0+mixin.0.8.6" mixin = "0.14.0+mixin.0.8.6"
annotations = "24.1.0" annotations = "24.1.0"

View file

@ -1,6 +1,6 @@
plugins { plugins {
java java
id("dev.frogmc.phytotelma") version "0.0.1-alpha.4" id("dev.frogmc.phytotelma") version "0.0.1-alpha.6"
} }
repositories { repositories {

View file

@ -122,6 +122,4 @@ public final class ModExtensions {
((Collection<String>) l).forEach(c); ((Collection<String>) l).forEach(c);
} }
} }
} }

View file

@ -7,6 +7,7 @@ import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType; import java.lang.invoke.MethodType;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.nio.file.*; import java.nio.file.*;
import java.nio.file.attribute.BasicFileAttributes;
import java.util.*; import java.util.*;
import com.electronwill.nightconfig.core.UnmodifiableConfig; import com.electronwill.nightconfig.core.UnmodifiableConfig;
@ -76,9 +77,11 @@ public class Minecraft implements FrogPlugin {
path.getFileName().toString().endsWith(FrogLoaderImpl.MOD_FILE_EXTENSION)); path.getFileName().toString().endsWith(FrogLoaderImpl.MOD_FILE_EXTENSION));
this.getClass().getClassLoader().resources(ModPropertiesReader.PROPERTIES_FILE_NAME).map(ModPropertiesReader::readFile) this.getClass().getClassLoader().resources(ModPropertiesReader.PROPERTIES_FILE_NAME).map(ModPropertiesReader::readFile)
.map(o -> o.orElse(null)).filter(Objects::nonNull).forEach(modProperties::add); .map(o -> o.orElse(null)).filter(Objects::nonNull).forEach(modProperties::add);
Map<Path, ModProperties> modPaths = new HashMap<>(); Map<Path, ModProperties> modPaths = new HashMap<>();
Path jijCache = getJijCacheDir();
for (Path mod : new HashSet<>(mods)) { for (Path mod : new HashSet<>(mods)) {
findJiJMods(mod, mods, modPaths); findJiJMods(mod, mods, modPaths, jijCache);
} }
try { try {
@ -89,13 +92,14 @@ public class Minecraft implements FrogPlugin {
LoaderGui.execUnfulfilledDep(CrashReportGenerator.writeReport(e, modProperties), e, false); LoaderGui.execUnfulfilledDep(CrashReportGenerator.writeReport(e, modProperties), e, false);
} }
mods.stream().filter(p -> modProperties.contains(modPaths.get(p))).map(Path::toUri).map(uri -> { mods.stream().filter(p -> modProperties.contains(modPaths.get(p))).map(path -> {
try { try {
return uri.toURL(); return path.toUri().toURL();
} catch (MalformedURLException e) { } catch (MalformedURLException e) {
throw new RuntimeException(e); LOGGER.warn("Failed to resolve url for {}", path, e);
return null;
} }
}).forEach(FrogLoaderImpl.getInstance().getClassloader()::addURL); }).filter(Objects::nonNull).forEach(FrogLoaderImpl.getInstance().getClassloader()::addURL);
modProperties.forEach(props -> { modProperties.forEach(props -> {
Object o = props.extensions().get(BuiltinExtensions.MIXIN_CONFIG); Object o = props.extensions().get(BuiltinExtensions.MIXIN_CONFIG);
@ -118,7 +122,7 @@ public class Minecraft implements FrogPlugin {
FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL()); FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL());
} }
protected void findJiJMods(Path mod, Collection<Path> mods, Map<Path, ModProperties> modPaths) throws IOException { protected void findJiJMods(Path mod, Collection<Path> mods, Map<Path, ModProperties> modPaths, Path jijCache) throws IOException {
Optional<ModProperties> opt = ModPropertiesReader.read(mod); Optional<ModProperties> opt = ModPropertiesReader.read(mod);
if (opt.isPresent()) { if (opt.isPresent()) {
ModProperties p = opt.get(); ModProperties p = opt.get();
@ -132,14 +136,45 @@ public class Minecraft implements FrogPlugin {
for (List<UnmodifiableConfig> jars : entries) { for (List<UnmodifiableConfig> jars : entries) {
for (UnmodifiableConfig jar : jars) { for (UnmodifiableConfig jar : jars) {
Path path = fs.getPath(jar.get("path")).toAbsolutePath(); Path path = fs.getPath(jar.get("path")).toAbsolutePath();
mods.add(path); Path extracted = jijCache.resolve((String) jar.get("id"));
findJiJMods(path, mods, modPaths); if (!Files.exists(extracted)){
Files.createDirectories(jijCache);
Files.copy(path, extracted);
}
mods.add(extracted);
findJiJMods(extracted, mods, modPaths, jijCache);
} }
} }
} }
} }
} }
private Path getJijCacheDir(){
Path dir = FrogLoader.getInstance().getGameDir().resolve(".frogmc").resolve("jijcache");
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
Files.walkFileTree(dir, new SimpleFileVisitor<>(){
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return super.visitFile(file, attrs);
}
@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return super.postVisitDirectory(dir, exc);
}
});
} catch (IOException e) {
LOGGER.error("Failed to clear extracted jij mods!", e);
}
}));
return dir;
}
@Override @Override
public Collection<ModProperties> getMods() { public Collection<ModProperties> getMods() {
return modProperties; return modProperties;