World Time
Package: com.hypixel.hytale.server.core.modules.time
World time uses java.time.Instant for high-precision game time tracking. See also Weather for the per-world weather system, which updates hourly based on game time.
Accessing Time
Section titled “Accessing Time”// get time resourceStore<EntityStore> store = world.getEntityStore().getStore();WorldTimeResource timeResource = store.getResource(WorldTimeResource.getResourceType());
// current game timeInstant gameTime = timeResource.getGameTime();LocalDateTime dateTime = timeResource.getGameDateTime();
// current hour (0-23)int hour = timeResource.getCurrentHour();
// day progress (0.0 to 1.0)float dayProgress = timeResource.getDayProgress();
// sunlight factor (0.0 to 1.0, affected by time of day)double sunlight = timeResource.getSunlightFactor();
// moon phase (0 to totalMoonPhases-1)int moonPhase = timeResource.getMoonPhase();Setting Time
Section titled “Setting Time”// set absolute timetimeResource.setGameTime(Instant.parse("0001-06-15T12:00:00Z"), world, store);
// set time of day (0.0 = midnight, 0.5 = noon, 1.0 = next midnight)timeResource.setDayTime(0.5, world, store); // noonTime Ranges
Section titled “Time Ranges”// check if current time is within range (0.0 to 1.0 scale)boolean isDaytime = timeResource.isDayTimeWithinRange(0.25, 0.75);
// check moon phase rangeboolean isFullMoon = timeResource.isMoonPhaseWithinRange(world, 3, 3);Pausing Time
Section titled “Pausing Time”WorldConfig config = world.getWorldConfig();config.setGameTimePaused(true);config.markChanged();Day/Night Duration
Section titled “Day/Night Duration”Default is 50% daytime, 50% nighttime (1728 seconds each). Configure via GameplayConfig or per-world override:
// get configured durationsint daytimeSeconds = world.getDaytimeDurationSeconds();int nighttimeSeconds = world.getNighttimeDurationSeconds();Example: Time-Based Spawning
Section titled “Example: Time-Based Spawning”public class DaylightSpawnPlugin extends JavaPlugin {
@Override protected void setup() { getEventRegistry().registerGlobal(ChunkPreLoadProcessEvent.class, this::onChunkLoad); }
private void onChunkLoad(ChunkPreLoadProcessEvent event) { if (!event.isNewlyGenerated()) return;
World world = event.getChunk().getWorld(); Store<EntityStore> store = world.getEntityStore().getStore(); WorldTimeResource time = store.getResource(WorldTimeResource.getResourceType());
// only spawn during daytime if (time.isDayTimeWithinRange(0.25, 0.75)) { spawnDaytimeCreatures(event.getChunk()); } }}