LlamaLad7 / MixinExtras

Companion library to SpongePowered Mixin with many custom injectors for a more expressive experience.
MIT License
304 stars 17 forks source link

@WrapOperation can not recieve arguments from method, thus failing to replace @Redirect in some cases #24

Closed magicus closed 1 year ago

magicus commented 1 year ago

MixinExtras has been a great improvement to skip all those @Redirect in our mod. Thanks for that!

However, I just noticed that I have a place where I cannot replace @Redirect with @WrapOperation. Consider the following code:

public void outerMethod(ItemStack itemStack, int i) {
 // ...
 innerCall(0, i);
}

For @Redirect, it is possible to get the arguments of outerMethod as well, using a signature like this:

void myMixin(int zero, int i, ItemStack itemStack, int i2)

Unfortunately, @WrapOperation does not have this functionality. And since I needed that ItemStack to get my mixin to work, I need to keep the @Redirect.

It would be nice if this use case could be supported by @WrapOperation as well.

magicus commented 1 year ago

It was pointed out to me that using @Local will solve this particular issue, and it seems to work fine for me.

However, since @Local is still in beta, users might be reluctant to use it. So I'm leaving this issue open; but feel free to close it. (And feel even freer in bringing @Local to a fully supported state! ;-))

LlamaLad7 commented 1 year ago

As mentioned in its docs, WrapOperation does let you get the enclosing method's arguments. As with every other injector you simply add them to the end of your handler parameters. If this is not working for you then feel free to re-open with some more details of exactly what you're trying and what isn't working.

magicus commented 1 year ago

I went back to try to figure out what I was doing which did not work. And of course, now it worked. I think my problem was that I added the additional arguments before the Operation argument, and not after. PEBKAC, as they say. :)

Sorry for the false bug report, and thank you for a fantastic toolkit for us modders! I cannot for my life understand why this is not part of the Mixin core functionality, but I'm happy at least that you provide it. Thanks!