Interface DayNightCycle


public interface DayNightCycle
The clock of a world: its age, its time of day and how fast time flows.

Time is counted in ticks; a full day lasts 24000 ticks, the day starting at sunrise (0). Times of day are the time modulo 24000.

Since:
0.1.0
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
    The length of a full day, in ticks.
    static final int
    The time of day of midnight.
    static final int
    The number of moon phases, one per day.
    static final int
    The time of day night falls.
    static final int
    The time of day of noon.
    static final int
    The last time of day players may sleep, inclusive.
    static final int
    The first time of day players may sleep, inclusive.
    static final int
    The time of day the sun starts rising.
    static final int
    The time of day the sun is fully risen, and the day starts.
    static final int
    The time of day the sun starts setting.
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addTime(long ticks)
    Moves the time forward, or backward with a negative value.
    default boolean
    Returns true when the time of day allows players to sleep.
    default double
    Returns the angle of the sun in the sky, as a fraction of a full turn.
    Returns the key of the minecraft:world_clock driving this cycle.
    default long
    day()
    Returns the number of full days elapsed.
    boolean
    Returns true while the time advances on its own.
    float
    Returns the fraction of tick accumulated when the rate is not a whole number.
    default boolean
    Returns true during DayPhase.DAY.
    default boolean
    Returns true during DayPhase.NIGHT.
    default int
    Returns the moon phase, from 0 (full moon) to MOON_PHASES - 1.
    default DayPhase
    Returns the part of the day the current time falls in.
    float
    Returns the number of ticks the time advances by per server tick, 1 by default.
    void
    setDoDaylightCycle(boolean enabled)
    Freezes or resumes the time.
    void
    setRate(float rate)
    Sets how fast time flows.
    void
    setTime(long time)
    Sets the total time and resynchronizes the clients.
    default double
    Returns the angle of the sun in the sky, in degrees.
    default long
    ticksUntil(int targetTimeOfDay)
    Returns the number of ticks until the given time of day comes next, from 1 to DAY_LENGTH.
    long
    Returns the total time, in ticks; it only advances while the cycle runs.
    default int
    Returns the time of day, from 0 to DAY_LENGTH - 1.
    long
    Returns the number of ticks this world has existed, whatever the cycle does.
  • Field Details

    • DAY_LENGTH

      static final int DAY_LENGTH
      The length of a full day, in ticks.
      Since:
      0.1.0
      See Also:
    • SUNRISE_END

      static final int SUNRISE_END
      The time of day the sun is fully risen, and the day starts.
      Since:
      0.1.0
      See Also:
    • NOON

      static final int NOON
      The time of day of noon.
      Since:
      0.1.0
      See Also:
    • SUNSET

      static final int SUNSET
      The time of day the sun starts setting.
      Since:
      0.1.0
      See Also:
    • NIGHT_START

      static final int NIGHT_START
      The time of day night falls.
      Since:
      0.1.0
      See Also:
    • MIDNIGHT

      static final int MIDNIGHT
      The time of day of midnight.
      Since:
      0.1.0
      See Also:
    • SUNRISE

      static final int SUNRISE
      The time of day the sun starts rising.
      Since:
      0.1.0
      See Also:
    • SLEEP_START

      static final int SLEEP_START
      The first time of day players may sleep, inclusive.
      Since:
      0.1.0
      See Also:
    • SLEEP_END

      static final int SLEEP_END
      The last time of day players may sleep, inclusive.
      Since:
      0.1.0
      See Also:
    • MOON_PHASES

      static final int MOON_PHASES
      The number of moon phases, one per day.
      Since:
      0.1.0
      See Also:
  • Method Details

    • clock

      Key clock()
      Returns the key of the minecraft:world_clock driving this cycle.
      Returns:
      the key of the minecraft:world_clock driving this cycle
      Since:
      0.1.0
    • worldAge

      long worldAge()
      Returns the number of ticks this world has existed, whatever the cycle does.
      Returns:
      the number of ticks this world has existed, whatever the cycle does
      Since:
      0.1.0
    • time

      long time()
      Returns the total time, in ticks; it only advances while the cycle runs.
      Returns:
      the total time, in ticks; it only advances while the cycle runs
      Since:
      0.1.0
    • setTime

      void setTime(long time)
      Sets the total time and resynchronizes the clients.
      Parameters:
      time - the new total time, in ticks
      Since:
      0.1.0
    • addTime

      default void addTime(long ticks)
      Moves the time forward, or backward with a negative value.
      Parameters:
      ticks - the number of ticks to add
      Since:
      0.1.0
    • fractionalTime

      float fractionalTime()
      Returns the fraction of tick accumulated when the rate is not a whole number.
      Returns:
      the fraction of tick accumulated when the rate is not a whole number
      Since:
      0.1.0
    • rate

      float rate()
      Returns the number of ticks the time advances by per server tick, 1 by default.
      Returns:
      the number of ticks the time advances by per server tick, 1 by default
      Since:
      0.1.0
    • setRate

      void setRate(float rate)
      Sets how fast time flows.
      Parameters:
      rate - the number of ticks per server tick; negative values are treated as 0
      Since:
      0.1.0
    • doDaylightCycle

      boolean doDaylightCycle()
      Returns true while the time advances on its own.
      Returns:
      true while the time advances on its own
      Since:
      0.1.0
    • setDoDaylightCycle

      void setDoDaylightCycle(boolean enabled)
      Freezes or resumes the time.
      Parameters:
      enabled - false to freeze the time
      Since:
      0.1.0
    • timeOfDay

      default int timeOfDay()
      Returns the time of day, from 0 to DAY_LENGTH - 1.
      Returns:
      the time of day, from 0 to DAY_LENGTH - 1
      Since:
      0.1.0
    • day

      default long day()
      Returns the number of full days elapsed.
      Returns:
      the number of full days elapsed
      Since:
      0.1.0
    • moonPhase

      default int moonPhase()
      Returns the moon phase, from 0 (full moon) to MOON_PHASES - 1.
      Returns:
      the moon phase, from 0 (full moon) to MOON_PHASES - 1
      Since:
      0.1.0
    • phase

      default DayPhase phase()
      Returns the part of the day the current time falls in.
      Returns:
      the part of the day the current time falls in
      Since:
      0.1.0
    • isDay

      default boolean isDay()
      Returns true during DayPhase.DAY.
      Returns:
      true during DayPhase.DAY
      Since:
      0.1.0
    • isNight

      default boolean isNight()
      Returns true during DayPhase.NIGHT.
      Returns:
      true during DayPhase.NIGHT
      Since:
      0.1.0
    • canSleep

      default boolean canSleep()
      Returns true when the time of day allows players to sleep.
      Returns:
      true when the time of day allows players to sleep
      Since:
      0.1.0
    • ticksUntil

      default long ticksUntil(int targetTimeOfDay)
      Returns the number of ticks until the given time of day comes next, from 1 to DAY_LENGTH.
      Parameters:
      targetTimeOfDay - the time of day to wait for
      Returns:
      the number of ticks until the given time of day comes next, from 1 to DAY_LENGTH
      Since:
      0.1.0
    • skyAngleDegrees

      default double skyAngleDegrees()
      Returns the angle of the sun in the sky, in degrees.
      Returns:
      the angle of the sun in the sky, in degrees
      Since:
      0.1.0
    • celestialAngle

      default double celestialAngle()
      Returns the angle of the sun in the sky, as a fraction of a full turn.
      Returns:
      the angle of the sun in the sky, as a fraction of a full turn
      Since:
      0.1.0