10
10
import net .neoforged .neoforgespi .coremod .ICoreMod ;
11
11
import org .objectweb .asm .MethodVisitor ;
12
12
import org .objectweb .asm .Opcodes ;
13
+ import org .objectweb .asm .Type ;
13
14
import org .objectweb .asm .tree .ClassNode ;
14
15
import org .objectweb .asm .tree .FieldNode ;
15
16
import org .objectweb .asm .tree .InsnList ;
16
17
import org .objectweb .asm .tree .InsnNode ;
18
+ import org .objectweb .asm .tree .LocalVariableNode ;
17
19
import org .objectweb .asm .tree .MethodInsnNode ;
18
20
import org .objectweb .asm .tree .MethodNode ;
19
21
import org .objectweb .asm .tree .TypeInsnNode ;
20
22
import org .objectweb .asm .tree .VarInsnNode ;
23
+ import org .sinytra .adapter .patch .analysis .locals .LocalVariableLookup ;
21
24
import org .slf4j .Logger ;
22
25
23
26
import java .util .List ;
@@ -113,12 +116,29 @@ public Iterable<? extends ITransformer<?>> getTransformers() {
113
116
}
114
117
}
115
118
);
119
+ ITransformer <?> expandLocalVarScope = new BaseTransformer <>(
120
+ TargetType .METHOD ,
121
+ ITransformer .Target .targetMethod ("net.minecraft.world.entity.LivingEntity" , "forceAddEffect" , "(Lnet/minecraft/world/effect/MobEffectInstance;Lnet/minecraft/world/entity/Entity;)V" ),
122
+ input -> {
123
+ LocalVariableLookup lvt = new LocalVariableLookup (input );
124
+ LocalVariableNode mobEffect = lvt .getByTypedOrdinal (Type .getObjectType ("net/minecraft/world/effect/MobEffectInstance" ), 1 ).orElse (null );
125
+ if (mobEffect != null ) {
126
+ mobEffect .start = lvt .getByIndex (0 ).start ;
127
+ input .instructions .insert (mobEffect .start , ASMAPI .listOf (
128
+ new InsnNode (Opcodes .ACONST_NULL ),
129
+ new VarInsnNode (Opcodes .ASTORE , mobEffect .index )
130
+ ));
131
+ LOGGER .debug ("Expanded local variable scope for LivingEntity#forceAddEffect index {}" , mobEffect .index );
132
+ }
133
+ }
134
+ );
116
135
117
136
return ImmutableList .<ITransformer <?>>builder ()
118
137
.add (keyMappingFieldTypeTransform , creativeModeTabConstructorTransform )
119
138
.addAll (addedFields )
120
139
.addAll (getFabricASMTransformers ())
121
140
.add (missingOrderingCall )
141
+ .add (expandLocalVarScope )
122
142
.build ();
123
143
}
124
144
@@ -128,7 +148,7 @@ private static ITransformer<?> addFieldToClass(String cls, String name, String d
128
148
ITransformer .Target .targetClass (cls ),
129
149
input -> {
130
150
input .fields .add (new FieldNode (access , name , desc , null , null ));
131
-
151
+
132
152
LOGGER .debug ("Added field {} to class {}" , name , cls );
133
153
}
134
154
);
0 commit comments