SpongeAPI icon indicating copy to clipboard operation
SpongeAPI copied to clipboard

Time/DayCycle/MoonPhase API

Open ryantheleach opened this issue 10 years ago • 12 comments
trafficstars

The API should expose a way to get and set the current time in the world.

Kobata pointed out that modded worlds may not even have a day night cycle, or have modified cycles and that the API docs should reflect that.

So I went through all the methods in World and WorldProvider and compiled a list of what may in some form prove useful in an API (noting that they are currently raw from minecraft and may be somewhat implementation specific)

getTotalTime get's the total time that the world has been loaded for, I would recommend not providing a setter for this in the API due to the amount of things that rely on this value unless someone can provide a good usecase.

getWorldTime setWorldTime would allow setting the current time of the world, much like the vanilla /time command, however it relies upon hardcoding known values for day and night which may vary for mod provided worlds.

isDaytime is a relatively easy check to include in the API, but provides no support for knowing if a future time is day/night.

calculateSkylightSubtracted and others provides a method for seeing how much darker the world gets at a given time of day.

getCurrentDate provides a calendar for working out how many minecraft days have passed in game, I'm not familar enough with Calendars to evaluate whether exposing this or a copy of a calendar is a bad idea.

getMoonPhase allows you to get a int containing the index of the moonPhaseFactor which affects slime spawns, and the local difficulty.

World
public boolean isDaytime()
public int calculateSkylightSubtracted(float time)
public float getSunBrightnessFactor(float time)
public float getCurrentMoonPhaseFactor()
public float getCelestialAngle(float time)
public float getCurrentMoonPhaseFactor()
public float getCelestialAngleRadians(float time)
public long getTotalWorldTime()
public long getWorldTime()
public void setWorldTime()
public Calendar getCurrentDate()
public int getSkylightSubtracted()
public void setSkylightSubtracted(int newSkylightSubtracted)

WorldProvider
public int getMoonPhase(long time)
public boolean getHasNoSky()
public float[] getLightBrightnessTable()
--moved from world--
public boolean isDaytime()
public float getSunBrightnessFactor(float time)
public float getCurrentMoonPhaseFactor()
public void setWorldTime(long time)
public long getWorldTime()

Any thoughts on what would be worth exposing, or what needs to be abstracted?

ryantheleach avatar Jan 17 '15 15:01 ryantheleach

What is totally worth exposing: world tick time, which IS available even with the doDaylightCycle = false gamerule. This is the only thing I can see needing direct exposure, other stuff would be cool.

octylFractal avatar Jan 17 '15 15:01 octylFractal

Also the Calender API sucks, and should be either wrapped in an immutable object or not exposed.

octylFractal avatar Jan 17 '15 15:01 octylFractal

I think this stuff would be nice to expose all of this, some of these things are really useful and most are rarely fully exposed.

Lunaphied avatar Jan 17 '15 16:01 Lunaphied

I'm interested in seeing a Calendar API, however, we should note that it is likely that some forge mods, such as Mystcraft add multiple celestial bodies which interweave with this API.

gabizou avatar Jan 18 '15 04:01 gabizou

Not sure if this is what you guys are looking for, or are talking about…

https://github.com/CallMeFoxie/Calendar

PitchBright avatar Jan 30 '16 00:01 PitchBright

I'd also like to see the time that players wake up at exposed in some form.

https://forums.spongepowered.org/t/bed-plugin/12600

ryantheleach avatar May 03 '16 18:05 ryantheleach

I'm a bit disappointed that after two years of this issue being opened that no progress at all has been made to add this to the api. Instead many things have been completely rewritten and a lot of other things I won't mention.

MattBDev avatar Dec 14 '16 03:12 MattBDev

@MattBDev If you want it then go open a PR, otherwise I guess you'll just have to wait for someone else to spend the time on it or there to be few enough higher priority issues for someone on the core team to get to it. Complaining about it doesn't do shit and you can take that attitude elsewhere.

Deamon5550 avatar Dec 14 '16 03:12 Deamon5550

I almost opened an issue that a duplicate of a duplicate of this, so I'll just post what I was going to post there

-- start of post -- Personal Player Time/Weather : I'd like to propose personal player times, mainly for the convenience factor. I'd rather not have mixins providing this feature multiple times and have it in the API. This would be useful for personal player preferences like, for example, some players prefer not to ever have rain. Or it could be used in plugins to have custom regions with no sunlight, etc... -- end of post --

I'll take a crack at this issue when I can (it's on my bookmarks list of things to do, after kittycannons :P )

Maxqia avatar Dec 16 '16 05:12 Maxqia

BTW, while going through your method list (implementing it), I noticed that getCurrentMoonPhaseFactor is listed twice :P

Maxqia avatar Dec 27 '16 09:12 Maxqia

So the time methods are exposed in WorldProperties.

Other than that I can see adding the moon phases being important, I might work on that soon. As well as the daytime and hasSkylight methods in some fashion.

The sun brightness and light brightness methods are a bit stranger and I'll look into those separately.

parlough avatar Aug 17 '17 05:08 parlough

Hopefully this can be added to API 9.

MattBDev avatar Jan 26 '22 00:01 MattBDev