# Where is the time the last tick took, avg tick took etc.?

## Recommended Posts

So I added a variable timestep to my physics simulation, and I want to make the speed things move independent of server lag by changing the speed from 1/20 to how many ticks happened in the last second. Where does Minecraft keep these things?

"you seem to be THE best modder I've seen imo."

~spynathan

ლ(́◉◞౪◟◉‵ლ

##### Share on other sites

I've played with this before and like diesieben07 mentions it usually doesn't result in what you think -- you can fairly easily make the physics honor real time (I'll explain how below), but when everything else in the game is lagging it is really weird when the physics works real time. Basically it is just much more playable when everything lags together.

But, if you want to play around with it, you can use Java's System.nanoTime field to measure the time each tick is taking and adjust accordingly. Basically, you need a field to hold the result of System.nanoTime from the previous tick, and you need a field for the time for current tick. You can update these in the tick events (probably the client tick and server tick events) where you copy current time to the previous time, then update the current time from System.nanoTime.

Then you just need to compare what the tick took relative to what it should be. There is supposed to be 20 ticks per second so each tick should be 0.05 seconds = 50 miliseconds = 50,000 nanoseconds. So to adjust things for this lag, you would use a scaling factor of (currentTime - previousTime) / 50000.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

##### Share on other sites

Of course, I just record the system time the last time i ran the tick, and subtract the current time.

Better than rummaging through MC code anyway.

"you seem to be THE best modder I've seen imo."

~spynathan

ლ(́◉◞౪◟◉‵ლ

##### Share on other sites

Then you just need to compare what the tick took relative to what it should be. There is supposed to be 20 ticks per second so each tick should be 0.05 seconds = 50 miliseconds = 50,000 nanoseconds. So to adjust things for this lag, you would use a scaling factor of (currentTime - previousTime) / 50000.

Its not 50,000 nanos.  It's 50,000,000.  Mili, micro, nano.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

DO NOT PM ME WITH PROBLEMS. No help will be given.

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

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

• ### Posts

• my game keeps crashing with the error message: The game crashed whilst rendering overlay Error: java.lang.ExceptionInInitializerError: null Exit code:-1 I would greatly appreciate some help      https://pastebin.com/iYSaXcJK crash report here
• [main/FATAL] [mixin/]: Mixin apply for mod reach_entity_attributes failed reach_entity_attributes is part of it, mentioned in the mod list:   ... - connectorextras 1.11.2+1.20.1 |-- amecsapi 1.5.3+mc1.20-pre1 |-- connectorextras_architectury_bridge 1.11.2+1.20.1 |-- connectorextras_emi_bridge 1.11.2+1.20.1 |-- connectorextras_energy_bridge 1.11.2+1.20.1 |-- connectorextras_geckolib_fabric_compat 1.11.2+1.20.1 |-- connectorextras_jei_bridge 1.11.2+1.20.1 |-- connectorextras_kubejs_bridge 1.11.2+1.20.1 |-- connectorextras_modmenu_bridge 1.11.2+1.20.1 \-- modmenu 7.2.2 |-- connectorextras_pehkui_bridge 1.11.2+1.20.1 |-- connectorextras_rei_bridge 1.11.2+1.20.1 |-- connectorextras_terrablender_bridge 1.11.2+1.20.1 |-- forgeconfigapiport 8.0.0 \-- reach_entity_attributes 2.4.0 ...
• yes it does, tysm. where'd you find the mod being mentioned in the log?

• ### Who's Online (See full list)

×

• #### Activity

×
• Create New...