try to fix alternative intermediary usage
All checks were successful
Publish to snapshot maven / build (push) Successful in 21s

This commit is contained in:
moehreag 2024-08-20 15:44:47 +02:00
parent d869085dd8
commit 0a602a5012
2 changed files with 32 additions and 23 deletions

View file

@ -7,7 +7,7 @@ plugins {
} }
group = "dev.frogmc" group = "dev.frogmc"
version = "0.0.1-alpha.21" version = "0.0.1-alpha.22"
repositories { repositories {
maven { maven {

View file

@ -131,38 +131,47 @@ public class MinecraftGamePlugin implements GamePlugin {
if (!Files.exists(remappedGamePath)) { if (!Files.exists(remappedGamePath)) {
MappingBundle mappings; MappingBundle mappings;
String mappingPath = System.getProperty(SystemProperties.INTERMEDIARY_MAPPINGS); String mappingPath = System.getProperty(SystemProperties.INTERMEDIARY_MAPPINGS);
if (mappingPath != null) { try {
URL resource = this.getClass().getResource(""); if (mappingPath != null) {
String data; mappings = readIntemediaryMappings(mappingPath);
if (resource != null) {
data = new BufferedReader(new InputStreamReader(resource.openStream())).lines().collect(Collectors.joining("\n"));
} else { } else {
data = Files.readString(Paths.get(mappingPath)); mappings = MojmapProvider.get(version, remappedGamePath.resolveSibling("client-" + version + ".txt")).orElse(null);
} }
try { if (mappings == null) {
mappings = TinyV2Parser.parse(data); mappings = readIntemediaryMappings("mappings/mappings.tiny");
} catch (IllegalStateException e) {
throw new IllegalStateException("Failed to read intermediary mappings: " + data, e);
} }
} else { if (mappings != null) {
mappings = MojmapProvider.get(version, remappedGamePath.resolveSibling("client-" + version + ".txt")).orElseGet(() -> { Thyroxine.remap(mappings.flattenData(), gamePath, remappedGamePath, true, false);
LOGGER.warn("Failed to retrieve/parse mojmap for {}! If it isn't available you will need to specify intermediary mappings yourself!", version); return;
return null; }
}); } catch (Exception e) {
} LOGGER.error("Failed to remap game: ", e);
if (mappings != null) {
Thyroxine.remap(mappings.flattenData(), gamePath, remappedGamePath, true, false);
} else {
runtimePath = gamePath;
LOGGER.warn("No intermediary mappings found! The game will be launched obfuscated. Mods are likely to error!");
} }
runtimePath = gamePath;
LOGGER.error("No intermediary mappings found! The game will be launched obfuscated. Mods are likely to error! " +
"You may need to specify the path of your mappings manually. " +
"Use -D"+SystemProperties.INTERMEDIARY_MAPPINGS+" to specify a file!");
} }
} }
FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL()); FrogLoaderImpl.getInstance().getClassloader().addURL(runtimePath.toUri().toURL());
} }
private MappingBundle readIntemediaryMappings(String path) throws IOException {
URL resource = this.getClass().getResource(path);
String data;
if (resource != null) {
data = new BufferedReader(new InputStreamReader(resource.openStream())).lines().collect(Collectors.joining("\n"));
} else {
data = Files.readString(Paths.get(path));
}
try {
return TinyV2Parser.parse(data);
} catch (IllegalStateException e) {
throw new IllegalStateException("Failed to read intermediary mappings: " + data, e);
}
}
@Override @Override
public @NotNull String queryVersion() { public @NotNull String queryVersion() {
return version; return version;