Interface MinecraftDayTime


  • public interface MinecraftDayTime
    Represents an in-game time of day.
    • Method Detail

      • ofInGameDuration

        static MinecraftDayTime ofInGameDuration​(Engine engine,
                                                 java.time.Duration duration)
        Creates a MinecraftDayTime based on the in-game time since the Minecraft epoch (6:00am on Day 1) for the given Engine.

        For example, if the supplied Duration was 1 day, 3 hours and 40 minutes, this would correspond to an in game time of 9:40am on Day 2.

        In the case where the supplied Duration does not completely align with a valid MinecraftDayTime, the nearest valid time will be returned.

        Parameters:
        engine - The Engine to use in calculating the day time
        duration - The duration since the Minecraft Epoch.
        Returns:
        The MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if the duration is negative
      • ofWallClockDuration

        static MinecraftDayTime ofWallClockDuration​(Engine engine,
                                                    java.time.Duration duration)
        Creates a MinecraftDayTime that represents the world time if the world has been running for the supplied Duration in real world time under idealised conditions for the given Engine.

        For example, if the supplied Duration was 1 day, 3 hours and 40 minutes and each Minecraft day lasts 20 minutes in the vanilla game, this would correspond to 6:00am on day 84 (1 day, 3 hours and 40 minutes is 1660 minutes, which is 83 20-minute chunks).

        In the case where the supplied Duration does not completely align with a valid MinecraftDayTime, the nearest valid time will be returned.

        Parameters:
        engine - The Engine to use in calculating the day time
        duration - The wall-clock duration
        Returns:
        The MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if the duration is negative
      • of

        static MinecraftDayTime of​(int day,
                                   int hours,
                                   int minutes)
        Creates a MinecraftDayTime that corresponds to the given units of in-game time.

        The parameters are subject to the following constraints:

        • day must be positive;
        • hours is in 24-hour time, and so must be between 0 and 23, except on day 1, where it must be between 6 and 23; and
        • minutes must be between 0 and 59.

        In the case where the supplied time does not completely align with a valid MinecraftDayTime, the nearest valid time will be returned.

        Parameters:
        day - The day to set. Must be positive.
        hours - The hour to set in 24 hour time.
        minutes - The minute to set.
        Returns:
        The MinecraftDayTime.
        Throws:
        java.lang.IllegalArgumentException - if any of the listed constraints are violated.
      • of

        static MinecraftDayTime of​(Engine engine,
                                   Ticks ticks)
        Creates a MinecraftDayTime based on the number of Ticks elapsed since the Minecraft epoch (6:00am on Day 1) for the given Engine.

        For example, if the supplied Ticks was Ticks.of(18000) on the vanilla server, this would correspond to an in game time of 12:00am on Day 2 (18 hours after Minecraft epoch).

        Parameters:
        engine - The Engine to calculate the time for.
        ticks - The Ticks since the Minecraft Epoch.
        Returns:
        The MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if the tick count is negative
      • day

        int day()
        The day this represents.
        Returns:
        The day
      • hour

        int hour()
        The hour this represents.
        Returns:
        The hour.
      • minute

        int minute()
        The minute this represents.
        Returns:
        The minute.
      • add

        MinecraftDayTime add​(int days,
                             int hour,
                             int minute)
        Adds the time given by the arguments and returns a new object with the result.
        Parameters:
        days - The number of days to advance
        hour - The number of hours to advance (between 0 and 23)
        minute - The number of minutes to advance (between 0 and 59)
        Returns:
        A new MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments are negative.
      • subtract

        MinecraftDayTime subtract​(Ticks ticks)
        Subtracts the time given by the provided Ticks object and returns a new object with the result.
        Parameters:
        ticks - The Ticks to subtract.
        Returns:
        A new MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if the result would be a negative time.
      • subtract

        MinecraftDayTime subtract​(int days,
                                  int hour,
                                  int minute)
        Subtracts the time given by the arguments and returns a new object with the result.
        Parameters:
        days - The number of days to advance
        hour - The number of hours to advance (between 0 and 23)
        minute - The number of minutes to advance (between 0 and 59)
        Returns:
        A new MinecraftDayTime
        Throws:
        java.lang.IllegalArgumentException - if any of the arguments are negative or the result would be a negative time.
      • asInGameDuration

        java.time.Duration asInGameDuration()
        Returns a Duration that represents in-game time from the minecraft epoch (so, for Day 2 at 12:30pm will return a duration of 1 day, 6 hours and 30 minutes).
        Returns:
        A Duration
      • asWallClockDuration

        default java.time.Duration asWallClockDuration​(Engine engine)
        Returns a Duration that represents wall-clock time from the minecraft epoch for the given Engine. (For example, if this object represents Day 2 at 12:30pm, will return a Duration of 25 minutes and 25 seconds for a vanilla minecraft Server).
        Parameters:
        engine - The Engine to calculate the time for.
        Returns:
        A Duration
      • asTicks

        Ticks asTicks()
        Returns the number of Ticks that have elapsed since the minecraft epoch.
        Returns:
        The epoch.