diff --git a/server/player/player.go b/server/player/player.go index f633290a0..39b07e0bf 100644 --- a/server/player/player.go +++ b/server/player/player.go @@ -55,7 +55,7 @@ type Player struct { skin atomic.Pointer[skin.Skin] // s holds the session of the player. This field should not be used directly, but instead, // Player.session() should be called. - s atomic.Pointer[*session.Session] + s atomic.Pointer[session.Session] // h holds the current Handler of the player. It may be changed at any time by calling the Handle method. h atomic.Pointer[Handler] @@ -155,7 +155,7 @@ func New(name string, skin skin.Skin, pos mgl64.Vec3) *Player { // you can leave the data as nil to use default data. func NewWithSession(name, xuid string, uuid uuid.UUID, skin skin.Skin, s *session.Session, pos mgl64.Vec3, data *Data) *Player { p := New(name, skin, pos) - p.s.Store(&s) + p.s.Store(s) p.skin.Store(&skin) p.uuid, p.xuid = uuid, xuid p.inv, p.offHand, p.enderChest, p.armour, p.heldSlot = s.HandleInventories() @@ -2939,7 +2939,7 @@ func (p *Player) Data() Data { // is returned. func (p *Player) session() *session.Session { if s := p.s.Load(); s != nil { - return *s + return s } return session.Nop } diff --git a/server/session/handler_item_stack_request.go b/server/session/handler_item_stack_request.go index 55915f349..177c561bf 100644 --- a/server/session/handler_item_stack_request.go +++ b/server/session/handler_item_stack_request.go @@ -208,7 +208,7 @@ func (h *ItemStackRequestHandler) handleSwap(a *protocol.SwapStackRequestAction, // smelting. If it does, it will drop the rewards at the player's location. func (h *ItemStackRequestHandler) collectRewards(s *Session, inv *inventory.Inventory, slot int) { w := s.c.World() - if inv == *s.openedWindow.Load() && s.containerOpened.Load() && slot == inv.Size()-1 { + if inv == s.openedWindow.Load() && s.containerOpened.Load() && slot == inv.Size()-1 { if f, ok := w.Block(*s.openedPos.Load()).(smelter); ok { for _, o := range entity.NewExperienceOrbs(entity.EyePosition(s.c), f.ResetExperience()) { o.SetVelocity(mgl64.Vec3{(rand.Float64()*0.2 - 0.1) * 2, rand.Float64() * 0.4, (rand.Float64()*0.2 - 0.1) * 2}) diff --git a/server/session/handler_player_auth_input.go b/server/session/handler_player_auth_input.go index 38ec6542c..bc81cb18f 100644 --- a/server/session/handler_player_auth_input.go +++ b/server/session/handler_player_auth_input.go @@ -51,7 +51,7 @@ func (h PlayerAuthInputHandler) handleMovement(pk *packet.PlayerAuthInput, s *Se } if expected := s.teleportPos.Load(); expected != nil { - if newPos.Sub(**expected).Len() > 1 { + if newPos.Sub(*expected).Len() > 1 { // The player has moved before it received the teleport packet. Ignore this movement entirely and // wait for the client to sync itself back to the server. Once we get a movement that is close // enough to the teleport position, we'll allow the player to move around again. diff --git a/server/session/player.go b/server/session/player.go index 7de374ccd..935f432aa 100644 --- a/server/session/player.go +++ b/server/session/player.go @@ -246,12 +246,12 @@ func (s *Session) invByID(id int32) (*inventory.Inventory, bool) { return s.armour.Inventory(), true case protocol.ContainerLevelEntity: if s.containerOpened.Load() { - return *s.openedWindow.Load(), true + return s.openedWindow.Load(), true } case protocol.ContainerBarrel: if s.containerOpened.Load() { if _, barrel := s.c.World().Block(*s.openedPos.Load()).(block.Barrel); barrel { - return *s.openedWindow.Load(), true + return s.openedWindow.Load(), true } } case protocol.ContainerBeaconPayment: @@ -300,7 +300,7 @@ func (s *Session) invByID(id int32) (*inventory.Inventory, bool) { protocol.ContainerBlastFurnaceIngredient, protocol.ContainerSmokerIngredient: if s.containerOpened.Load() { if _, ok := s.c.World().Block(*s.openedPos.Load()).(smelter); ok { - return *s.openedWindow.Load(), true + return s.openedWindow.Load(), true } } } diff --git a/server/session/session.go b/server/session/session.go index 5c5fbad7c..1106ec8f4 100644 --- a/server/session/session.go +++ b/server/session/session.go @@ -47,7 +47,7 @@ type Session struct { chunkLoader *world.Loader chunkRadius, maxChunkRadius int32 - teleportPos atomic.Pointer[*mgl64.Vec3] + teleportPos atomic.Pointer[mgl64.Vec3] entityMutex sync.RWMutex // currentEntityRuntimeID holds the runtime ID assigned to the last entity. It is incremented for every @@ -68,7 +68,7 @@ type Session struct { inTransaction, containerOpened atomic.Bool openedWindowID atomic.Uint32 openedContainerID atomic.Uint32 - openedWindow atomic.Pointer[*inventory.Inventory] + openedWindow atomic.Pointer[inventory.Inventory] openedPos atomic.Pointer[cube.Pos] swingingArm atomic.Bool changingDimension atomic.Bool @@ -167,7 +167,7 @@ func New(conn Conn, maxChunkRadius int, log Logger, joinMessage, quitMessage str quitMessage: quitMessage, } inv := inventory.New(1, nil) - s.openedWindow.Store(&inv) + s.openedWindow.Store(inv) var scoreboardName string var scoreboardLines []string diff --git a/server/session/world.go b/server/session/world.go index 5fca88d99..953efc485 100644 --- a/server/session/world.go +++ b/server/session/world.go @@ -249,8 +249,7 @@ func (s *Session) ViewEntityTeleport(e world.Entity, position mgl64.Vec3) { yaw, pitch := e.Rotation().Elem() if id == selfEntityRuntimeID { s.chunkLoader.Move(position) - pos := &position - s.teleportPos.Store(&pos) + s.teleportPos.Store(&position) } s.writePacket(&packet.SetActorMotion{EntityRuntimeID: id}) @@ -974,7 +973,7 @@ func (s *Session) OpenBlockContainer(pos cube.Pos) { nextID := s.nextWindowID() s.containerOpened.Store(true) inv := inventory.New(1, nil) - s.openedWindow.Store(&inv) + s.openedWindow.Store(inv) s.openedPos.Store(&pos) var containerType byte @@ -999,7 +998,7 @@ func (s *Session) OpenBlockContainer(pos cube.Pos) { b.AddViewer(w, pos) inv := s.c.EnderChestInventory() - s.openedWindow.Store(&inv) + s.openedWindow.Store(inv) defer s.sendInv(inv, uint32(nextID)) } @@ -1020,7 +1019,7 @@ func (s *Session) openNormalContainer(b block.Container, pos cube.Pos) { nextID := s.nextWindowID() s.containerOpened.Store(true) inv := b.Inventory(s.c.World(), pos) - s.openedWindow.Store(&inv) + s.openedWindow.Store(inv) s.openedPos.Store(&pos) var containerType byte @@ -1162,7 +1161,7 @@ func (s *Session) closeWindow() { } s.openedContainerID.Store(0) inv := inventory.New(1, nil) - s.openedWindow.Store(&inv) + s.openedWindow.Store(inv) s.writePacket(&packet.ContainerClose{WindowID: byte(s.openedWindowID.Load())}) }