|
7 | 7 | import gay.object.hexdebug.registry.HexDebugItems; |
8 | 8 | import net.minecraft.client.Minecraft; |
9 | 9 | import net.minecraft.world.item.Item; |
| 10 | +import org.jetbrains.annotations.Contract; |
10 | 11 | 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; |
11 | 15 | import org.spongepowered.asm.mixin.injection.At; |
12 | 16 | import org.spongepowered.asm.mixin.injection.Inject; |
13 | 17 | import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; |
14 | 18 |
|
15 | 19 | // client side |
16 | 20 | @Mixin(ShiftScrollListener.class) |
17 | 21 | 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 | + |
18 | 31 | @Inject(method = "IsScrollableItem", at = @At("RETURN"), cancellable = true) |
19 | 32 | private static void hexdebug$IsScrollableItem(Item item, CallbackInfoReturnable<Boolean> cir) { |
20 | 33 | if (item == HexDebugItems.DEBUGGER.getValue()) { |
21 | 34 | cir.setReturnValue(true); |
22 | 35 | } |
23 | 36 | } |
24 | 37 |
|
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) { |
34 | 41 | var player = Minecraft.getInstance().player; |
35 | 42 | if ( |
| 43 | + // onScroll preconditions |
36 | 44 | player != null |
| 45 | + && (player.isShiftKeyDown() || !needsSneaking) |
| 46 | + && !player.isSpectator() |
| 47 | + // additional logic |
37 | 48 | && !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()) |
40 | 51 | ) { |
41 | | - return false; |
| 52 | + offHandDelta += delta; |
| 53 | + cir.setReturnValue(true); |
42 | 54 | } |
43 | | - return original.call(item); |
44 | 55 | } |
45 | 56 | } |
0 commit comments