Files
mc/server/session/handler_interact.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

43 lines
1.1 KiB
Go

package session
import (
"fmt"
"github.com/df-mc/dragonfly/server/world"
"github.com/sandertv/gophertunnel/minecraft/protocol"
"github.com/sandertv/gophertunnel/minecraft/protocol/packet"
)
// InteractHandler handles the packet.Interact.
type InteractHandler struct{}
// Handle ...
func (h *InteractHandler) Handle(p packet.Packet, s *Session, _ *world.Tx, c Controllable) error {
pk := p.(*packet.Interact)
pos := c.Position()
switch pk.ActionType {
case packet.InteractActionMouseOverEntity:
// We don't need this action.
case packet.InteractActionOpenInventory:
if s.invOpened {
// When there is latency, this might end up being sent multiple times. If we send a ContainerOpen
// multiple times, the client crashes.
return nil
}
s.invOpened = true
s.writePacket(&packet.ContainerOpen{
WindowID: 0,
ContainerType: 0xff,
ContainerEntityUniqueID: -1,
ContainerPosition: protocol.BlockPos{
int32(pos[0]),
int32(pos[1]),
int32(pos[2]),
},
})
default:
return fmt.Errorf("unexpected interact packet action %v", pk.ActionType)
}
return nil
}