LlamaLad7 / MixinExtras

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

Is it possible to do @WrapOperation with @At("HEAD")? #60

Closed StewStrong closed 6 months ago

StewStrong commented 6 months ago

I can't seem to get it working. If not, this would be very useful!

LlamaLad7 commented 6 months ago

Wrapping the first instruction in a method most likely does not make sense depending on what the instruction is. It’s certainly not a stable idea to target. If you want to wrap the entire method then that’d be different and might potentially be planned, i’ll have to see. If you have a specific scenario then just ask in the discord cause it’s probably possible right now anyway.

StewStrong commented 6 months ago

Can you link the discord? I can't find it.

LlamaLad7 commented 6 months ago

Whatever discord your modloader uses, or the sponge powered discord if none of those fit.

StewStrong commented 6 months ago

If you want to wrap the entire method then that’d be different and might potentially be planned Yeah thats what I want.

Currently I have to do something like this

boolean isModifyingPathType = false;

@Inject(method = "getBlockPathTypeRaw", at = @At("RETURN"), cancellable = true)
private static void getBlockPathTypeForShips(final BlockGetter blockGetter, final BlockPos blockPos,
    final CallbackInfoReturnable<BlockPathTypes> cir) {
    if (isModifyingPathType) {
        return;
    }

    isModifyingPathType = true;

    // Reinvoke with different args
    modified = getBlockPathTypeRaw(((PathNavigationRegionAccessor) blockGetter).getLevel(), groundPos);

    isModifyingPathType = false;

It'd be better to write this using something like @WrapMethod.

LlamaLad7 commented 6 months ago

Well no, you should just use a ModifyVariable at HEAD. If you want to modify multiple parameters at once then use mutable Locals.