Skip to content

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.

// get time resource
Store<EntityStore> store = world.getEntityStore().getStore();
WorldTimeResource timeResource = store.getResource(WorldTimeResource.getResourceType());
// current game time
Instant 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();
// set absolute time
timeResource.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); // noon
// check if current time is within range (0.0 to 1.0 scale)
boolean isDaytime = timeResource.isDayTimeWithinRange(0.25, 0.75);
// check moon phase range
boolean isFullMoon = timeResource.isMoonPhaseWithinRange(world, 3, 3);
WorldConfig config = world.getWorldConfig();
config.setGameTimePaused(true);
config.markChanged();

Default is 50% daytime, 50% nighttime (1728 seconds each). Configure via GameplayConfig or per-world override:

// get configured durations
int daytimeSeconds = world.getDaytimeDurationSeconds();
int nighttimeSeconds = world.getNighttimeDurationSeconds();

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());
}
}
}