Jump to content

Recommended Posts

Posted

Is there a way to detect if another day has started? A new day?

 

World#getTotalWorldTime returns the total time passed in a certain world. Dividing that number by 24000 should return the number of days that have passed in a certain world. If you want the number of whole days, just round the quotient down. Keep in mind, however, that this number gets incremented even if 'gamerule doDaylightCycle' is set to false (which doesn't really make sense if you ask me).

 

-EDIT:

 

Actually thinking about it, don't do that if you only want to do something if a day has just started. If you only want to do something only when a new day starts, just check if World#getWorldTime equals 0.

Posted

Actually,

world#getWorldTime()

is not %24000, TheMasterGabriel is incorrect about that (or rather, his assumption based off a particular piece of lying Javadoc).  If you trace its usage you will find that it is not moduloed anywhere in the code, and in fact is used to track the current world time (cough, as expected, cough) and (IIRC) is used to calculate the current moon phase.

 

World#getTotalWorldTime()

on the other hand, returns the realtime the world has existed, meaning that if you sleep, the timer is not incremented respective to

world#getWorldTime()

.

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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

Posted

Actually,

world#getWorldTime()

is not %24000, TheMasterGabriel is incorrect about that (or rather, his assumption based off a particular piece of lying Javadoc).  If you trace its usage you will find that it is not moduloed anywhere in the code, and in fact is used to track the current world time (cough, as expected, cough) and (IIRC) is used to calculate the current moon phase.

 

World#getTotalWorldTime()

on the other hand, returns the realtime the world has existed, meaning that if you sleep, the timer is not incremented respective to [ttworld#getWorldTime()[/code].

 

My mistake, pesky lying javadoc. However, the procedure for checking if it's a new day is pretty much exactly the same. Instead of checking if World#getWorldTime() is equal to 0, check if World#getWorldTime() % 24000 is equal to 0. I pulled that straight from CommandTime#execute (which they actually updated it to incorporate a modulo operation in 1.9, Draco), so check that method if you want to know how to calculate other time stuff (like days and the age of the world). Using this method, however, will cause whatever you are planning on doing to fire as soon as the world first loads (which makes sense, because that's how maths work). So assuming you don't want it to fire immediately (which I'm guessing you don't), you should probably do another check to make sure that World#getWorldTime() does not equal 0 (which would be at dawn on the very first day).

Posted

Or check

% 23999

.

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.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

Announcements



×
×
  • Create New...

Important Information

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