How do I change the return value using a Mixin?

I have a method that i want to change that looks like this:

 public boolean checkSomething(int value) {
     return (value / other value) < thirdValue;
}

But my mod needs it to act like this under certain conditions only:

public boolean checkSomething(int value) {
if(condition) {
return (value / other value) > thirdValue;
} else {
return (value / other value) < thirdValue;
}

So, my plan was to create an inject that looks like this:

@Inject(..., cancellable=true, at=@At("HEAD"))
private void method(int value, CallbackInfo info) {
   if(condition) { //THIS IS AN INTERVENTION!
     boolean returnValue = return (value / other value) > thirdValue;
     info.cancel();
     //What now?
    } else return;
}

The problem is obvious: How do I get the value out of the Inject and into the method itself?

I invite you to read the documentation: Advanced Mixin Usage Callback Injectors · SpongePowered/Mixin Wiki · GitHub .

1 Like

thanks for the awesome information.