2021-12-03 08:35:29 -05:00
|
|
|
archivesBaseName = "fabric-data-generation-api-v1"
|
|
|
|
version = getSubprojectVersion(project)
|
|
|
|
|
|
|
|
moduleDependencies(project, [
|
|
|
|
'fabric-api-base',
|
|
|
|
'fabric-registry-sync-v0',
|
2022-01-14 10:08:18 -05:00
|
|
|
'fabric-networking-api-v1',
|
2022-09-25 09:44:35 -04:00
|
|
|
'fabric-resource-conditions-api-v1',
|
2022-10-22 15:38:33 -04:00
|
|
|
'fabric-item-group-api-v1'
|
2021-12-03 08:35:29 -05:00
|
|
|
])
|
|
|
|
|
2021-12-22 13:25:57 -05:00
|
|
|
dependencies {
|
|
|
|
}
|
|
|
|
|
2021-12-03 08:35:29 -05:00
|
|
|
sourceSets {
|
|
|
|
testmod {
|
|
|
|
resources {
|
|
|
|
srcDirs += [
|
|
|
|
'src/testmod/generated'
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
loom {
|
|
|
|
accessWidenerPath = file("src/main/resources/fabric-data-generation-api-v1.accesswidener")
|
|
|
|
|
|
|
|
runs {
|
|
|
|
datagen {
|
|
|
|
inherit testmodServer
|
|
|
|
name "Data Generation"
|
|
|
|
vmArg "-Dfabric-api.datagen"
|
|
|
|
vmArg "-Dfabric-api.datagen.output-dir=${file("src/testmod/generated")}"
|
|
|
|
vmArg "-Dfabric-api.datagen.strict-validation"
|
|
|
|
|
|
|
|
ideConfigGenerated = true
|
|
|
|
runDir "build/datagen"
|
|
|
|
}
|
|
|
|
datagenClient {
|
|
|
|
client()
|
|
|
|
name "Data Generation"
|
|
|
|
vmArg "-Dfabric-api.datagen"
|
|
|
|
vmArg "-Dfabric-api.datagen.output-dir=${file("src/testmod/generated")}"
|
|
|
|
vmArg "-Dfabric-api.datagen.strict-validation"
|
|
|
|
|
|
|
|
ideConfigGenerated = true
|
|
|
|
runDir "build/datagen"
|
|
|
|
source sourceSets.testmod
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 12:22:58 -05:00
|
|
|
test.dependsOn runDatagen
|
2021-12-03 08:35:29 -05:00
|
|
|
|
|
|
|
import org.objectweb.asm.ClassReader
|
|
|
|
import org.objectweb.asm.Opcodes
|
|
|
|
import org.objectweb.asm.tree.ClassNode
|
|
|
|
|
|
|
|
import java.util.zip.ZipFile
|
|
|
|
|
|
|
|
task generateAccessWidener() {
|
|
|
|
doLast {
|
2022-06-19 14:17:44 -04:00
|
|
|
File inputJar = loom.namedMinecraftProvider.parentMinecraftProvider.commonJar.toFile()
|
2021-12-03 08:35:29 -05:00
|
|
|
String accessWidener = file("template.accesswidener").text + "\n"
|
|
|
|
|
2022-10-22 15:38:33 -04:00
|
|
|
visitMethods(inputJar, "net/minecraft/data/server/recipe/RecipeProvider.class") { name, desc, owner ->
|
2021-12-03 08:35:29 -05:00
|
|
|
if (it.name == "generate")
|
|
|
|
return
|
|
|
|
|
|
|
|
accessWidener += "transitive-accessible\tmethod\t${owner}\t${name}\t${desc}\n"
|
|
|
|
}
|
|
|
|
|
2022-02-11 12:02:44 -05:00
|
|
|
visitMethods(inputJar, "net/minecraft/data/client/BlockStateModelGenerator.class") { name, desc, owner ->
|
2021-12-03 08:35:29 -05:00
|
|
|
if (desc == "()V")
|
|
|
|
// Skip over methods that dont take any arguments, as they are specific to minecraft.
|
|
|
|
return
|
|
|
|
|
|
|
|
accessWidener += "transitive-accessible\tmethod\t${owner}\t${name}\t${desc}\n"
|
|
|
|
}
|
|
|
|
|
2022-10-22 15:38:33 -04:00
|
|
|
visitMethods(inputJar, "net/minecraft/data/server/loottable/BlockLootTableGenerator.class") { name, desc, owner ->
|
2021-12-03 08:35:29 -05:00
|
|
|
accessWidener += "transitive-accessible\tmethod\t${owner}\t${name}\t${desc}\n"
|
|
|
|
}
|
|
|
|
|
2022-06-19 14:17:44 -04:00
|
|
|
visitMethods(inputJar, "net/minecraft/data/client/ItemModelGenerator.class") { name, desc, owner ->
|
|
|
|
accessWidener += "transitive-accessible\tmethod\t${owner}\t${name}\t${desc}\n"
|
|
|
|
}
|
|
|
|
|
2021-12-03 08:35:29 -05:00
|
|
|
file("src/main/resources/fabric-data-generation-api-v1.accesswidener").text = accessWidener
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
def visitMethods(File input, String className, closure) {
|
|
|
|
def clazz = getClassNode(input, className)
|
2022-02-11 12:02:44 -05:00
|
|
|
|
2021-12-03 08:35:29 -05:00
|
|
|
clazz.methods.forEach {
|
|
|
|
if ((it.access & Opcodes.ACC_SYNTHETIC) != 0 || (it.access & Opcodes.ACC_PUBLIC) != 0)
|
|
|
|
return
|
|
|
|
|
|
|
|
if (it.name.startsWith("<"))
|
|
|
|
return
|
|
|
|
|
|
|
|
closure(it.name, it.desc, clazz.name)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ClassNode getClassNode(File input, String className) {
|
2022-02-11 12:02:44 -05:00
|
|
|
new ZipFile(input).withCloseable { ZipFile zip ->
|
2021-12-03 08:35:29 -05:00
|
|
|
zip.getInputStream(zip.getEntry(className)).withCloseable { is ->
|
|
|
|
ClassReader reader = new ClassReader(is)
|
|
|
|
ClassNode classNode = new ClassNode()
|
|
|
|
reader.accept(classNode, 0)
|
|
|
|
|
|
|
|
return classNode
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-04-17 14:23:48 -04:00
|
|
|
|
|
|
|
generateResources.dependsOn generateAccessWidener
|