Run the world clock so day and night happen
set_time was declared nowhere and sent never, so the client's sky was frozen wherever it started: the sun did not move, night did not fall, and nothing in the world had a time. 26.1.2 replaced the old (gameTime, dayTime, doDaylightCycle) triple with a registry of named clocks. The packet now carries a fixed-width game time plus a map from world clock to (totalTicks, partialTick, rate); the client advances each clock locally at its rate and drives the minecraft:day timeline -- a keyframe track over a 24000-tick period -- from the overworld clock. The clock registry is already among the 28 we sync, so the id is looked up rather than hardcoded and the server refuses to start if it is missing. The counter rides the entity tick loop because that is the only loop already running at 20 TPS. It belongs on the single authoritative tick the engine still needs; putting a sixth ticker beside the five that exist would make that worse. Broadcast every second, which is what vanilla does -- the client interpolates in between, so the resend only corrects drift. The clock also persists now. The world metadata file was written once and never touched again; it is atomically rewritable, carries gameTime and dayTime, and a file written before those fields existed still opens and resumes at dawn as it did. Saved every 30 seconds alongside the chunk autosave, and once more on shutdown after the final flush.
This commit is contained in:
parent
4db7638377
commit
57214fbd76
9 changed files with 386 additions and 15 deletions
|
|
@ -70,6 +70,8 @@ type Server struct {
|
|||
players map[[16]byte]*PlayerSession
|
||||
playerNames map[string][16]byte
|
||||
nextPlayerID int32
|
||||
|
||||
clock worldClock
|
||||
}
|
||||
|
||||
// PacketSender is the connection capability retained by the session registry.
|
||||
|
|
@ -155,10 +157,26 @@ func validateConfig(cfg Config) error {
|
|||
}
|
||||
|
||||
func newServerState(cfg Config, chunks *world.Cache, store *world.Store, entities *world.EntityManager) *Server {
|
||||
return &Server{
|
||||
s := &Server{
|
||||
cfg: cfg, chunks: chunks, store: store, entities: entities,
|
||||
players: make(map[[16]byte]*PlayerSession), playerNames: make(map[string][16]byte),
|
||||
}
|
||||
// Resume the world clock where it was saved, so a restart does not throw
|
||||
// the sky back to dawn.
|
||||
if store != nil {
|
||||
gameTime, dayTime := store.WorldTime()
|
||||
s.SetWorldTime(gameTime, dayTime)
|
||||
}
|
||||
return s
|
||||
}
|
||||
|
||||
// SaveWorldTime persists the current clock. It is a no-op without a store.
|
||||
func (s *Server) SaveWorldTime() error {
|
||||
if s.store == nil {
|
||||
return nil
|
||||
}
|
||||
gameTime, dayTime := s.WorldTime()
|
||||
return s.store.SaveWorldTime(gameTime, dayTime)
|
||||
}
|
||||
|
||||
// Config returns the active configuration.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue