LlamaLad7 / MixinExtras

Companion library to SpongePowered Mixin with many custom injectors for a more expressive experience.
MIT License
293 stars 16 forks source link

[Question]How do I modify these two (or more) as a whole? #77

Closed Crystal0404 closed 4 months ago

Crystal0404 commented 4 months ago

Here's a snippet of code I found

if (pos.getY() >= world.getSeaLevel()) {
            // .........
        }

How do I use @ModifyExpressionValue to make it look like this

if (myboolean() && (pos.getY() >= world.getSeaLevel()) ) {
            // .........
        }
LlamaLad7 commented 4 months ago

ModifyExpressionValue the getSeaLevel call, and if you want to force the comparison to false then return Integer.MAX_VALUE

Crystal0404 commented 4 months ago

thank

Garouelcazador commented 4 months ago

Although you could also use Float.NaN

Geolykt commented 4 months ago

Although you could also use Float.NaN

That is not the case. NaN cannot be represented as an integer and ModifyExpressionValue does not allow changing the datatype of a value (as instructions after the expression expect the datatype to be an integer still).

Garouelcazador commented 4 months ago

Although you could also use Float.NaN

That is not the case. NaN cannot be represented as an integer and ModifyExpressionValue does not allow changing the datatype of a value (as instructions after the expression expect the datatype to be an integer still).

I just checked and you are right both are values of type int, I assumed that the "getY()" method was of type float or double

Earthcomputer commented 4 months ago

Note that once MixinExtras gets its expression injection point, you will be able to simply target the whole expression directly, which should make situations like this easier