Generate fake fabric.mod.json to be sure that it is on the current classpath.

This commit is contained in:
shedaniel
2021-01-19 22:23:11 +08:00
parent 475c79fc67
commit b54bd5176f
3 changed files with 32 additions and 7 deletions

View File

@@ -1,10 +1,8 @@
package me.shedaniel.architect.plugin
import net.fabricmc.loom.util.LoggerFilter
import org.gradle.api.JavaVersion
import org.gradle.api.Plugin
import org.gradle.api.Project
import org.gradle.api.plugins.JavaPluginExtension
import java.net.URI
class ArchitectPlugin : Plugin<Project> {
@@ -36,11 +34,12 @@ class ArchitectPlugin : Plugin<Project> {
project.tasks.register("transformArchitectJar", TransformTask::class.java) {
it.group = "Architectury"
it.runtime = false
}
project.tasks.register("transformArchitectJarRuntime", TransformTask::class.java) {
it.group = "Architectury"
it.addRefmap = false
it.runtime = true
}
project.repositories.apply {

View File

@@ -76,6 +76,10 @@ open class RemapMCPTask : Jar() {
}
}
}
if (ZipUtil.containsEntry(intermediate.toFile(), "fabric.mod.json")) {
ZipUtil.removeEntry(intermediate.toFile(), "fabric.mod.json")
}
}

View File

@@ -10,13 +10,17 @@ import net.fabricmc.tinyremapper.*
import org.gradle.api.file.RegularFileProperty
import org.gradle.api.tasks.TaskAction
import org.gradle.jvm.tasks.Jar
import org.zeroturnaround.zip.ByteSource
import org.zeroturnaround.zip.ZipUtil
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.util.*
import kotlin.collections.LinkedHashSet
open class TransformTask : Jar() {
val input: RegularFileProperty = GradleSupport.getFileProperty(project)
var addRefmap = true
var runtime = false
@TaskAction
fun doTask() {
@@ -25,7 +29,7 @@ open class TransformTask : Jar() {
val intermediate2: Path = input.parent.resolve(input.toFile().nameWithoutExtension + "-intermediate2.jar")
val output: Path = this.archiveFile.get().asFile.toPath()
if (addRefmap) {
if (!runtime) {
val loomExtension = project.extensions.getByType(LoomGradleExtension::class.java)
var remapperBuilder = TinyRemapper.newRemapper()
for (mixinMapFile in loomExtension.allMixinMappings) {
@@ -65,6 +69,24 @@ open class TransformTask : Jar() {
remapper.finish()
} else {
Files.copy(input, intermediate)
val fakeModId = "generated_" + UUID.randomUUID().toString().filterNot { it == '-' }.take(7)
ZipUtil.addOrReplaceEntries(
intermediate.toFile(), arrayOf(
ByteSource(
"fabric.mod.json", """
{
"schemaVersion": 1,
"id": "$fakeModId",
"name": "Generated Mod (Please Ignore)",
"version": "1.0.0",
"custom": {
"fabric-loom:generated": true
}
}
""".toByteArray()
)
)
)
}
Files.deleteIfExists(intermediate2)
@@ -81,7 +103,7 @@ open class TransformTask : Jar() {
Files.deleteIfExists(intermediate2)
if (addRefmap) {
if (!runtime) {
val loomExtension = project.extensions.getByType(LoomGradleExtension::class.java)
var refmapHelperClass: Class<*>? = null
runCatching {