-
Notifications
You must be signed in to change notification settings - Fork 19
ModifyReturnValue
NB: Not to be confused with ModifyExpressionValue
Allows you to tweak the value being returned from a method.
Your handler method receives the value about to be returned (optionally followed by the enclosing method's parameters), and should return the adjusted value.
Should be used in favour of Inject
s with the cir.setReturnValue(modify(cir.getReturnValue()))
pattern, as that pattern does not chain when multiple people do it, whereas this does.
When targeting code such as the following:
return this.speed * 10f - 0.5f;
you may wish to change the value being returned, e.g. by dividing it by 2.
This could be done like so:
@ModifyReturnValue(
method = "targetMethod",
at = @At("RETURN")
)
private float halveSpeed(float original) {
return original / 2f;
}
Your handler method would then be called with the result of the existing calculation, and you could change the value as it is returned.
Multiple mods can do this at the same time, and all their modifications will be applied.
- return this.speed * 10f - 0.5f;
+ return halveSpeed(this.speed * 10f - 0.5f);