forked from df-mc/dragonfly
-
Notifications
You must be signed in to change notification settings - Fork 1
/
entity_metadata.go
66 lines (58 loc) · 1.74 KB
/
entity_metadata.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 session
import (
"github.com/sunproxy/sunfly/dragonfly/world"
)
// entityMetadata represents a map that holds metadata associated with an entity. The data held in the map
// depends on the entity and varies on a per-entity basis.
type entityMetadata map[uint32]interface{}
// defaultEntityMetadata returns an entity metadata object with default values. It is equivalent to setting
// all properties to their default values and disabling all flags.
func defaultEntityMetadata(e world.Entity) entityMetadata {
m := entityMetadata{}
m.setFlag(dataKeyFlags, dataFlagAffectedByGravity)
bb := e.AABB()
m[dataKeyBoundingBoxWidth] = float32(bb.Width())
m[dataKeyBoundingBoxHeight] = float32(bb.Height())
m[dataKeyPotionColour] = int32(0)
m[dataKeyPotionAmbient] = byte(0)
m[dataKeyColour] = byte(0)
return m
}
// setFlag sets a flag with a specific index in the int64 stored in the entity metadata map to the value
// passed. It is typically used for entity metadata flags.
func (m entityMetadata) setFlag(key uint32, index uint8) {
if v, ok := m[key]; !ok {
m[key] = int64(0) ^ (1 << uint64(index))
} else {
m[key] = v.(int64) ^ (1 << uint64(index))
}
}
//noinspection GoUnusedConst
const (
dataKeyFlags = iota
dataKeyHealth
dataKeyVariant
dataKeyColour
dataKeyNameTag
dataKeyOwnerRuntimeID
dataKeyTargetRuntimeID
dataKeyAir
dataKeyPotionColour
dataKeyPotionAmbient
dataKeyScale = 38
dataKeyBoundingBoxWidth = 53
dataKeyBoundingBoxHeight = 54
)
//noinspection GoUnusedConst
const (
dataFlagOnFire = iota
dataFlagSneaking
dataFlagRiding
dataFlagSprinting
dataFlagUsingItem
dataFlagInvisible
dataFlagNoAI = 16
dataFlagBreathing = 35
dataFlagAffectedByGravity = 48
dataFlagSwimming = 56
)