Created
July 31, 2024 22:40
-
-
Save Konicai/b3dc6c044daae0a5ea9fc0880487dd29 to your computer and use it in GitHub Desktop.
Minecraft Decompilation & Deobfuscation with Vanilla Gradle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.spongepowered.gradle.vanilla.repository.MinecraftPlatform | |
| import java.nio.file.Files | |
| import java.nio.file.Path | |
| import java.util.zip.ZipFile | |
| plugins { | |
| java | |
| id("org.spongepowered.gradle.vanilla") version "0.2.1-SNAPSHOT" | |
| } | |
| group = "me.konicai" | |
| version = "1.0-SNAPSHOT" | |
| val minecraftVersion = "1.21" | |
| val minecraftPlatform = MinecraftPlatform.JOINED | |
| repositories { | |
| mavenCentral() | |
| } | |
| minecraft { | |
| version(minecraftVersion) // or: latestRelease() or latestSnapshot() | |
| platform(minecraftPlatform) | |
| } | |
| tasks { | |
| register<UnpackJarTask>("unpack") { | |
| val platform = minecraftPlatform.name | |
| val jarName = "$platform-$minecraftVersion-sources.jar" | |
| val jar = File(System.getProperty("user.home")).resolve(".gradle/caches/VanillaGradle/v2/jars/net/minecraft/$platform/$minecraftVersion/$jarName") | |
| sourceJar.set(jar) | |
| destination.set(project.projectDir.resolve("src/main/java")) | |
| ignoredEntries.set(setOf("data", "assets", "version.json", "pack.png", "flightrecorder-config.jfc")) | |
| } | |
| getByName("unpack").dependsOn(decompile) | |
| } | |
| abstract class UnpackJarTask : DefaultTask() { | |
| @get:Optional | |
| @get:Input | |
| abstract val ignoredEntries: Property<Collection<String>> | |
| @get:InputFile | |
| abstract val sourceJar: Property<File> | |
| @get:OutputDirectory | |
| abstract val destination: Property<File> | |
| @TaskAction | |
| fun unpack() { | |
| val jar: Path = sourceJar.get().toPath() | |
| val dest: Path = destination.get().toPath() | |
| project.delete(dest) | |
| Files.createDirectories(dest) | |
| extract(jar, dest, ignoredEntries.getOrElse(emptySet())) | |
| println("Successfully extracted") | |
| } | |
| private fun extract(jar: Path, dest: Path, ignoredEntries: Collection<String>) { | |
| ZipFile(jar.toFile()).use { archive -> | |
| archive.stream().forEachOrdered { entry -> | |
| val name = entry.name | |
| for (ignored in ignoredEntries) { | |
| if (name.startsWith(ignored)) { | |
| return@forEachOrdered | |
| } | |
| } | |
| println(name) | |
| val entryDest = dest.resolve(name) | |
| if (!Files.exists(entryDest.parent)) { | |
| Files.createDirectories(entryDest.parent) | |
| } | |
| Files.copy(archive.getInputStream(entry), entryDest) | |
| } | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| rootProject.name = "vg-client" | |
| pluginManagement { | |
| repositories { | |
| maven("https://repo.spongepowered.org/repository/maven-public/") | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment