-
Notifications
You must be signed in to change notification settings - Fork 19
ModifyExpressionValue
Allows you to tweak the resultant value of a method call, field get, constant, or new object instantiation.
Your handler method receives the expression's resultant value (optionally followed by the enclosing method's parameters), and should return the adjusted value.
Should be used in favour of Redirect
s or ModifyConstant
s when you want to tweak an expression's existing value instead of replacing it entirely, as unlike Redirect
s and ModifyConstant
s, this chains when used by multiple people.
When targeting code such as the following:
if (this.shouldFly()) {
this.fly();
}
you may wish to add an extra condition, e.g. && YourMod.isFlyingAllowed()
This could be done like so:
@ModifyExpressionValue(
method = "targetMethod",
at = @At(value = "INVOKE", target = "Ltarget/Class;shouldFly()Z")
)
private boolean onlyFlyIfAllowed(boolean original) {
return original && YourMod.isFlyingAllowed();
}
Your handler method would then be called with the result of shouldFly
, and you could prevent flying should you wish.
Multiple mods can do this at the same time, and all their modifications will be applied.
- if (this.shouldFly()) {
+ if (onlyFlyIfAllowed(this.shouldFly())) {