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

How could I get the player movement speed in my mod in km/h. I want to display it in a GUI in the bottom right-hand corner (which I know how to do). Any ideas?

  • 3 weeks later...

If you still are thinking about this, then I would suggest you store players position in variable

 

then on specifid tick you calculate the distance the player traveled since the last "readout".

 

lets say the tick is every second then this pseudo code should be right.

 

//calculate distance since last reading
diffx = player.x - prev_posx
diffy = player.y - prev_posy
diffz = player.z - prev_posz

//calculate overall distance
distance = sqrt( diffx + diffy + diffz)

//calculate speed
// speed = distance * 60 *60 /1000
speed_in_km_h = distance*3,6

// store player position for next time
prev_posx = player.x
prev_posy = player.y
prev_posz = player.z

Not all things in the world are red, there are round objects too!

Another way to get the distance (in a perhaps more cleaner way) could be like this:

Vec3 lastPosVec = new Vec3(prev_posx, prev_posy, prev_posz);
Vec3 currentPosVec = new Vec3(player.x, player.y, player.z);

// Euclidean distance between your last and current position. 
double distanceTraveled = lastPosVec.distanceTo(currentPosVec);

 

As for handling the gui, I am afraid I cannot be of any help there as I have no experience in that.

If you haven't so far, you should perhaps read this:

http://www.minecraftforge.net/wiki/Gui_Overlay

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

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.