Skip to content

Commit 8da361b

Browse files
committed
requested
1 parent cab859e commit 8da361b

File tree

4 files changed

+19
-8
lines changed

4 files changed

+19
-8
lines changed

server/session/world.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,12 @@ func entityOffset(e world.Entity) mgl64.Vec3 {
227227
}
228228

229229
// ViewTime ...
230-
func (s *Session) ViewTime(time int, doDayLightCycle bool) {
230+
func (s *Session) ViewTime(time int) {
231231
s.writePacket(&packet.SetTime{Time: int32(time)})
232+
}
233+
234+
// ViewTimeCycle ...
235+
func (s *Session) ViewTimeCycle(doDayLightCycle bool) {
232236
s.sendGameRules([]protocol.GameRule{{Name: "dodaylightcycle", Value: doDayLightCycle}})
233237
}
234238

server/world/tick.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ func (t ticker) tick(tx *Tx) {
6565

6666
if tick%20 == 0 {
6767
for _, viewer := range viewers {
68-
if w.Dimension().TimeCycle() {
69-
viewer.ViewTime(tim, cycle)
68+
if w.Dimension().TimeCycle() && cycle {
69+
viewer.ViewTime(tim)
7070
}
7171
if w.Dimension().WeatherCycle() {
7272
viewer.ViewWeather(rain, thunder)

server/world/viewer.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ type Viewer interface {
3939
ViewChunk(pos ChunkPos, dim Dimension, blockEntities map[cube.Pos]Block, c *chunk.Chunk)
4040
// ViewTime views the time of the world. It is called every time the time is changed or otherwise every
4141
// second.
42-
ViewTime(t int, doDayLightCycle bool)
42+
ViewTime(t int)
43+
// ViewTimeCycle controls the automatic time-of-day cycle (day and night) in the world for this viewer.
44+
ViewTimeCycle(doDayLightCycle bool)
4345
// ViewEntityItems views the items currently held by an Entity that is able to equip items.
4446
ViewEntityItems(e Entity)
4547
// ViewEntityArmour views the items currently equipped as armour by the Entity.
@@ -87,7 +89,8 @@ func (NopViewer) ViewEntityMovement(Entity, mgl64.Vec3, cube.Rotation, bool)
8789
func (NopViewer) ViewEntityVelocity(Entity, mgl64.Vec3) {}
8890
func (NopViewer) ViewEntityTeleport(Entity, mgl64.Vec3) {}
8991
func (NopViewer) ViewChunk(ChunkPos, Dimension, map[cube.Pos]Block, *chunk.Chunk) {}
90-
func (NopViewer) ViewTime(int, bool) {}
92+
func (NopViewer) ViewTime(int) {}
93+
func (NopViewer) ViewTimeCycle(bool) {}
9194
func (NopViewer) ViewEntityItems(Entity) {}
9295
func (NopViewer) ViewEntityArmour(Entity) {}
9396
func (NopViewer) ViewEntityAction(Entity, EntityAction) {}

server/world/world.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -598,12 +598,11 @@ func (w *World) SetTime(new int) {
598598
}
599599
w.set.Lock()
600600
w.set.Time = int64(new)
601-
timeCycle := w.set.TimeCycle
602601
w.set.Unlock()
603602

604603
viewers, _ := w.allViewers()
605604
for _, viewer := range viewers {
606-
viewer.ViewTime(new, timeCycle)
605+
viewer.ViewTime(new)
607606
}
608607
}
609608

@@ -639,6 +638,10 @@ func (w *World) enableTimeCycle(v bool) {
639638
w.set.Lock()
640639
defer w.set.Unlock()
641640
w.set.TimeCycle = v
641+
viewers, _ := w.allViewers()
642+
for _, viewer := range viewers {
643+
viewer.ViewTimeCycle(v)
644+
}
642645
}
643646

644647
// temperature returns the temperature in the World at a specific position.
@@ -1062,7 +1065,8 @@ func (w *World) addWorldViewer(l *Loader) {
10621065
w.viewers[l] = l.viewer
10631066
w.viewerMu.Unlock()
10641067

1065-
l.viewer.ViewTime(w.Time(), w.TimeCycle())
1068+
l.viewer.ViewTime(w.Time())
1069+
l.viewer.ViewTimeCycle(w.TimeCycle())
10661070
w.set.Lock()
10671071
raining, thundering := w.set.Raining, w.set.Raining && w.set.Thundering
10681072
w.set.Unlock()

0 commit comments

Comments
 (0)