Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed Nov 22, 2023
1 parent a6d0217 commit 23b03ee
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package xyz.wagyourtail.patchbase.gradle

import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.jvm.tasks.Jar
import xyz.wagyourtail.patchbase.gradle.tasks.ApplySourcePatchTask
import xyz.wagyourtail.patchbase.gradle.tasks.CreateClassPatchTask
Expand All @@ -24,58 +25,6 @@ class PatchCreatorPlugin : Plugin<Project> {
target.logger.lifecycle("[PatchbaseCreator] Plugin Version: $pluginVersion")

target.extensions.create("patchbase", PatchExtension::class.java)

}

}

fun MinecraftConfig.patchBaseCreator() {
if (side == EnvType.COMBINED) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] Merged may make applying patches more difficult, proceed with caution")
}
if (!defaultRemapJar) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] defaultRemapJar is false, this may cause issues with patching")
}
if (mcPatcher !is JarModAgentMinecraftTransformer) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] mcPatcher is not a JarModAgentMinecraftTransformer, this may cause issues with dev runs")
}

project.tasks.register("createSourcePatch".withSourceSet(sourceSet), CreateSourcePatchTask::class.java) {
it.group = "patchbase"
it.sourceDir.set(project.file("src/main/java"))
it.outputDir.set(project.file("patches/main"))
val sourceFile = minecraftFileDev.resolveSibling(minecraftFileDev.nameWithoutExtension + "-sources.jar")
it.sources.set(project.files(sourceFile))
if (!sourceFile.exists()) {
it.dependsOn("genSources")
}
}

project.tasks.register("applySourcePatch".withSourceSet(sourceSet), ApplySourcePatchTask::class.java) {
it.group = "patchbase"
it.patchDir.set(project.file("patches/main"))
it.outputDir.set(project.file("src/main/java"))
val sourceFile = minecraftFileDev.resolveSibling(minecraftFileDev.nameWithoutExtension + "-sources.jar")
it.sources.set(project.files(sourceFile))
if (!sourceFile.exists()) {
it.dependsOn("genSources".withSourceSet(sourceSet))
}
}

project.tasks.register("createClassPatch".withSourceSet(sourceSet), CreateClassPatchTask::class.java) {
it.group = "patchbase"
it.inputFile.set((project.tasks.findByName("remapJar".withSourceSet(sourceSet)) as Jar).outputs.files.singleFile)

when (side) {
EnvType.CLIENT -> it.classpath.set(project.files(minecraftData.minecraftClientFile))
EnvType.SERVER -> it.classpath.set(project.files(minecraftData.minecraftServerFile))
EnvType.COMBINED -> {
it.classpath.set(project.files(mergedOfficialMinecraftFile))
}
else -> throw IllegalStateException("Unknown side: $side")
}

it.archiveClassifier.set("patch")
it.dependsOn("remapJar".withSourceSet(sourceSet))
}
}
64 changes: 61 additions & 3 deletions src/main/kotlin/xyz/wagyourtail/patchbase/gradle/PatchExtension.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,69 @@
package xyz.wagyourtail.patchbase.gradle

import org.gradle.api.Project
import org.gradle.api.tasks.SourceSet
import org.gradle.jvm.tasks.Jar
import xyz.wagyourtail.patchbase.gradle.tasks.ApplySourcePatchTask
import xyz.wagyourtail.patchbase.gradle.tasks.CreateClassPatchTask
import xyz.wagyourtail.patchbase.gradle.tasks.CreateSourcePatchTask
import xyz.wagyourtail.unimined.api.minecraft.EnvType
import xyz.wagyourtail.unimined.api.minecraft.MinecraftConfig
import xyz.wagyourtail.unimined.api.unimined
import xyz.wagyourtail.unimined.internal.minecraft.patch.jarmod.JarModAgentMinecraftTransformer
import xyz.wagyourtail.unimined.util.withSourceSet

abstract class PatchExtension {
abstract class PatchExtension(val project: Project) {

fun patchBaseCreator(minecraftConfig: MinecraftConfig) {
minecraftConfig.patchBaseCreator()
fun patchBaseCreator(sourceSet: SourceSet) {
val mc = project.unimined.minecrafts.map[sourceSet]!!
if (mc.side == EnvType.COMBINED) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] Merged may make applying patches more difficult, proceed with caution")
}
if (!mc.defaultRemapJar) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] defaultRemapJar is false, this may cause issues with patching")
}
if (mc.mcPatcher !is JarModAgentMinecraftTransformer) {
project.logger.warn("[PatchBase/Creator ${this.project.path} ${sourceSet}] mcPatcher is not a JarModAgentMinecraftTransformer, this may cause issues with dev runs")
}

project.tasks.register("createSourcePatch".withSourceSet(sourceSet), CreateSourcePatchTask::class.java) {
it.group = "patchbase"
it.sourceDir.set(project.file("src/${sourceSet.name}/java"))
it.outputDir.set(project.file("patches/${sourceSet.name}"))
val sourceFile = mc.minecraftFileDev.resolveSibling(mc.minecraftFileDev.nameWithoutExtension + "-sources.jar")
it.sources.set(project.files(sourceFile))
if (!sourceFile.exists()) {
it.dependsOn("genSources")
}
}

project.tasks.register("applySourcePatch".withSourceSet(sourceSet), ApplySourcePatchTask::class.java) {
it.group = "patchbase"
it.patchDir.set(project.file("patches/${sourceSet.name}"))
it.outputDir.set(project.file("src/${sourceSet.name}/java"))
val sourceFile = mc.minecraftFileDev.resolveSibling(mc.minecraftFileDev.nameWithoutExtension + "-sources.jar")
it.sources.set(project.files(sourceFile))
if (!sourceFile.exists()) {
it.dependsOn("genSources".withSourceSet(sourceSet))
}
}

project.tasks.register("createClassPatch".withSourceSet(sourceSet), CreateClassPatchTask::class.java) {
it.group = "patchbase"
it.inputFile.set((project.tasks.findByName("remapJar".withSourceSet(sourceSet)) as Jar).outputs.files.singleFile)

when (mc.side) {
EnvType.CLIENT -> it.classpath.set(project.files(mc.minecraftData.minecraftClientFile))
EnvType.SERVER -> it.classpath.set(project.files(mc.minecraftData.minecraftServerFile))
EnvType.COMBINED -> {
it.classpath.set(project.files(mc.mergedOfficialMinecraftFile))
}
else -> throw IllegalStateException("Unknown side: ${mc.side}")
}

it.archiveClassifier.set("patch")
it.dependsOn("remapJar".withSourceSet(sourceSet))
}
}

fun patchBase(minecraftConfig: MinecraftConfig) {
Expand Down

0 comments on commit 23b03ee

Please sign in to comment.