Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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");
        }

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.

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

 

 

  • 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

  • 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 ;)

  • 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.