-
Notifications
You must be signed in to change notification settings - Fork 97
/
block_actor_data.go
39 lines (34 loc) · 1.2 KB
/
block_actor_data.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
package packet
import (
"bytes"
"github.com/sandertv/gophertunnel/minecraft/nbt"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// BlockActorData is sent by the server to update data of a block entity client-side, for example the data of
// a chest.
type BlockActorData struct {
// Position is the position of the block that holds the block entity. If no block entity is at this
// position, the packet is ignored by the client.
Position protocol.BlockPos
// NBTData is the new data of the block that will be encoded to NBT and applied client-side, so that the
// client can see the block update. The NBTData should contain all properties of the block, not just
// properties that were changed.
NBTData map[string]interface{}
}
// ID ...
func (*BlockActorData) ID() uint32 {
return IDBlockActorData
}
// Marshal ...
func (pk *BlockActorData) Marshal(buf *bytes.Buffer) {
_ = protocol.WriteUBlockPosition(buf, pk.Position)
_ = nbt.NewEncoder(buf).Encode(pk.NBTData)
}
// Unmarshal ...
func (pk *BlockActorData) Unmarshal(buf *bytes.Buffer) error {
pk.NBTData = make(map[string]interface{})
return chainErr(
protocol.UBlockPosition(buf, &pk.Position),
nbt.NewDecoder(buf).Decode(&pk.NBTData),
)
}