Skip to content

Commit 1ddfdf7

Browse files
committed
Fix broken mixin on Fabric
1 parent 975bf72 commit 1ddfdf7

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

Common/src/main/java/gay/object/hexdebug/mixin/MixinShiftScrollListener.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,50 @@
77
import gay.object.hexdebug.registry.HexDebugItems;
88
import net.minecraft.client.Minecraft;
99
import net.minecraft.world.item.Item;
10+
import org.jetbrains.annotations.Contract;
1011
import org.spongepowered.asm.mixin.Mixin;
12+
import org.spongepowered.asm.mixin.Shadow;
13+
import org.spongepowered.asm.mixin.gen.Accessor;
14+
import org.spongepowered.asm.mixin.gen.Invoker;
1115
import org.spongepowered.asm.mixin.injection.At;
1216
import org.spongepowered.asm.mixin.injection.Inject;
1317
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
1418

1519
// client side
1620
@Mixin(ShiftScrollListener.class)
1721
public abstract class MixinShiftScrollListener {
22+
@Shadow(remap = false)
23+
private static double offHandDelta;
24+
25+
@Contract
26+
@Invoker(value = "IsScrollableItem", remap = false)
27+
public static boolean hexdebug$invokeIsScrollableItem(Item item) {
28+
throw new AssertionError();
29+
}
30+
1831
@Inject(method = "IsScrollableItem", at = @At("RETURN"), cancellable = true)
1932
private static void hexdebug$IsScrollableItem(Item item, CallbackInfoReturnable<Boolean> cir) {
2033
if (item == HexDebugItems.DEBUGGER.getValue()) {
2134
cir.setReturnValue(true);
2235
}
2336
}
2437

25-
@WrapOperation(
26-
method = "onScroll",
27-
at = @At(
28-
value = "INVOKE",
29-
target = "Lat/petrak/hexcasting/client/ShiftScrollListener;IsScrollableItem(Lnet/minecraft/world/item/Item;)Z",
30-
ordinal = 0
31-
)
32-
)
33-
private static boolean hexdebug$preferOffhandIfNotDebugging(Item item, Operation<Boolean> original) {
38+
// TODO: the duplicated logic here feels nasty, but everything else I tried had issues with remapping
39+
@Inject(method = "onScroll", at = @At("HEAD"), cancellable = true, remap = false)
40+
private static void hexdebug$preferOffhandIfNotDebugging(double delta, boolean needsSneaking, CallbackInfoReturnable<Boolean> cir) {
3441
var player = Minecraft.getInstance().player;
3542
if (
43+
// onScroll preconditions
3644
player != null
45+
&& (player.isShiftKeyDown() || !needsSneaking)
46+
&& !player.isSpectator()
47+
// additional logic
3748
&& !ItemDebugger.isDebugging()
38-
&& item == HexDebugItems.DEBUGGER.getValue()
39-
&& original.call(player.getOffhandItem().getItem())
49+
&& player.getMainHandItem().getItem() == HexDebugItems.DEBUGGER.getValue()
50+
&& hexdebug$invokeIsScrollableItem(player.getOffhandItem().getItem())
4051
) {
41-
return false;
52+
offHandDelta += delta;
53+
cir.setReturnValue(true);
4254
}
43-
return original.call(item);
4455
}
4556
}

Common/src/main/resources/hexdebug-common.mixins.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
"compatibilityLevel": "JAVA_17",
55
"minVersion": "0.8",
66
"client": [
7+
"MixinShiftScrollListener"
78
],
89
"mixins": [
910
"MixinMsgShiftScrollC2S",
10-
"MixinOpEval",
11-
"MixinShiftScrollListener"
11+
"MixinOpEval"
1212
],
1313
"injectors": {
1414
"defaultRequire": 1

0 commit comments

Comments
 (0)