Class WorldTimeResource

java.lang.Object
com.hypixel.hytale.server.core.modules.time.WorldTimeResource
All Implemented Interfaces:
Resource<EntityStore>, Cloneable

public class WorldTimeResource extends Object implements Resource<EntityStore>
An entity store resource that contains and processes the current world time.
  • Field Details

    • NANOS_PER_DAY

      public static final long NANOS_PER_DAY
    • SECONDS_PER_DAY

      public static final int SECONDS_PER_DAY
    • HOURS_PER_DAY

      public static final int HOURS_PER_DAY
    • DAYS_PER_YEAR

      public static final int DAYS_PER_YEAR
    • ZERO_YEAR

      public static final Instant ZERO_YEAR
    • MAX_TIME

      public static final Instant MAX_TIME
    • ZONE_OFFSET

      public static final ZoneOffset ZONE_OFFSET
    • SUN_HEIGHT

      public static final float SUN_HEIGHT
      See Also:
    • USE_SHADOW_MAPPING_SAFE_ANGLE

      public static final boolean USE_SHADOW_MAPPING_SAFE_ANGLE
      See Also:
    • DAYTIME_PORTION_PERCENTAGE

      public static final float DAYTIME_PORTION_PERCENTAGE
      See Also:
    • DAYTIME_SECONDS

      public static final int DAYTIME_SECONDS
    • NIGHTTIME_SECONDS

      public static final int NIGHTTIME_SECONDS
    • SUNRISE_SECONDS

      public static final int SUNRISE_SECONDS
    • SHADOW_MAPPING_SAFE_ANGLE_LERP

      public static final float SHADOW_MAPPING_SAFE_ANGLE_LERP
      The lerp amount used when applying the safe angle for shadow mapping
      See Also:
  • Constructor Details

    • WorldTimeResource

      public WorldTimeResource()
  • Method Details

    • getResourceType

      @Nonnull public static ResourceType<EntityStore, WorldTimeResource> getResourceType()
    • getSecondsPerTick

      public static double getSecondsPerTick(World world)
    • tick

      public void tick(float dt, @Nonnull Store<EntityStore> store)
      Called to tick and update the logic of this world time resource instance.
      Parameters:
      dt - The delta time of the current tick.
      store - The Store<EntityStore> for component access.
    • getMoonPhase

      public int getMoonPhase()
      Returns:
      the current moon phase of this world.
    • setMoonPhase

      public void setMoonPhase(int moonPhase, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to set the moon phase of the world.
      Parameters:
      moonPhase - The moon phase to set.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
    • updateMoonPhase

      public void updateMoonPhase(@Nonnull World world, @Nonnull ComponentAccessor<EntityStore> componentAccessor)
      Called to update the current moon phase of the world.
      Parameters:
      world - The provided world to update the moon phase for.
      componentAccessor - The ComponentAccessor<EntityStore> for component access.
    • isMoonPhaseWithinRange

      public boolean isMoonPhaseWithinRange(@Nonnull World world, int minMoonPhase, int maxMoonPhase)
      Determines whether the current moon phase is within the given range.
      Parameters:
      world - The world associated with this world time resource.
      minMoonPhase - The start of the moon phase range.
      maxMoonPhase - The end of the moon phase range.
      Returns:
      true if the phase is within the given range, false otherwise.
    • setGameTime0

      public void setGameTime0(@Nonnull Instant gameTime)
      Called to set the game time to the given instant
      Parameters:
      gameTime - The game time instant to set.
    • getGameTime

      public Instant getGameTime()
      Returns:
      the current game time instant of the world.
    • getGameDateTime

      public LocalDateTime getGameDateTime()
      Returns:
      the current game time, as a local date time, of the world.
    • getSunlightFactor

      public double getSunlightFactor()
      Returns:
      the current sunlight factor of the world.
    • setGameTime

      public void setGameTime(@Nonnull Instant gameTime, @Nonnull World world, @Nonnull ComponentAccessor<EntityStore> store)
      Called to set the current game time of the world.
      Parameters:
      gameTime - The game time instant to set.
      world - The world to set the game time of.
      store - The entity store associated with the world.
    • setDayTime

      public void setDayTime(double dayTime, @Nonnull World world, @Nonnull ComponentAccessor<EntityStore> store)
      Called to set the current day time of the world.
      Parameters:
      dayTime - The day time to be set.
      world - The world to set the day time of.
      store - The entity store associated with the world.
    • startDayTimeInterpolation

      public void startDayTimeInterpolation(double targetDayProgress, double durationSeconds, boolean forward, boolean pauseOnComplete, @Nonnull World world, @Nonnull ComponentAccessor<EntityStore> store)
      Begins interpolating the game time from its current value to targetDayProgress (0.0-1.0, where 0.5 is noon) over durationSeconds of real time, advanced each tick(float, Store). A duration of 0 or less applies the target instantly. forward chooses the direction the time sweeps to reach the target, so a transition can run e.g. 13:00 -> 06:00 backward rather than the long way around. When pauseOnComplete is set, time is paused once the target is reached. Unlike setDayTime(double, World, ComponentAccessor), this does not force forward-only movement.
    • isInterpolating

      public boolean isInterpolating()
      Returns:
      whether a day-time interpolation is currently in progress.
    • cancelInterpolation

      public void cancelInterpolation()
      Cancels any in-progress day-time interpolation, leaving the time at its current value.
    • broadcastTimePacket

      public void broadcastTimePacket(@Nonnull ComponentAccessor<EntityStore> store)
      Broadcasts the current time data to all players within the given entity store.
      Parameters:
      store - The entity store to broadcast the time data to each player of.
    • sendTimePackets

      public void sendTimePackets(@Nonnull PlayerRef playerRef)
      Sends the current time settings and packet to the given player.
      Parameters:
      playerRef - The PlayerRef component of the player to send the data to.
    • isDayTimeWithinRange

      public boolean isDayTimeWithinRange(double minTime, double maxTime)
      Determines if world time is between start and end time. The start and end time need to be between [0, 1]: (time in hours / 24f)
      Parameters:
      minTime - The start of the time range.
      maxTime - The end of the time range.
      Returns:
      true if the current day time is within the provided range, false otherwise.
    • updateTimePacket

      public void updateTimePacket(@Nonnull UpdateTime currentTimePacket)
      Called to update the UpdateTime packet with the latest game time data.
      Parameters:
      currentTimePacket - The UpdateTime packet to populate.
    • updateTimeSettingsPacket

      @Nonnull public static UpdateTimeSettings updateTimeSettingsPacket(@Nonnull UpdateTimeSettings settings, @Nonnull World world)
      Called to update and return the current UpdateTimeSettings packet with the latest gameplay config information.
      Parameters:
      settings - The UpdateTimeSettings packet to populate.
      world - The world to read the time configuration from.
      Returns:
      the updated UpdateTimeSettings packet.
    • isScaledDayTimeWithinRange

      public boolean isScaledDayTimeWithinRange(double minTime, double maxTime)
      Determines if world time scaled relative to daylight portion is within the interval. 0 - 6 represents the hours between midnight and sunrise. 6 - 12 represents the hours between sunrise and midday. 12 - 18 represents the hours between midday and sunset. 18 - 24 represents the hours between sunset and midnight. These values are normalised for minTime and maxTime to be between 0 and 1.
      Parameters:
      minTime - The start of the time range.
      maxTime - The end of the time range.
      Returns:
      true if the scaled day time is within the given range, false otherwise.
    • isYearWithinRange

      public boolean isYearWithinRange(double minTime, double maxTime)
      Determines whether the current year progress of the game time is within the given range.
      Parameters:
      minTime - The start of the time range.
      maxTime - The end of the time range.
      Returns:
      true if the year is within the given range, false otherwise.
    • getCurrentHour

      public int getCurrentHour()
      Returns:
      the current hour of the world time.
    • getDayProgress

      public float getDayProgress()
      Returns:
      the current day progress of the world time.
    • dayProgressToInstant

      @Nonnull public Instant dayProgressToInstant(double dayProgress)
      Resolves the absolute Instant for the given day progress (0.0-1.0) within the current day, without mutating world time. Useful for a per-client time override that shows a specific time of day.
    • getSunDirection

      @Nonnull public org.joml.Vector3d getSunDirection()
      Called to calculate and fetch the sun direction based on the time of the given world.
      Returns:
      the Vector3d instance representing the sun direction.
    • instantToInstantData

      @Nonnull public static InstantData instantToInstantData(@Nonnull Instant instant)
      Called to convert and fetch the InstantData of the provided Instant instance.
      Parameters:
      instant - The Instant instance to convert into an InstantData instance.
      Returns:
      the converted InstantData instance.
    • instantDataToInstant

      @Nonnull public static Instant instantDataToInstant(@Nonnull InstantData instantData)
      Called to convert and fetch the Instant of the provided InstantData instance.
      Parameters:
      instantData - The InstantData instance to convert into an Instant instance.
      Returns:
      the converted Instant instance.
    • clone

      @Nonnull public Resource<EntityStore> clone()
      Specified by:
      clone in interface Resource<EntityStore>
      Returns:
      a clone instance of the original resource instance.

    • toString

      @Nonnull public String toString()
      Overrides:
      toString in class Object