MixinExtras icon indicating copy to clipboard operation
MixinExtras copied to clipboard

[Suggestion] @WrapMethod

Open contariaa opened this issue 1 year ago • 2 comments

Hi,

a new @WrapMethod injector, which would work similar to WrapOperation, except wrapping the entire method instead of just a single call.

I am currently working on a project which requires me to do some synchronization, however it seems all the ways i can think of to accomplish my goal have some sort of downside. Specifically, I am trying to synchronize this entire method on the this.surfaceBuilder object.

public void buildSurface(Random random, Chunk chunk, int x, int z, int worldHeight, double noise, BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed) {
    this.surfaceBuilder.initSeed(seed);
    this.surfaceBuilder.generate(random, chunk, this, x, z, worldHeight, noise, defaultBlock, defaultFluid, seaLevel, seed);
}

I can't use two WrapOperation's because i rely on it being a single synchronization block and i can't use a mixin config plugin to synchronize the method because i want it to synchronize specifically on the surfacebuilder object AND additionally i only want to apply the synchronization conditionally. Another solution I've considered is using some form of lock and simply injecting at head and tail, however it seems not ideal to have the lock release not be in a finally block.

Using a new @WrapMethod injector i could simply wrap the entire method with my synchronization logic. It could also allow for adding try-catch or -finally blocks.

The only thing similar in the closed issues i could find was https://github.com/LlamaLad7/MixinExtras/issues/8 suggesting try-catch-finally injectors which are now covered by wrapoperation, however you also talked about potentially wrapping the entire method or slices of methods. While this wouldn't cover only wrapping a certain slice, it would allow catching errors in the entire method, not just on a single operation.

contariaa avatar Jan 17 '24 12:01 contariaa

This is planned but good to have an issue tracking it.

LlamaLad7 avatar Jan 17 '24 12:01 LlamaLad7

I also need this, pretty much need to wrap a whole method in a try-with-resources.

Need to wrap a parameter, and then close the wrapper before return.

TropheusJ avatar Feb 29 '24 19:02 TropheusJ