forked from Sandertv/gophertunnel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
attribute.go
87 lines (79 loc) · 2.78 KB
/
attribute.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
package protocol
const (
AttributeModifierOperationAddition = iota
AttributeModifierOperationMultiplyBase
AttributeModifierOperationMultiplyTotal
AttributeModifierOperationCap
)
const (
AttributeModifierOperandMin = iota
AttributeModifierOperandMax
AttributeModifierOperandCurrent
)
// AttributeValue holds the value of an attribute, including the min and max.
type AttributeValue struct {
// Name is the name of the attribute, for example 'minecraft:health'. These names must be identical to
// the ones defined client-side.
Name string
// Value is the current value of the attribute. This value will be applied to the entity when sent in a
// packet.
Value float32
// Max and Min specify the boundaries within the value of the attribute must be. The definition of these
// fields differ per attribute. The maximum health of an entity may be changed, whereas the maximum
// movement speed for example may not be.
Max, Min float32
}
// Marshal encodes/decodes an AttributeValue.
func (x *AttributeValue) Marshal(r IO) {
r.String(&x.Name)
r.Float32(&x.Min)
r.Float32(&x.Value)
r.Float32(&x.Max)
}
// Attribute is an entity attribute, that holds specific data such as the health of the entity. Each attribute
// holds a default value, maximum and minimum value, name and its current value.
type Attribute struct {
AttributeValue
// Default is the default value of the attribute. It's not clear why this field must be sent to the
// client, but it is required regardless.
Default float32
// Modifiers is a slice of AttributeModifiers that are applied to the attribute.
Modifiers []AttributeModifier
}
// Marshal encodes/decodes an Attribute.
func (x *Attribute) Marshal(r IO) {
r.Float32(&x.Min)
r.Float32(&x.Max)
r.Float32(&x.Value)
r.Float32(&x.Default)
r.String(&x.Name)
Slice(r, &x.Modifiers)
}
// AttributeModifier temporarily buffs/debuffs a given attribute until the modifier is used. In vanilla, these are
// mainly used for effects.
type AttributeModifier struct {
// ID is the unique ID of the modifier. It is used to identify the modifier in the packet.
ID string
// Name is the name of the attribute that is modified.
Name string
// Amount is the amount of difference between the current value of the attribute and the new value.
Amount float32
// Operation is the operation that is performed on the attribute. It can be addition, multiply base, multiply total
// or cap.
Operation int32
// Operand ...
// TODO: Figure out what this field is used for.
Operand int32
// Serializable ...
// TODO: Figure out what this field is used for.
Serializable bool
}
// Marshal encodes/decodes an AttributeModifier.
func (x *AttributeModifier) Marshal(r IO) {
r.String(&x.ID)
r.String(&x.Name)
r.Float32(&x.Amount)
r.Int32(&x.Operation)
r.Int32(&x.Operand)
r.Bool(&x.Serializable)
}