I need some help with Mixin
-
As title
i wanna find a way to do it but failed :<
So if some one can give an helping hand for make boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
to true
btw. flag2 is in EntityPlayerSP.onUpdateWalkingPlayer() and in EntityPlayerSP's 221
Please added it with valid -
@vanillamirror said in I need some help with Mixin:
So if some one can give an helping hand for make boolean flag2 = d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
to trueALWAYS set to true though?
-
@vanillamirror said in I need some help with Mixin:
@mems yes
Alright, this is my method to solve this, even though there are probably a few more:
First, you use the
ModifyVariable
injection, withSTORE
as the annotation type, then we make use of thename
parameter, or whatever it's called. In your case, you are looking to target theflag2
variable's value that exists in theonUpdateWalkingPlayer
function.This is how it's done in code:
@ModifyVariable(method = "onUpdateWalkingPlayer", at = @At("STORE"), name = "flag2")
Then you add the required function (boolean type as the variable is a boolean type):
private boolean nameThatYouWouldLike(boolean value) { }
boolean value
contains the default value result that is from theflag2
variable.This:
d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
in case you ask.Replace the
nameThatYouWouldLike
with whatever you want, or keep it like that, as long as it has a name.Finally, you add your custom code inside and in your case again it's to set the value to true. Remember, you must also use
return
to the new value you set, whether it's false or true, or something else. An example:private boolean nameThatYouWouldLike(boolean value) { if (LiquidBounce.moduleManager.getModule(XRay.class).getState()) { return true; } return value; }
return value
this will return the value result from the original code, which is this:d0 * d0 + d1 * d1 + d2 * d2 > 9.0E-4D || this.positionUpdateTicks >= 20;
return true
is your modified code. (it just returns true, it won't change, as long as the statement is also true)This is how the full version of the example looks like:
@ModifyVariable(method = "onUpdateWalkingPlayer", at = @At("STORE"), name = "flag2") private boolean nameThatYouWouldLike(boolean value) { if (LiquidBounce.moduleManager.getModule(XRay.class).getState()) { return true; } return value; }
And now, I assume you know how to code, so replace this:
if (LiquidBounce.moduleManager.getModule(XRay.class).getState()) { return true; }
with something of your own.
Long ass post, but I want to make sure you understand. If you have any questions regarding that, don't hesitate to ask.