Skip to content

Commit

Permalink
world/entity.go: Move worldless bool resetting to execWorld.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sandertv committed Dec 23, 2024
1 parent 30df97d commit 09399ad
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/world/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func NewEntity(t EntityType, conf EntityConfig) *EntityHandle {
// entityFromData reads an entity from the decoded NBT data passed and returns
// an EntityHandle.
func entityFromData(t EntityType, id int64, data map[string]any) *EntityHandle {
handle := &EntityHandle{t: t, cond: sync.NewCond(&sync.Mutex{})}
handle := &EntityHandle{t: t, cond: sync.NewCond(&sync.Mutex{}), worldless: &atomic.Bool{}}
binary.LittleEndian.PutUint64(handle.id[8:], uint64(id))
handle.decodeNBT(data)
t.DecodeNBT(data, &handle.data)
Expand Down Expand Up @@ -152,6 +152,7 @@ func (e *EntityHandle) execWorld(f func(tx *Tx, e Entity), weak bool) (run bool)
for e.w == nil || (!weak && e.weakTxActive) {
e.cond.Wait()
}
e.worldless.Store(false)
if e.w == closeWorld {
// EntityHandle was closed.
e.cond.L.Unlock()
Expand Down Expand Up @@ -215,7 +216,6 @@ func (e *EntityHandle) setAndUnlockWorld(w *World, tx *Tx) {
panic("cannot add entity to new world before removing from old world")
}
e.w = w
e.worldless.Store(false)
e.cond.Broadcast()
}

Expand Down

0 comments on commit 09399ad

Please sign in to comment.