Skip to content

Commit

Permalink
session/player.go: Store hidden entities by UUID instead of EntityHan…
Browse files Browse the repository at this point in the history
…dle.

Fixes #978.
  • Loading branch information
Sandertv committed Dec 28, 2024
1 parent 65c2bab commit 89a79c6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
8 changes: 4 additions & 4 deletions server/session/player.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ import (
// StartShowingEntity is made.
func (s *Session) StopShowingEntity(e world.Entity) {
s.entityMutex.Lock()
_, ok := s.hiddenEntities[e.H()]
_, ok := s.hiddenEntities[e.H().UUID()]
if !ok {
s.hiddenEntities[e.H()] = struct{}{}
s.hiddenEntities[e.H().UUID()] = struct{}{}
}
s.entityMutex.Unlock()

Expand All @@ -42,9 +42,9 @@ func (s *Session) StopShowingEntity(e world.Entity) {
// StartShowingEntity starts showing a world.Entity to the Session that was previously hidden using StopShowingEntity.
func (s *Session) StartShowingEntity(e world.Entity) {
s.entityMutex.Lock()
_, ok := s.hiddenEntities[e.H()]
_, ok := s.hiddenEntities[e.H().UUID()]
if ok {
delete(s.hiddenEntities, e.H())
delete(s.hiddenEntities, e.H().UUID())
}
s.entityMutex.Unlock()

Expand Down
5 changes: 3 additions & 2 deletions server/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/df-mc/dragonfly/server/player/skin"
"github.com/df-mc/dragonfly/server/world"
"github.com/go-gl/mathgl/mgl64"
"github.com/google/uuid"
"github.com/sandertv/gophertunnel/minecraft"
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/sandertv/gophertunnel/minecraft/protocol"
Expand Down Expand Up @@ -51,7 +52,7 @@ type Session struct {
// entityRuntimeIDs holds the runtime IDs of entities shown to the session.
entityRuntimeIDs map[*world.EntityHandle]uint64
entities map[uint64]*world.EntityHandle
hiddenEntities map[*world.EntityHandle]struct{}
hiddenEntities map[uuid.UUID]struct{}

// heldSlot is the slot in the inventory that the controllable is holding.
heldSlot *uint32
Expand Down Expand Up @@ -153,7 +154,7 @@ func (conf Config) New(conn Conn) *Session {
handlers: map[uint32]packetHandler{},
entityRuntimeIDs: map[*world.EntityHandle]uint64{},
entities: map[uint64]*world.EntityHandle{},
hiddenEntities: map[*world.EntityHandle]struct{}{},
hiddenEntities: map[uuid.UUID]struct{}{},
blobs: map[uint64][]byte{},
chunkRadius: int32(r),
maxChunkRadius: int32(conf.MaxChunkRadius),
Expand Down
2 changes: 1 addition & 1 deletion server/session/world.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type OffsetEntity interface {
// entityHidden checks if a world.Entity is being explicitly hidden from the Session.
func (s *Session) entityHidden(e world.Entity) bool {
s.entityMutex.RLock()
_, ok := s.hiddenEntities[e.H()]
_, ok := s.hiddenEntities[e.H().UUID()]
s.entityMutex.RUnlock()
return ok
}
Expand Down

0 comments on commit 89a79c6

Please sign in to comment.