Skip to content

Commit

Permalink
Merge pull request #7 from KoblizekXD/runtime/v1.1
Browse files Browse the repository at this point in the history
v1.1
  • Loading branch information
KoblizekXD authored Sep 23, 2023
2 parents ec1986b + eb0f572 commit cf3ce77
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 5 deletions.
7 changes: 5 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
}

group = "lol.koblizek"
version = "1.0"
version = "1.1"

repositories {
mavenCentral()
Expand All @@ -18,11 +18,14 @@ repositories {
name = "neoforgedReleases"
url = uri("https://maven.neoforged.net/releases")
}
maven { url = uri("https://jitpack.io") }
maven { url = uri("https://nexus.velocitypowered.com/repository/maven-public/") }
}

dependencies {
implementation("com.github.MCPHackers:DiffPatch:cde1224")
implementation("net.neoforged:AutoRenamingTool:1.0.7")
implementation("org.vineflower:vineflower:1.9.2")
implementation("org.vineflower:vineflower:1.9.3")
implementation("net.fabricmc:tiny-remapper:0.8.7")
implementation("net.fabricmc:mapping-io:0.4.2")
implementation("commons-io:commons-io:2.13.0")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ class MinecraftDevelopment {
* if project should be decompiled
*/
var decompile: Boolean = false
lateinit var mappings: String

fun useCustomMappings(): Boolean {
return ::mappings.isInitialized
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/lol/koblizek/torch/plugin/ModProject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ class ModProject {
lateinit var minecraft: String
lateinit var mappings: String
lateinit var minecraftDevelopment: MinecraftDevelopment
lateinit var customManifest: String
var side: String = "any"

/**
* Specifies the development of game api,
Expand All @@ -36,5 +38,13 @@ class ModProject {
* @return true if are mappings field inside `minecraft` block used
*/
private fun areMappingsInitialized(): Boolean = ::mappings.isInitialized

fun useSide(): Boolean = side != "any"
fun useCustomManifest(): Boolean = ::customManifest.isInitialized

fun getSideOrDefault(): String {
if (useSide()) return side
else return "mappings/mappings.tiny"
}
fun fieldsInitialized(): Boolean = isMinecraftInitialized() && areMappingsInitialized()
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ class TorchLoaderPlugin : Plugin<Project> {
downloadJsonTask = project.tasks.create("downloadJson", DownloadJsonTask::class.java)
downloadMinecraftTask = project.tasks.create("downloadMinecraft", DownloadMinecraftTask::class.java)
downloadMappingsTask = project.tasks.create("downloadMappings", DownloadMappingsTask::class.java)
project.tasks.create("genPatch", GenPatchTask::class.java)
project.tasks.create("applyPatch", ApplyPatchTask::class.java)

project.tasks.withType(JavaCompile::class.java) {
it.options.encoding = "UTF-8"
Expand Down
28 changes: 28 additions & 0 deletions src/main/kotlin/lol/koblizek/torch/plugin/tasks/ApplyPatchTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package lol.koblizek.torch.plugin.tasks

import codechicken.diffpatch.PatchOperation
import codechicken.diffpatch.util.PatchMode
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction


abstract class ApplyPatchTask : DefaultTask() {
init {
group = "torch"
description = "applies patches from origin/ directory to source"
}

@TaskAction
fun apply() {
val patchDir = project.file("patches/")
val base = project.file("src/main/java/")
val patchOperation = PatchOperation.builder()
.basePath(base.toPath())
.patchesPath(patchDir.toPath())
.outputPath(base.toPath())
.mode(PatchMode.OFFSET)
.build()
val status = patchOperation.doPatch()
println("Patch status: $status")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ abstract class DownloadJsonTask : DefaultTask() {
val version = manifest.findByVersion(ModProject.modProjectInstance.minecraft)
?: throw RuntimeException("Specified Minecraft version(${ModProject.modProjectInstance.minecraft}) doesn't exist")
println("Downloading Minecraft source JSON")
Download(version.url, "minecraft-data.json", true, this)
if (ModProject.modProjectInstance.useCustomManifest())
Download(ModProject.modProjectInstance.customManifest, "minecraft-data.json", true, this)
else Download(version.url, "minecraft-data.json", true, this)
println("Finished source JSON download")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ abstract class DownloadMappingsTask : DefaultTask() {
zipFile.getInputStream(zipFile.getEntry("mappings/mappings.tiny")),
file
)
} else if (ModProject.modProjectInstance.minecraftDevelopment.useCustomMappings()) {
val mappingFile = Download(ModProject.modProjectInstance.minecraftDevelopment.mappings, "mappings-jar.jar").file
val zipFile = ZipFile(mappingFile)
val file = Download.getFile("mappings.tiny", true, this)
FileUtils.copyInputStreamToFile(
zipFile.getInputStream(zipFile.getEntry(ModProject.modProjectInstance.getSideOrDefault())),
file
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package lol.koblizek.torch.plugin.tasks

import com.google.gson.Gson
import com.google.gson.JsonObject
import lol.koblizek.torch.plugin.ModProject
import lol.koblizek.torch.plugin.TorchLoaderPlugin
import lol.koblizek.torch.plugin.util.Download
import org.gradle.api.DefaultTask
Expand All @@ -21,7 +22,7 @@ abstract class DownloadMinecraftTask : DefaultTask() {
val file = File(TorchLoaderPlugin.downloadJsonTask.temporaryDir, "minecraft-data.json")
val json = Gson().fromJson(file.readText(), JsonObject::class.java)
val clientUrl = json.getAsJsonObject("downloads")
.getAsJsonObject("client")
.getAsJsonObject(if (ModProject.modProjectInstance.useSide()) ModProject.modProjectInstance.side else "client")
.getAsJsonPrimitive("url").asString
Download(clientUrl, "minecraft.jar", true, this)
val gameArgs = FileWriter(File(temporaryDir, "args.json"))
Expand Down
30 changes: 30 additions & 0 deletions src/main/kotlin/lol/koblizek/torch/plugin/tasks/GenPatchTask.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package lol.koblizek.torch.plugin.tasks

import codechicken.diffpatch.DiffOperation
import org.gradle.api.DefaultTask
import org.gradle.api.tasks.TaskAction

abstract class GenPatchTask : DefaultTask() {
init {
group = "torch"
description = "generates patch files from origin/ directory"
}

@TaskAction
fun genPatches() {
val patchDir = project.file("patches/")
if (!patchDir.exists()) {
patchDir.mkdirs()
}
val diffOperation = DiffOperation.builder()
.aPath(project.file("origin/").toPath())
.bPath(project.file("src/main/java/").toPath())
.aPrefix(null)
.bPrefix(null)
.filter { it.endsWith(".java") }
.outputPath(patchDir.toPath())
.build()
diffOperation.doDiff()
println("Patch done.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ class DecompileTask : EvaluatedTask() {
}
fernFlower.decompileContext()
moveNonCodeFiles(project)
val file = project.file("origin/")
val from = project.file("src/main/java/")
if (!file.exists()) file.mkdirs()
FileUtils.copyDirectory(from, file)

} else {
logger.quiet("Minecraft resource are not missing, no need to redownload")
}
Expand Down Expand Up @@ -65,7 +70,7 @@ class DecompileTask : EvaluatedTask() {
val main = project.file("src/main/java/")

main.listFiles()?.forEach {
if (!(it.name == "com" || it.name == "net"))
if (!(it.name == "com" || it.name == "net" || it.name.endsWith(".java")))
FileUtils.moveToDirectory(it, resources, true)
}
}
Expand Down

0 comments on commit cf3ce77

Please sign in to comment.