@@ -46,7 +46,7 @@ class TileEntityAccessor<T extends BlockState> {
46
46
private boolean writeDetected ;
47
47
private boolean readDetected ;
48
48
49
- private TileEntityAccessor () {
49
+ TileEntityAccessor () {
50
50
// Do nothing
51
51
}
52
52
@@ -59,25 +59,28 @@ private TileEntityAccessor(FieldAccessor tileEntityField, T state) {
59
59
if (tileEntityField != null ) {
60
60
this .tileEntityField = tileEntityField ;
61
61
Class <?> type = tileEntityField .getField ().getType ();
62
+ findMethods (type , state );
63
+ }
64
+ }
62
65
63
- // Possible read/write methods
66
+ void findMethods (Class <?> type , T state ) {
67
+ // Possible read/write methods
68
+ try {
69
+ findMethodsUsingASM ();
70
+ } catch (IOException ex1 ) {
64
71
try {
65
- findMethodsUsingASM ();
66
- } catch (IOException ex1 ) {
67
- try {
68
- // Much slower though
69
- findMethodUsingCGLib (state );
70
- } catch (Exception ex2 ) {
71
- throw new RuntimeException ("Cannot find read/write methods in " + type , ex2 );
72
- }
72
+ // Much slower though
73
+ findMethodUsingCGLib (state );
74
+ } catch (Exception ex2 ) {
75
+ throw new RuntimeException ("Cannot find read/write methods in " + type , ex2 );
73
76
}
74
-
75
- // Ensure we found them
76
- if (readCompound == null )
77
- throw new RuntimeException ("Unable to find read method in " + type );
78
- if (writeCompound == null )
79
- throw new RuntimeException ("Unable to find write method in " + type );
80
77
}
78
+
79
+ // Ensure we found them
80
+ if (readCompound == null )
81
+ throw new RuntimeException ("Unable to find read method in " + type );
82
+ if (writeCompound == null )
83
+ throw new RuntimeException ("Unable to find write method in " + type );
81
84
}
82
85
83
86
/**
@@ -90,25 +93,25 @@ private void findMethodsUsingASM() throws IOException {
90
93
final ClassReader reader = new ClassReader (tileEntityClass .getCanonicalName ());
91
94
92
95
final String tagCompoundName = getJarName (MinecraftReflection .getNBTCompoundClass ());
93
- final String expectedDesc = "(L" + tagCompoundName + ";)V " ;
96
+ final String expectedDesc = "(L" + tagCompoundName + ";)" ;
94
97
95
98
reader .accept (new EmptyClassVisitor () {
96
99
@ Override
97
100
public MethodVisitor visitMethod (int access , String name , String desc , String signature , String [] exceptions ) {
98
101
final String methodName = name ;
99
102
100
103
// Detect read/write calls to NBTTagCompound
101
- if (expectedDesc . equals ( desc )) {
104
+ if (desc . startsWith ( expectedDesc )) {
102
105
return new EmptyMethodVisitor () {
103
106
private int readMethods ;
104
107
private int writeMethods ;
105
108
106
109
@ Override
107
110
public void visitMethodInsn (int opcode , String owner , String name , String desc ) {
108
111
// This must be a virtual call on NBTTagCompound that accepts a String
109
- if (opcode == Opcodes .INVOKEVIRTUAL &&
110
- tagCompoundName .equals (owner ) &&
111
- desc .startsWith ("(Ljava/lang/String" )) {
112
+ if (opcode == Opcodes .INVOKEVIRTUAL
113
+ && tagCompoundName .equals (owner )
114
+ && desc .startsWith ("(Ljava/lang/String" )) {
112
115
113
116
// Is this a write call?
114
117
if (desc .endsWith (")V" )) {
@@ -126,10 +129,12 @@ public void visitEnd() {
126
129
} else if (writeMethods > readMethods ) {
127
130
writeCompound = Accessors .getMethodAccessor (tileEntityClass , methodName , nbtCompoundClass );
128
131
}
132
+
129
133
super .visitEnd ();
130
134
}
131
135
};
132
136
}
137
+
133
138
return null ;
134
139
}
135
140
}, 0 );
0 commit comments