github.com/df-mc/dragonfly@v0.9.13/server/session/handler_interact.go (about) 1 package session 2 3 import ( 4 "fmt" 5 "github.com/sandertv/gophertunnel/minecraft/protocol" 6 "github.com/sandertv/gophertunnel/minecraft/protocol/packet" 7 ) 8 9 // InteractHandler handles the packet.Interact. 10 type InteractHandler struct{} 11 12 // Handle ... 13 func (h *InteractHandler) Handle(p packet.Packet, s *Session) error { 14 pk := p.(*packet.Interact) 15 pos := s.c.Position() 16 17 switch pk.ActionType { 18 case packet.InteractActionMouseOverEntity: 19 // We don't need this action. 20 case packet.InteractActionOpenInventory: 21 if s.invOpened { 22 // When there is latency, this might end up being sent multiple times. If we send a ContainerOpen 23 // multiple times, the client crashes. 24 return nil 25 } 26 s.invOpened = true 27 s.writePacket(&packet.ContainerOpen{ 28 WindowID: 0, 29 ContainerType: 0xff, 30 ContainerEntityUniqueID: -1, 31 ContainerPosition: protocol.BlockPos{ 32 int32(pos[0]), 33 int32(pos[1]), 34 int32(pos[2]), 35 }, 36 }) 37 default: 38 return fmt.Errorf("unexpected interact packet action %v", pk.ActionType) 39 } 40 return nil 41 }