forked from Tnze/go-mc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
misc.go
91 lines (75 loc) · 2.04 KB
/
misc.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package ptypes
import (
"io/ioutil"
"github.com/Tnze/go-mc/chat"
"github.com/Tnze/go-mc/data"
pk "github.com/Tnze/go-mc/net/packet"
)
// SoundEffect is a clientbound packet used to play a specific sound ID
// on the client.
type SoundEffect struct {
Sound pk.VarInt
Category pk.VarInt
X, Y, Z pk.Int
Volume, Pitch pk.Float
}
func (p *SoundEffect) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.Sound, &p.Category, &p.X, &p.Y, &p.Z, &p.Volume, &p.Pitch)
}
// NamedSoundEffect is a clientbound packet used to play a sound with the
// specified name on the client.
type NamedSoundEffect struct {
Sound pk.String
Category pk.VarInt
X, Y, Z pk.Int
Volume, Pitch pk.Float
}
func (p *NamedSoundEffect) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.Sound, &p.Category, &p.X, &p.Y, &p.Z, &p.Volume, &p.Pitch)
}
// ChatMessageClientbound represents a chat message forwarded by the server.
type ChatMessageClientbound struct {
S chat.Message
Pos pk.Byte
Sender pk.UUID
}
func (p *ChatMessageClientbound) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.S, &p.Pos, &p.Sender)
}
// UpdateHealth encodes player health/food information from the server.
type UpdateHealth struct {
Health pk.Float
Food pk.VarInt
FoodSaturation pk.Float
}
func (p *UpdateHealth) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.Health, &p.Food, &p.FoodSaturation)
}
// PluginData encodes the custom data encoded in a plugin message.
type PluginData []byte
func (p PluginData) Encode() []byte {
return []byte(p)
}
func (p *PluginData) Decode(r pk.DecodeReader) error {
data, err := ioutil.ReadAll(r)
if err != nil {
return err
}
*p = data
return nil
}
// PluginMessage represents a packet with a customized payload.
type PluginMessage struct {
Channel pk.Identifier
Data PluginData
}
func (p *PluginMessage) Decode(pkt pk.Packet) error {
return pkt.Scan(&p.Channel, &p.Data)
}
func (p *PluginMessage) Encode() pk.Packet {
return pk.Marshal(
data.CustomPayloadServerbound,
p.Channel,
p.Data,
)
}