@@ -166,11 +166,13 @@ private void applyBlockStateCacheScan(ClassNode targetClass) {
166166 "getFluidState" , "method_26227" , "m_60819_" , "func_204520_s"
167167 );
168168 Map <String , MethodNode > injectorMethodNames = new HashMap <>();
169+ Map <String , MethodNode > allMethods = new HashMap <>();
169170 Map <String , String > injectorMixinSource = new HashMap <>();
170171 String descriptor = Type .getDescriptor (MixinMerged .class );
171172 for (MethodNode m : targetClass .methods ) {
172173 if ((m .access & Opcodes .ACC_STATIC ) != 0 )
173174 continue ;
175+ allMethods .put (m .name , m );
174176 Set <AnnotationNode > seenNodes = new HashSet <>();
175177 if (m .invisibleAnnotations != null ) {
176178 for (AnnotationNode ann : m .invisibleAnnotations ) {
@@ -217,8 +219,35 @@ private void applyBlockStateCacheScan(ClassNode targetClass) {
217219 }
218220 }
219221 Set <String > accessedFieldNames = new HashSet <>();
220- // We now know all methods that have been injected into initCache. See what fields they write to
221- injectorMethodNames .forEach ((name , method ) -> {
222+
223+ // Make a map of all injected methods called by initCache
224+ Map <String , MethodNode > writingMethods = new HashMap <>(injectorMethodNames );
225+ writingMethods .keySet ().retainAll (cacheCalledInjectors );
226+
227+ // Recursively check the injected methods for any methods they may call
228+ int previousSize = 0 ;
229+ Set <String > checkedCalls = new HashSet <>();
230+ while (writingMethods .size () > previousSize ) {
231+ previousSize = writingMethods .size ();
232+ List <String > keysToCheck = new ArrayList <>(writingMethods .keySet ());
233+ for (String name : keysToCheck ) {
234+ if (!checkedCalls .add (name ))
235+ continue ;
236+ for (AbstractInsnNode n : writingMethods .get (name ).instructions ) {
237+ if (n instanceof MethodInsnNode ) {
238+ MethodInsnNode invokeNode = (MethodInsnNode )n ;
239+ if (invokeNode .owner .equals (targetClass .name )) {
240+ MethodNode theMethod = allMethods .get (invokeNode .name );
241+ if (theMethod != null )
242+ writingMethods .put (invokeNode .name , theMethod );
243+ }
244+ }
245+ }
246+ }
247+ }
248+
249+ // We now know all methods that have been injected into initCache, and their callers. See what fields they write to
250+ writingMethods .forEach ((name , method ) -> {
222251 if (cacheCalledInjectors .contains (name )) {
223252 for (AbstractInsnNode n : method .instructions ) {
224253 if (n instanceof FieldInsnNode ) {
0 commit comments