Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/lib/bossbar.js
9427 views
1
const colors = ['pink', 'blue', 'red', 'green', 'yellow', 'purple', 'white']
2
const divisions = [0, 6, 10, 12, 20]
3
4
function loader (registry) {
5
const ChatMessage = require('prismarine-chat')(registry)
6
return class BossBar {
7
constructor (uuid, title, health, dividers, color, flags) {
8
this._entityUUID = uuid
9
this.title = title
10
this._health = health
11
this._dividers = divisions[dividers]
12
this._color = colors[color]
13
this._shouldDarkenSky = flags & 0x1
14
this._isDragonBar = flags & 0x2
15
this._createFog = flags & 0x4
16
}
17
18
set entityUUID (uuid) {
19
this._entityUUID = uuid
20
}
21
22
set title (title) {
23
if (title && typeof title === 'object' && title.type === 'string' && 'value' in title) {
24
this._title = title.value
25
} else {
26
const chatMsg = ChatMessage.fromNotch(title)
27
if (chatMsg !== undefined && chatMsg !== null) {
28
this._title = chatMsg
29
} else if (typeof title === 'string') {
30
this._title = title
31
} else {
32
this._title = ''
33
}
34
}
35
}
36
37
set health (health) {
38
this._health = health
39
}
40
41
set dividers (dividers) {
42
this._dividers = divisions[dividers]
43
}
44
45
set color (color) {
46
this._color = colors[color]
47
}
48
49
set flags (flags) {
50
this._shouldDarkenSky = flags & 0x1
51
this._isDragonBar = flags & 0x2
52
this._createFog = flags & 0x4
53
}
54
55
get flags () {
56
return (this._shouldDarkenSky) | (this._isDragonBar << 1) | (this._createFog << 2)
57
}
58
59
set shouldDarkenSky (darkenSky) {
60
this._shouldDarkenSky = darkenSky
61
}
62
63
set isDragonBar (dragonBar) {
64
this._isDragonBar = dragonBar
65
}
66
67
get createFog () {
68
return this._createFog
69
}
70
71
set createFog (createFog) {
72
this._createFog = createFog
73
}
74
75
get entityUUID () {
76
return this._entityUUID
77
}
78
79
get title () {
80
return this._title
81
}
82
83
get health () {
84
return this._health
85
}
86
87
get dividers () {
88
return this._dividers
89
}
90
91
get color () {
92
return this._color
93
}
94
95
get shouldDarkenSky () {
96
return this._shouldDarkenSky
97
}
98
99
get isDragonBar () {
100
return this._isDragonBar
101
}
102
103
get shouldCreateFog () {
104
return this._createFog
105
}
106
}
107
}
108
109
module.exports = loader
110
111