Set time to start of day? + SleepingEvent

Hello, I am trying to set the time of a world in Sponge. I found the setWorldTime() in the WorldProperties object, but the JavaDocs say that that value is the total world time and doesn’t reset to 0. Is it ok if I set it to 0 or is there an alternate method to set the time to the start of the day?

The WorldProperties represents the storage properties of the world. IE, information about the world, such as how long it’s been running (world time).

Yes, manipulating the world time is possible. I’m not entirely certain if this would affect the time of the day, however.

If it would, for the sake of statistics, I would recommend pretending that setting the world time would be akin to moving forward in time, rather than resetting it. For instance, take the current time, figure out how many days it’s been, and move forward from there.

public void setTicksToMorningRelativeToDaysAlive(WorldProperties properties) {
    final long alive = properties.getWorldTime();
    final double days = alive / 24000;
    final long setTo = ((int) Math.ceil(days)) * 24000;
    properties.setWorldTime(setTo);
}

EDIT: Of course, you could easily make that a one-liner - I was just attempting to show what exactly is being done, and why.

public void setTicksToMorningRelativeToDaysAlive(WorldProperties properties) {
    properties.setWorldTime(((int) Math.ceil(properties.getWorldTime() / 24000)) * 24000);
}

Thanks! I’ll test it out!

Also, I have another (somewhat) related question: Is the SleepingEvent implemented yet? From what I can see, it’s not but I just want to verify that it isn’t implemented.

Personally, I keep this bookmarked.

That’s helpful, thanks!