Posted November 30, 201410 yr Hello, I'm looking for a way to check, if player's current X(or any axis really) ends with .99 and then fire an event. My current code: double playerX = Math.floor(Minecraft.getMinecraft().thePlayer.posX); double playerY = Math.floor(Minecraft.getMinecraft().thePlayer.posY); double playerZ = Math.floor(Minecraft.getMinecraft().thePlayer.posZ); double playerYaw = Minecraft.getMinecraft().thePlayer.rotationYaw; if (String.format("%.2f", playerX) = endsWith(.99)); { LogHelper.info("true"); }
November 30, 201410 yr First: double playerX = Math.floor(Minecraft.getMinecraft().thePlayer.posX); The floor function maps a number to its largest preceeding integer (e.g. 29.99 -> 29.00), so you will have a value ending with .00. Second: if (coordinate > 0) { float v = coordinate - .99; if (x = (int) x) { // the player's positive coordinate ends with .99 } } else { float v = coordinate + .99; if (x = (int) x) { // the player's negative coordinate ends with .99 } } Note: if the coordinates have more than two digits after the decimal point, this code will mess up. If that is the case, be sure to truncate the floats.
November 30, 201410 yr Hi I think your sample code will work fine with a bit of tweaking double playerXfloor = Math.floor(Minecraft.getMinecraft().thePlayer.posX); double playerXremainder = Minecraft.getMinecraft().thePlayer.posX - playerXfloor; if (String.format("%.2f", playerXremainder ).contains(".99")); { LogHelper.info("true"); } For positive numbers, this will trigger for any numbers between x.985 and x.9949999999 For negative numbers, this will trigger at numbers ending in 0.01 instead of 0.99 Is that what you want? I'm with DieSieben though, are you sure that's really the effect you're looking for? -TGG
December 1, 201410 yr Author Uhm... that sounds like weird request. Why do you want to do that? The mod is supposed to help me do 4 block jumps since I have been getting worse at them
December 1, 201410 yr Author And... why do you need to check for ".99" then? To check if my coordinate ends with .99 and then jump to guarantee successful jump
December 2, 201410 yr Author Then I don't think you want to check "ends with .99". I think you want to check "first two decimal places are 99". Then it's all just maths: double absPos = Math.abs(player.posX); boolean endsWith99 = (int) ((absPos - (int) absPos) * 100) == 99; Alright, I had to make it check for just 9 and add booleans for 8 and 7, but it works and does exactly what I want. Thank you very much!
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.