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

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.

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.

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

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

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.