-
-
Notifications
You must be signed in to change notification settings - Fork 88
/
boss_event.go
103 lines (97 loc) · 3.47 KB
/
boss_event.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
92
93
94
95
96
97
98
99
100
101
102
103
package packet
import (
"github.com/sandertv/gophertunnel/minecraft/protocol"
)
const (
BossEventShow = iota
BossEventRegisterPlayer
BossEventHide
BossEventUnregisterPlayer
BossEventHealthPercentage
BossEventTitle
BossEventAppearanceProperties
BossEventTexture
BossEventRequest
)
const (
BossEventColourGrey = iota
BossEventColourBlue
BossEventColourRed
BossEventColourGreen
BossEventColourYellow
BossEventColourPurple
BossEventColourWhite
)
// BossEvent is sent by the server to make a specific 'boss event' occur in the
// world. It includes features such as showing a boss bar to the player and
// turning the sky dark.
type BossEvent struct {
// BossEntityUniqueID is the unique ID of the boss entity that the boss
// event sent involves. By default, the health percentage and title of the
// boss bar depend on the health and name tag of this entity. If
// BossEntityUniqueID is the same as the client's entity unique ID, its
// HealthPercentage and BossBarTitle can be freely altered.
BossEntityUniqueID int64
// EventType is the type of the event. The fields written depend on the
// event type set, and some event types are sent by the client, whereas
// others are sent by the server. The event type is one of the constants
// above.
EventType uint32
// PlayerUniqueID is the unique ID of the player that is registered to or
// unregistered from the boss fight. It is set if EventType is either
// BossEventRegisterPlayer or BossEventUnregisterPlayer.
PlayerUniqueID int64
// BossBarTitle is the title shown above the boss bar. It may be set to set
// a different title if the BossEntityUniqueID matches the client's entity
// unique ID.
BossBarTitle string
// HealthPercentage is the percentage of health that is shown in the boss
// bar (0.0-1.0). The HealthPercentage may be set to a specific value if the
// BossEntityUniqueID matches the client's entity unique ID.
HealthPercentage float32
// ScreenDarkening currently seems not to do anything.
ScreenDarkening uint16
// Colour is the colour of the boss bar that is shown when a player is
// subscribed. It is only set if the EventType is BossEventShow,
// BossEventAppearanceProperties or BossEventTexture. This is functional as
// of 1.18 and can be any of the BossEventColour constants listed above.
Colour uint32
// Overlay is the overlay of the boss bar that is shown on top of the boss
// bar when a player is subscribed. It currently does not function. It is
// only set if the EventType is BossEventShow, BossEventAppearanceProperties
// or BossEventTexture.
Overlay uint32
}
// ID ...
func (*BossEvent) ID() uint32 {
return IDBossEvent
}
func (pk *BossEvent) Marshal(io protocol.IO) {
io.Varint64(&pk.BossEntityUniqueID)
io.Varuint32(&pk.EventType)
switch pk.EventType {
case BossEventShow:
io.String(&pk.BossBarTitle)
io.Float32(&pk.HealthPercentage)
io.Uint16(&pk.ScreenDarkening)
io.Varuint32(&pk.Colour)
io.Varuint32(&pk.Overlay)
case BossEventRegisterPlayer, BossEventUnregisterPlayer, BossEventRequest:
io.Varint64(&pk.PlayerUniqueID)
case BossEventHide:
// No extra payload for this boss event type.
case BossEventHealthPercentage:
io.Float32(&pk.HealthPercentage)
case BossEventTitle:
io.String(&pk.BossBarTitle)
case BossEventAppearanceProperties:
io.Uint16(&pk.ScreenDarkening)
io.Varuint32(&pk.Colour)
io.Varuint32(&pk.Overlay)
case BossEventTexture:
io.Varuint32(&pk.Colour)
io.Varuint32(&pk.Overlay)
default:
io.UnknownEnumOption(pk.EventType, "boss event type")
}
}