-
Notifications
You must be signed in to change notification settings - Fork 141
/
handler_interact.go
41 lines (37 loc) · 1.03 KB
/
handler_interact.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package session
import (
"fmt"
"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) error {
pk := p.(*packet.Interact)
pos := s.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
}