-
Notifications
You must be signed in to change notification settings - Fork 18
WrapWithCondition
Allows you to wrap a field write or void method call with a conditional check.
Your handler method receives the targeted instruction's arguments (optionally followed by the enclosing method's parameters), and should return a boolean indicating whether the operation should go ahead.
Should be used in favour of Redirect
s when you are simply wrapping the original call with a check, as unlike Redirect
s, this chains when used by multiple people.
Targeted operation | Handler signature |
---|---|
Non-static method call | private boolean yourHandlerMethod(OwnerType instance, <arguments of the original call>) |
Static method call | private boolean yourHandlerMethod(<arguments of the original call>) |
Non-static field write | private boolean yourHandlerMethod(OwnerType instance, FieldType newValue) |
Static field write | private boolean yourHandlerMethod(FieldType newValue) |
In all of these cases, you can optionally add the enclosing method's parameters to the end, should you require them for additional context.
When targeting code such as the following:
this.render(this.tickDelta);
you may wish to wrap the call in a conditional check, e.g. if (YourMod.shouldRender())
This could be done like so:
@WrapWithCondition(
method = "targetMethod",
at = @At(value = "INVOKE", target = "Lsome/package/TargetClass;render(F)V")
)
private boolean onlyRenderIfAllowed(TargetClass instance, float tickDelta) {
return YourMod.shouldRender();
}
render
would then only be called if your handler method returns true
.
Multiple mods can do this at the same time, and all their conditions will be applied.
+ if (onlyRenderIfAllowed(this, this.tickDelta)) {
this.render(this.tickDelta);
+ }