Files
mc/server/session/handler_container_close.go
TarnaWijaya 26ed99fda6
Build and deploy / Build (push) Has been cancelled
Build and deploy / Update Contributors (push) Has been cancelled
Build and deploy / Deploy (push) Has been cancelled
up3
2026-07-09 08:33:57 +08:00

41 lines
1014 B
Go

package session
import (
"github.com/df-mc/dragonfly/server/world"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// ContainerCloseHandler handles the ContainerClose packet.
type ContainerCloseHandler struct{}
// Handle ...
func (h *ContainerCloseHandler) Handle(p packet.Packet, s *Session, tx *world.Tx, c Controllable) error {
pk := p.(*packet.ContainerClose)
c.MoveItemsToInventory()
var containerType byte
switch pk.WindowID {
case 0:
// Closing of the normal inventory.
s.invOpened = false
case byte(s.openedWindowID.Load()):
containerType = byte(s.openedContainerID.Load())
s.closeCurrentContainer(tx, true)
case 0xff:
// Sent when an inventory/container is opened at the same time as chat.
s.invOpened = false
if s.containerOpened.Load() {
s.closeCurrentContainer(tx, false)
}
return nil
default:
containerType = pk.ContainerType
}
s.writePacket(&packet.ContainerClose{
WindowID: pk.WindowID,
ContainerType: containerType,
})
return nil
}