fabric/fabric-transitive-access-wideners-v1/build.gradle
AlphaMode 6dc0edd789 Deprecated BlockEntityRendererRegistry in favor of vanilla's BlockEntityRendererFactories (#2582)
* Deprecated BlockEntityRendererRegistry in favor of vanilla's BlockEntityRendererFactories

* Undo unintended change

* Update fabric-transitive-access-wideners-v1/src/main/resources/fabric-transitive-access-wideners-v1.accesswidener

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

* Update BlockEntityRendererRegistry javadoc to match others

* Implement sign renderer test

* Fix template

* Change SignTestBlockEntity to SignBlockEntityTest

Co-authored-by: haykam821 <24855774+haykam821@users.noreply.github.com>

(cherry picked from commit 08b73de4d1)
2022-12-23 15:32:51 +00:00

99 lines
3.4 KiB
Groovy

archivesBaseName = "fabric-transitive-access-wideners-v1"
version = getSubprojectVersion(project)
loom {
accessWidenerPath = file('src/main/resources/fabric-transitive-access-wideners-v1.accesswidener')
}
testDependencies(project, [
':fabric-rendering-v1',
':fabric-object-builder-api-v1'
])
import org.objectweb.asm.ClassReader
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
import java.nio.file.FileSystem
import java.nio.file.FileSystems
import java.nio.file.Files
import java.nio.file.Path
import java.util.stream.Collectors
task generateAccessWidener {
doLast {
List<String> lines = new ArrayList<>();
lines.add("accessWidener v2 named")
lines.add("")
lines.add("# DO NOT EDIT BY HAND! This file is generated automatically.")
lines.add("# Edit \"template.accesswidener\" instead then run \"gradlew generateAccessWidener\".")
lines.add("")
lines.addAll(file("template.accesswidener").text.lines().toList())
Path commonJar = loom.namedMinecraftProvider.parentMinecraftProvider.commonJar
try (def fs = FileSystems.newFileSystem(URI.create("jar:${commonJar.toUri()}"), [create: false])) {
generateBlockConstructors(lines, fs)
lines.add("")
}
Path clientJar = loom.namedMinecraftProvider.parentMinecraftProvider.clientOnlyJar
try (def fs = FileSystems.newFileSystem(URI.create("jar:${clientJar.toUri()}"), [create: false])) {
generateRenderPhaseFields(lines, fs)
}
file('src/main/resources/fabric-transitive-access-wideners-v1.accesswidener').text = String.join('\n', lines) + '\n'
}
}
def generateBlockConstructors(List<String> lines, FileSystem fs) {
lines.add("# Constructors of non-abstract block classes")
Files.list(fs.getPath("net/minecraft/block"))
.filter { Files.isRegularFile(it) && it.toString().endsWith(".class") }
.map { loadClass(it) }
.sorted(Comparator.comparing { it.name })
.filter { (it.access & Opcodes.ACC_ABSTRACT) == 0 }
.forEach { node ->
for (def method : node.methods) {
// Checklist for finding block constructors as of 1.18.2:
// - class directly in net.minecraft.block (excluding subpackages)
// - method name == <init> (by definition)
// - contains an AbstractBlock$Settings parameter
// - only taking into account non-abstract classes and non-public constructors
// Block constructor...
if (method.name == "<init>" && Type.getArgumentTypes(method.desc).any { it.internalName == 'net/minecraft/block/AbstractBlock$Settings' }) {
// ...and non-public
if ((method.access & Opcodes.ACC_PUBLIC) == 0) {
lines.add("transitive-accessible method $node.name <init> $method.desc")
}
}
}
}
}
def generateRenderPhaseFields(List<String> lines, FileSystem fs) {
lines.add("# Protected static fields of RenderPhase")
for (def field : loadClass(fs.getPath("net/minecraft/client/render/RenderPhase.class")).fields) {
// All protected static fields of RenderPhase
if ((field.access & Opcodes.ACC_PROTECTED) != 0 && (field.access & Opcodes.ACC_STATIC) != 0) {
lines.add("transitive-accessible field net/minecraft/client/render/RenderPhase ${field.name} ${field.desc}")
}
}
}
ClassNode loadClass(Path path) {
def node = new ClassNode()
try (def is = Files.newInputStream(path)) {
new ClassReader(is).accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
}
return node
}
generateResources.dependsOn generateAccessWidener