Skip to content

Commit a3cd815

Browse files
authored
Fix: Respect injection point specifier with shift. (FabricMC#187)
Gated since this is technically breaking.
1 parent 76b38b8 commit a3cd815

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ packaging=jar
44
description=Mixin (Fabric fork)
55
url=https://fabricmc.net
66
organization=FabricMC
7-
buildVersion=0.16.4
7+
buildVersion=0.16.5
88
upstreamMixinVersion=0.8.7
99
buildType=RELEASE
1010
asmVersion=9.8

src/main/java/org/spongepowered/asm/mixin/FabricUtil.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,15 @@ public final class FabricUtil {
4949
*/
5050
public static final int COMPATIBILITY_0_14_0 = 14000; // 0.14.0+mixin.0.8.6
5151

52+
/**
53+
* Fabric compatibility version 0.16.5
54+
*/
55+
public static final int COMPATIBILITY_0_16_5 = 16005; // 0.16.5+mixin.0.8.7
56+
5257
/**
5358
* Latest compatibility version
5459
*/
55-
public static final int COMPATIBILITY_LATEST = COMPATIBILITY_0_14_0;
60+
public static final int COMPATIBILITY_LATEST = COMPATIBILITY_0_16_5;
5661

5762
public static String getModId(IMixinConfig config) {
5863
return getModId(config, "(unknown)");

src/main/java/org/spongepowered/asm/mixin/injection/InjectionPoint.java

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import org.objectweb.asm.tree.AnnotationNode;
4646
import org.objectweb.asm.tree.InsnList;
4747
import org.objectweb.asm.tree.MethodNode;
48+
import org.spongepowered.asm.mixin.FabricUtil;
4849
import org.spongepowered.asm.mixin.MixinEnvironment;
4950
import org.spongepowered.asm.mixin.MixinEnvironment.Option;
5051
import org.spongepowered.asm.mixin.injection.callback.CallbackInjector;
@@ -552,14 +553,20 @@ static final class Shift extends InjectionPoint {
552553

553554
private final InjectionPoint input;
554555
private final int shift;
556+
private final boolean respectSpecifier;
555557

556558
public Shift(InjectionPoint input, int shift) {
559+
this(input, shift, FabricUtil.COMPATIBILITY_LATEST);
560+
}
561+
562+
public Shift(InjectionPoint input, int shift, int fabricCompatibility) {
557563
if (input == null) {
558564
throw new IllegalArgumentException("Must supply an input injection point for SHIFT");
559565
}
560566

561567
this.input = input;
562568
this.shift = shift;
569+
this.respectSpecifier = fabricCompatibility >= FabricUtil.COMPATIBILITY_0_16_5;
563570
}
564571

565572
/* (non-Javadoc)
@@ -606,6 +613,11 @@ public boolean find(String desc, InsnList insns, Collection<AbstractInsnNode> no
606613

607614
return nodes.size() > 0;
608615
}
616+
617+
@Override
618+
public Specifier getSpecifier(Specifier defaultSpecifier) {
619+
return this.respectSpecifier ? this.input.getSpecifier(defaultSpecifier) : super.getSpecifier(defaultSpecifier);
620+
}
609621
}
610622

611623
/**
@@ -871,15 +883,17 @@ private static InjectionPoint create(IMixinContext context, InjectionPointData d
871883

872884
private static InjectionPoint shift(IInjectionPointContext context, InjectionPoint point,
873885
At.Shift shift, int by) {
886+
887+
int fabricCompatibility = FabricUtil.getCompatibility(context);
874888

875889
if (point != null) {
876890
if (shift == At.Shift.BEFORE) {
877-
return InjectionPoint.before(point);
891+
return new InjectionPoint.Shift(point, -1, fabricCompatibility);
878892
} else if (shift == At.Shift.AFTER) {
879-
return InjectionPoint.after(point);
893+
return new InjectionPoint.Shift(point, 1, fabricCompatibility);
880894
} else if (shift == At.Shift.BY) {
881895
InjectionPoint.validateByValue(context.getMixin(), context.getMethod(), context.getAnnotationNode(), point, by);
882-
return InjectionPoint.shift(point, by);
896+
return new InjectionPoint.Shift(point, by, fabricCompatibility);
883897
}
884898
}
885899

0 commit comments

Comments
 (0)