/
add_item_actor.go
66 lines (61 loc) · 2.67 KB
/
add_item_actor.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
package packet
import (
"bytes"
"encoding/binary"
"github.com/go-gl/mathgl/mgl32"
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
// AddItemActor is sent by the server to the client to make an item entity show up. It is one of the few
// entities that cannot be sent using the AddActor packet
type AddItemActor struct {
// EntityUniqueID is the unique ID of the entity. The unique ID is a value that remains consistent across
// different sessions of the same world, but most servers simply fill the runtime ID of the entity out for
// this field.
EntityUniqueID int64
// EntityNetworkID is the runtime ID of the entity. The runtime ID is unique for each world session, and
// entities are generally identified in packets using this runtime ID.
EntityRuntimeID uint64
// Item is the item that is spawned. It must have a valid ID for it to show up client-side. If it is not
// a valid item, the client will crash when coming near.
Item protocol.ItemStack
// Position is the position to spawn the entity on. If the entity is on a distance that the player cannot
// see it, the entity will still show up if the player moves closer.
Position mgl32.Vec3
// Velocity is the initial velocity the entity spawns with. This velocity will initiate client side
// movement of the entity.
Velocity mgl32.Vec3
// EntityMetadata is a map of entity metadata, which includes flags and data properties that alter in
// particular the way the entity looks. Flags include ones such as 'on fire' and 'sprinting'.
// The metadata values are indexed by their property key.
EntityMetadata map[uint32]interface{}
// FromFishing specifies if the item was obtained by fishing it up using a fishing rod. It is not clear
// why the client needs to know this.
FromFishing bool
}
// ID ...
func (*AddItemActor) ID() uint32 {
return IDAddItemActor
}
// Marshal ...
func (pk *AddItemActor) Marshal(buf *bytes.Buffer) {
_ = protocol.WriteVarint64(buf, pk.EntityUniqueID)
_ = protocol.WriteVaruint64(buf, pk.EntityRuntimeID)
_ = protocol.WriteItem(buf, pk.Item)
_ = protocol.WriteVec3(buf, pk.Position)
_ = protocol.WriteVec3(buf, pk.Velocity)
_ = protocol.WriteEntityMetadata(buf, pk.EntityMetadata)
_ = binary.Write(buf, binary.LittleEndian, pk.FromFishing)
}
// Unmarshal ...
func (pk *AddItemActor) Unmarshal(buf *bytes.Buffer) error {
pk.EntityMetadata = map[uint32]interface{}{}
return chainErr(
protocol.Varint64(buf, &pk.EntityUniqueID),
protocol.Varuint64(buf, &pk.EntityRuntimeID),
protocol.Item(buf, &pk.Item),
protocol.Vec3(buf, &pk.Position),
protocol.Vec3(buf, &pk.Velocity),
protocol.EntityMetadata(buf, &pk.EntityMetadata),
binary.Read(buf, binary.LittleEndian, &pk.FromFishing),
)
}