Fix formatting again
All checks were successful
Publish to snapshot maven / build (push) Successful in 24s

This commit is contained in:
TheKodeToad 2024-05-13 14:27:56 +01:00
parent b1a30431f3
commit af4af1ba29
No known key found for this signature in database
GPG key ID: 5E39D70B4C93C38E

View file

@ -18,72 +18,72 @@ import org.objectweb.asm.commons.ClassRemapper;
public class MojMapPatcher {
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException, InterruptedException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
public static void run(String minecraftVersion, Path inputJar, Path outputJar) throws IOException, InterruptedException {
MappingData data = ProguardParser.read(MojmapProvider.get(minecraftVersion).orElseThrow()).reverse();
Mapper mapper = new Mapper(data);
Mapper mapper = new Mapper(data);
Files.deleteIfExists(outputJar);
Files.deleteIfExists(outputJar);
System.out.println("Remapping...");
System.out.println("Remapping...");
long startTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis();
try (ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
List<Callable<Void>> tasks = new ArrayList<>();
try (ExecutorService exec = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
FileSystem inFs = FileSystems.newFileSystem(inputJar);
FileSystem outFs = FileSystems.newFileSystem(outputJar, Map.of("create", "true"))) {
List<Callable<Void>> tasks = new ArrayList<>();
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
tasks.add(() -> {
try {
if (path.getFileName().toString().endsWith(".class")) {
String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf("."));
Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className) + ".class");
Path newClass = result.toAbsolutePath();
byte[] bytes = Files.readAllBytes(path);
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0);
reader.accept(new ClassRemapper(writer, mapper), 0);
Files.walkFileTree(inFs.getPath("/"), new SimpleFileVisitor<>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes basicFileAttributes) throws IOException {
tasks.add(() -> {
try {
if (path.getFileName().toString().endsWith(".class")) {
String className = path.getFileName().toString().substring(0, path.getFileName().toString().lastIndexOf("."));
Path result = outFs.getPath(path.toString()).resolveSibling(data.classes().getOrDefault(className, className) + ".class");
Path newClass = result.toAbsolutePath();
byte[] bytes = Files.readAllBytes(path);
ClassReader reader = new ClassReader(bytes);
ClassWriter writer = new ClassWriter(0);
reader.accept(new ClassRemapper(writer, mapper), 0);
Files.createDirectories(result.getParent());
Files.write(newClass, writer.toByteArray());
} else {
Path result = outFs.getPath(path.toString()).toAbsolutePath();
Files.createDirectories(result.getParent());
Files.copy(path, result);
}
} catch (IOException ex) {
throw new Error(ex);
}
Files.createDirectories(result.getParent());
Files.write(newClass, writer.toByteArray());
} else {
Path result = outFs.getPath(path.toString()).toAbsolutePath();
Files.createDirectories(result.getParent());
Files.copy(path, result);
}
} catch (IOException ex) {
throw new Error(ex);
}
return null;
});
return null;
});
return FileVisitResult.CONTINUE;
}
});
return FileVisitResult.CONTINUE;
}
});
exec.invokeAll(tasks);
exec.invokeAll(tasks);
System.out.printf("Finished remapping (%.2fs)\n", (System.currentTimeMillis() - startTime) / 1000F);
}
}
System.out.printf("Finished remapping (%.2fs)\n", (System.currentTimeMillis() - startTime) / 1000F);
}
}
public static void main(String[] args) throws IOException, InterruptedException {
// temporary
if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
return;
}
public static void main(String[] args) throws IOException, InterruptedException {
// temporary
if (args.length != 3) {
System.err.println("Usage: [minecraft-version] [minecraft.jar] [out.jar]");
return;
}
String minecraftVersion = args[0];
String minecraftJar = args[1];
String outJar = args[2];
String minecraftVersion = args[0];
String minecraftJar = args[1];
String outJar = args[2];
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
run(minecraftVersion, Paths.get(minecraftJar), Paths.get(outJar));
}
}
}