Add transitive access wideners for tracked data related creator entity methods (#4229)

* feat: transitive access wideners for display entity fields

* fix: change display transitive access widener collector to check for dataTracker accesses

* fix: incorrect method names & comments

* refactor: move getMethodParameterCount to use existing lib

* feat: InteractionEntity methods & missing method from DisplayEntity

(cherry picked from commit 54a41b1cc9)
This commit is contained in:
Daniel Orr 2024-11-25 18:13:21 +00:00 committed by modmuss50
parent aa5b2ca19e
commit 56e78b9be0
2 changed files with 110 additions and 2 deletions

View file

@ -11,6 +11,8 @@ testDependencies(project, [
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes
import org.objectweb.asm.Type
import org.objectweb.asm.tree.ClassNode
@ -19,7 +21,6 @@ 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
tasks.register('generateAccessWidener') {
doLast {
@ -38,6 +39,8 @@ tasks.register('generateAccessWidener') {
lines.add("")
generateItemConstructors(lines, fs)
lines.add("")
generateCreatorEntityTrackedDataMethods(lines, fs)
lines.add("")
}
Path clientJar = loom.namedMinecraftProvider.parentMinecraftProvider.clientOnlyJar.path
@ -128,11 +131,67 @@ def generateRenderPhaseInnerClasses(List<String> lines, FileSystem fs) {
}
}
def generateTrackedDataFields(String className, List<String> lines, FileSystem fs, String... extraMethods) {
// using a set to prevent duplicates from multiple dataTracker references in a single method
// linked to preserve order and improve generated access widener readability
Set<String> collectedWideners = new LinkedHashSet<>()
loadClass(fs.getPath("${className}.class")).accept(
new ClassVisitor(Opcodes.ASM9) {
@Override
MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) {
boolean isExtra = extraMethods.contains(name)
if (!isExtra) {
// check for desired methods
if (!name.startsWith("get") && !name.startsWith("set")) {
return null
}
// check methods as genuine basic getter/setters
int parameterCount = Type.getArgumentCount(descriptor)
if (name.startsWith("get") && parameterCount != 0) {
return null
}
if (name.startsWith("set") && parameterCount != 1) {
return null
}
} else {
println name
}
return new MethodVisitor(Opcodes.ASM9) {
@Override
void visitFieldInsn(int opcode, String owner, String fieldName, String fieldDescriptor) {
// check references its dataTracker field
if (isExtra || (fieldName == "dataTracker" && opcode == Opcodes.GETFIELD)) {
collectedWideners.add("transitive-accessible method $className $name $descriptor")
}
}
}
}
}
)
lines.addAll(collectedWideners)
}
def generateCreatorEntityTrackedDataMethods(List<String> lines, FileSystem fs) {
lines.add("# Private tracked data related methods of DisplayEntity (plus its subclasses) and InteractionEntity")
generateTrackedDataFields("net/minecraft/entity/decoration/DisplayEntity", lines, fs, "getTransformation")
generateTrackedDataFields("net/minecraft/entity/decoration/DisplayEntity\$ItemDisplayEntity", lines, fs)
generateTrackedDataFields("net/minecraft/entity/decoration/DisplayEntity\$BlockDisplayEntity", lines, fs)
generateTrackedDataFields("net/minecraft/entity/decoration/DisplayEntity\$TextDisplayEntity", lines, fs)
generateTrackedDataFields("net/minecraft/entity/decoration/InteractionEntity", lines, fs, "shouldRespond")
}
ClassNode loadClass(Path path) {
def node = new ClassNode()
Files.newInputStream(path).withCloseable { is ->
new ClassReader(is).accept(node, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
new ClassReader(is).accept(node, ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES)
}
return node

View file

@ -245,6 +245,55 @@ transitive-accessible method net/minecraft/block/WitherSkullBlock <init> (Lnet/m
# Constructors of non-abstract item classes
transitive-accessible method net/minecraft/item/MiningToolItem <init> (Lnet/minecraft/item/ToolMaterial;Lnet/minecraft/registry/tag/TagKey;FFLnet/minecraft/item/Item$Settings;)V
# Private tracked data related methods of DisplayEntity (plus its subclasses) and InteractionEntity
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getTransformation (Lnet/minecraft/entity/data/DataTracker;)Lnet/minecraft/util/math/AffineTransformation;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setTransformation (Lnet/minecraft/util/math/AffineTransformation;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setInterpolationDuration (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getInterpolationDuration ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setStartInterpolation (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getStartInterpolation ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setTeleportDuration (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getTeleportDuration ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setBillboardMode (Lnet/minecraft/entity/decoration/DisplayEntity$BillboardMode;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getBillboardMode ()Lnet/minecraft/entity/decoration/DisplayEntity$BillboardMode;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setBrightness (Lnet/minecraft/entity/decoration/Brightness;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getBrightnessUnpacked ()Lnet/minecraft/entity/decoration/Brightness;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getBrightness ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setViewRange (F)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getViewRange ()F
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setShadowRadius (F)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getShadowRadius ()F
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setShadowStrength (F)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getShadowStrength ()F
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setDisplayWidth (F)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getDisplayWidth ()F
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setDisplayHeight (F)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getGlowColorOverride ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity setGlowColorOverride (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity getDisplayHeight ()F
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$ItemDisplayEntity getItemStack ()Lnet/minecraft/item/ItemStack;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$ItemDisplayEntity setItemStack (Lnet/minecraft/item/ItemStack;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$ItemDisplayEntity setTransformationMode (Lnet/minecraft/item/ModelTransformationMode;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$ItemDisplayEntity getTransformationMode ()Lnet/minecraft/item/ModelTransformationMode;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$BlockDisplayEntity getBlockState ()Lnet/minecraft/block/BlockState;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$BlockDisplayEntity setBlockState (Lnet/minecraft/block/BlockState;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity getText ()Lnet/minecraft/text/Text;
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity setText (Lnet/minecraft/text/Text;)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity getLineWidth ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity setLineWidth (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity getTextOpacity ()B
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity setTextOpacity (B)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity getBackground ()I
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity setBackground (I)V
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity getDisplayFlags ()B
transitive-accessible method net/minecraft/entity/decoration/DisplayEntity$TextDisplayEntity setDisplayFlags (B)V
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity setInteractionWidth (F)V
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity getInteractionWidth ()F
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity setInteractionHeight (F)V
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity getInteractionHeight ()F
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity setResponse (Z)V
transitive-accessible method net/minecraft/entity/decoration/InteractionEntity shouldRespond ()Z
# Protected static fields of RenderPhase
transitive-accessible field net/minecraft/client/render/RenderPhase NO_TRANSPARENCY Lnet/minecraft/client/render/RenderPhase$Transparency;
transitive-accessible field net/minecraft/client/render/RenderPhase ADDITIVE_TRANSPARENCY Lnet/minecraft/client/render/RenderPhase$Transparency;