LlamaLad7 / MixinExtras

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

Localcapture for @ModifyExpressionValue #17

Closed KingContaria closed 1 year ago

KingContaria commented 1 year ago

Hi, since its possible to get the enclosing methods parameters, i was wondering if you'd consider also adding localcapture to @ModifyExpressionValue?

LlamaLad7 commented 1 year ago

Did you have a specific use-case in mind for this? I don't currently have any plans to add it because it would add an awful lot of complexity for me and I'm a firm believer that it's never the best way to do things.

KingContaria commented 1 year ago

image I am trying to use ModifyExpressionValue to transform boolean bl = blockHitResult.getBlockPos().equals(blockPos); to boolean bl = blockHitResult.getBlockPos().equals(blockPos) && blockHitResult.getType() != HitResult.Type.MISS; and capturing the blockHitResult seemed like the cleanest way to do that. I know could do some obscure solutions like modifying the getBlockPos instead to return some blockpos thats never equal to blockPos when my condition is wrong with @WrapOperation but it seems like a less readable/straight forward solution if you don't want to add localcapture tho i can resort to that so it wouldn't be too big a deal, i just liked it because of the readability mainly what exactly is so bad about localcapture anyway i never really understood?

KingContaria commented 1 year ago

This should be covered by sugar, correct?

LlamaLad7 commented 1 year ago

Yep, was just about to comment that lol

KingContaria commented 1 year ago

working very nicely! :)

image