generated from PrismarineJS/prismarine-template
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathindex.d.ts
238 lines (198 loc) · 5.89 KB
/
index.d.ts
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
declare class ChatMessage {
// for export
static MessageBuilder: typeof MessageBuilder
/**
* @param message content of ChatMessage
*/
constructor(
message: string | number | MessageBuilder | MessageBuilder[],
displayWarning?: boolean
)
public readonly json: any
/**
* Append one or more ChatMessages
*/
append(...messages: object[] | string[]): void
/**
* Returns a clone of the ChatMessage
*/
clone(): ChatMessage
/**
* Optional info with no guarantee for form or shape.
*/
extra?: Array<ChatMessage>
translate?: string
/**
* Flattens the message into plain-text, without style.
*/
toString(language?: Language): string
/**
* Flattens the message into text containing `§x` style codes.
*/
toMotd(language?: Language, parent?: object): string
/**
* Flattens the message into text styled with ANSI escape sequences.
* Useful for printing to the console.
* See also https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Select_Graphic_Rendition)_parameters
*/
toAnsi(language?: Language): string
/**
* Returns a CSS styled and escaped HTML string
*/
toHTML(language?: Language, styles?: Record<Color, string>, allowedFormats?: DefaultFormats): string
/**
* Returns the count of text extras and child ChatMessages.
* Does not count recursively in to the children.
*/
length(): number
/**
* Returns a text part from the message.
* @param idx Index of the part
*/
getText(idx: number, language?: Language): string
/**
* Flattens the message into plain-text, without style.
*/
valueOf(): string
static fromNotch(str: string): ChatMessage
// 1.19+
static fromNetwork(messageType: number, parameters: Record<string, Object>): ChatMessage
}
declare class MessageBuilder {
with: string[]
extra: string[]
bold?: boolean
italic?: boolean
underlined?: boolean
strikethrough?: boolean
obfuscated?: boolean
color?: string
text?: string
font?: string
translate?: string
insertion?: string
keybind?: string
score?: { name: string; objective: string }
clickEvent?: object
hoverEvent?: object
setBold(val: boolean): this
setItalic(val: boolean): this
setUnderlined(val: boolean): this
setStrikethrough(val: boolean): this
setObfuscated(val: boolean): this
setColor(val: Color): this
setText(val: string): this
/**
* The resource location of the font for this component in the resource pack within `assets/<namespace>/font`.
* @param {string} val Defaults to `minecraft:default`
*/
setFont(val?: string): this
/**
* When used, it's expected that all slots for text will be filled using .addWith()
*/
setTranslate(val: string): this
/**
* text shown when shift clicked on message
*/
setInsertion(val: string): this
/**
* Overrode by .setText()
* @example
* builder.setKeybind('key.inventory')
*/
setKeybind(val: string): this
/**
* Displays a score holder's current score in an objective.
* Displays nothing if the given score holder or the given objective do not exist, or if the score holder is not tracked in the objective.
* @param {string} name if '*', show reader their own score. Otherwise, this is the player's score shown. Can be a selector string, but must never select more than one entity.
* @param {string} objective The internal name of the objective to display the player's score in.
*/
setScore(name: string, objective: string): this
/**
* @example
* builder.setClickEvent('open_url', 'https://google.com')
* builder.setClickEvent('run_command', '/say Hi!') // for signs, the slash doesn't need to be there
* builder.setClickEvent('suggest_command', '/say ')
* builder.setClickEvent('change_page', '/say Hi!') // Can only be used in written books
* builder.setClickEvent('copy_to_clipboard', 'welcome to your clipboard')
*/
setClickEvent(
action:
| "open_url"
| "run_command"
| "suggest_command"
| "change_page"
| "copy_to_clipboard",
value: string | number
): this
setHoverEvent(
action: "show_text",
data: MessageBuilder,
type?: "contents" | "value"
): this
setHoverEvent(
action: "show_entity",
data: { displayName: string; name: string; uuid: string },
type?: "contents"
): this
setHoverEvent(
action: "show_item",
data: { name: string; count: number; nbt: any },
type?: "contents" | "value"
): this
/**
* appended to the end of this message object with the existing formatting.
* formatting can be overridden in child messagebuilder
*/
addExtra(...args: Array<MessageBuilder | string>): this
/**
* requires .translate to be set for this to be used
*/
addWith(...args: Array<MessageBuilder | string>): this
resetFormatting(): void
toJSON(): object
toString(): string
/**
* fromString('&aHello').toJSON() => { text: 'Hello', color: 'aqua' }
*/
static fromString(
str: string,
args?: { colorSeparator?: string }
): MessageBuilder
// 1.19+
static fromNetwork (messageType: number, parameters: Record<string, Object>): MessageBuilder
}
type Language = { [key: string]: string }
type Color =
| "black"
| "dark_blue"
| "dark_green"
| "dark_aqua"
| "dark_red"
| "dark_purple"
| "gold"
| "gray"
| "dark_gray"
| "blue"
| "green"
| "aqua"
| "red"
| "light_purple"
| "yellow"
| "white"
| "obfuscated"
| "bold"
| "strikethrough"
| "underlined"
| "italic"
| "reset"
type DefaultFormats = 'color' | 'bold' | 'strikethrough' | 'underlined' | 'italic'
// mcpc 1.20.3 uses NBT instead of JSON in some places to store chat, so the schema is a bit different
// processNbtMessage normalizes the JS object obtained from nbt derealization to the old JSON schema
function processNbtMessage(parsedNbtObject)
declare const loader: (registryOrVersion: string) => typeof ChatMessage
export default loader
export {
ChatMessage,
processNbtMessage
}