blockbench-types 4.8.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/.prettierignore +1 -0
  2. package/.prettierrc.json +9 -0
  3. package/README.md +1 -0
  4. package/package.json +43 -33
  5. package/scripts/generate_docs.js +243 -194
  6. package/tsconfig.json +13 -14
  7. package/types/action.d.ts +358 -279
  8. package/types/animation.d.ts +181 -143
  9. package/types/animation_controller.d.ts +105 -99
  10. package/types/blockbench.d.ts +146 -76
  11. package/types/canvas.d.ts +239 -228
  12. package/types/canvas_frame.d.ts +2 -2
  13. package/types/codec.d.ts +36 -32
  14. package/types/cube.d.ts +32 -11
  15. package/types/desktop.d.ts +14 -0
  16. package/types/dialog.d.ts +164 -37
  17. package/types/display_mode.d.ts +13 -6
  18. package/types/file_system.d.ts +159 -0
  19. package/types/format.d.ts +46 -12
  20. package/types/global.d.ts +49 -3
  21. package/types/group.d.ts +16 -5
  22. package/types/index.d.ts +1 -0
  23. package/types/interface.d.ts +21 -12
  24. package/types/io.d.ts +2 -0
  25. package/types/keyframe.d.ts +73 -57
  26. package/types/legacy.d.ts +2 -1
  27. package/types/math_util.d.ts +1 -0
  28. package/types/menu.d.ts +93 -78
  29. package/types/mesh.d.ts +89 -64
  30. package/types/misc.d.ts +114 -47
  31. package/types/mode.d.ts +14 -0
  32. package/types/molang.d.ts +17 -0
  33. package/types/outliner.d.ts +42 -23
  34. package/types/painter.d.ts +49 -11
  35. package/types/panel.d.ts +49 -21
  36. package/types/plugin.d.ts +29 -1
  37. package/types/preview.d.ts +71 -69
  38. package/types/preview_scene.d.ts +11 -12
  39. package/types/project.d.ts +56 -34
  40. package/types/screencam.d.ts +11 -6
  41. package/types/settings.d.ts +87 -85
  42. package/types/shared_actions.d.ts +94 -0
  43. package/types/texture_layers.d.ts +117 -0
  44. package/types/textures.d.ts +381 -176
  45. package/types/timeline.d.ts +60 -60
  46. package/types/undo.d.ts +107 -103
  47. package/types/util.d.ts +165 -33
  48. package/types/uveditor.d.ts +3 -0
  49. package/types/validator.d.ts +3 -2
  50. package/types/vue.d.ts +7 -0
@@ -1,4 +1,4 @@
1
- /// <reference types="three" />
1
+ /// <reference path="./blockbench.d.ts"/>
2
2
 
3
3
  interface TextureData {
4
4
  path?: string
@@ -6,202 +6,407 @@ interface TextureData {
6
6
  folder?: string
7
7
  namespace?: string
8
8
  id?: string
9
- particle?: boolean
10
- visible?: boolean
11
- mode?: string
12
- saved?: boolean
13
- keep_size?: boolean
14
- source?: string
9
+ particle?: boolean
10
+ visible?: boolean
11
+ mode?: string
12
+ saved?: boolean
13
+ keep_size?: boolean
14
+ source?: string
15
+ width?: number
16
+ height?: number
17
+ standalone?: boolean
15
18
  }
16
19
  interface TextureEditOptions {
17
- /**
18
- * Edit method. 'canvas' is default
19
- */
20
- method?: 'canvas' | 'jimp'
21
- /**
22
- * Name of the undo entry that is created
23
- */
24
- edit_name?: string
25
- /**
26
- * Whether to use the cached canvas/jimp instance
27
- */
28
- use_cache?: boolean
29
- /**
30
- * If true, no undo point is created. Default is false
31
- */
32
- no_undo?: boolean
33
- /**
34
- * If true, the texture is not updated visually
35
- */
36
- no_update?: boolean
37
- no_undo_init?: boolean
38
- no_undo_finish?: boolean
20
+ /**
21
+ * Edit method. 'canvas' is default
22
+ */
23
+ method?: 'canvas' | 'jimp'
24
+ /**
25
+ * Name of the undo entry that is created
26
+ */
27
+ edit_name?: string
28
+ /**
29
+ * Whether to use the cached canvas/jimp instance
30
+ */
31
+ use_cache?: boolean
32
+ /**
33
+ * If true, no undo point is created. Default is false
34
+ */
35
+ no_undo?: boolean
36
+ /**
37
+ * If true, the texture is not updated visually
38
+ */
39
+ no_update?: boolean
40
+ no_undo_init?: boolean
41
+ no_undo_finish?: boolean
39
42
  }
40
43
 
41
44
  /**
42
45
  * A texture combines the functionality of material, texture, and image, in one. Textures can be linked to files on the local hard drive, or hold the information in RAM.
43
46
  */
44
47
  declare class Texture {
45
- constructor(data: TextureData, uuid?: string);
46
- readonly frameCount: number | undefined;
47
- readonly display_height: number;
48
- readonly ratio: number;
49
-
50
- path: string
51
- name: string
52
- /** Relative path to the file's directory, used by some formats such as Java Block/Item*/
53
- folder: string
54
- namespace: string
55
- /** Texture ID or key, used by some formats. By default this is a number that increases with every texture that is added */
56
- id: string
57
- /** Whether the texture is used for the models particle system. Used by some formats such as Java Block/Item */
58
- particle: boolean
59
- render_mode: 'default' | 'emissive' | 'additive' | 'layered' | string
60
- render_sides: 'auto' | 'front' | 'double' | string
61
-
62
- /** Texture animation frame time */
63
- frame_time: number
64
- frame_order_type: 'custom' | 'loop' | 'backwards' | 'back_and_forth'
65
- /** Custom frame order */
66
- frame_order: string
67
- /** Interpolate between frames */
68
- frame_interpolate: boolean
69
-
70
- /** HTML-style source of the texture's displayed data. Can be a path (desktop app only), or a base64 data URL */
71
- source: string
72
- selected: boolean
73
- show_icon: boolean
74
- error: number
75
- /** Whether the texture is visible. Used for layered textures mode */
76
- visible: boolean
77
- /** Whether the texture canvas is displayed in the UV/2D editor, for live feedback */
78
- display_canvas: boolean
79
- width: number
80
- height: number
81
- currentFrame: number
82
- saved: boolean
83
- /** Whether the latest version of the texture is currently loaded from and linked to a file on disk, or held in memory as bitmap data */
84
- mode: 'link' | 'bitmap'
85
- uuid: UUID
86
-
87
- /**
88
- * The texture's associated canvas. Note: This may not always be up to date with the texture data
89
- */
90
- canvas: HTMLCanvasElement
91
- /**
92
- * Texture image element
93
- */
94
- img: HTMLImageElement
95
-
96
- getErrorMessage(): string;
97
- extend(data: TextureData): this;
98
- /**
99
- * Loads the texture from it's current source
100
- * @param cb Callback function
101
- */
102
- load(cb?: () => {}): this;
103
- fromJavaLink(link: string, path_array: string[]): this;
104
- fromFile(file: {name: string, content?: string, path: string}): this;
105
- fromPath(path: string): this;
106
- fromDataURL(data_url: string): this;
107
- fromDefaultPack(): true | undefined;
108
- /**
109
- * Loads the default white error texture
110
- * @param error_id Sets the error ID of the texture
111
- */
112
- loadEmpty(error_id?: number): this;
113
-
114
- updateSource(dataUrl: string): this;
115
- updateMaterial(): this;
116
-
117
- /**
118
- * Opens a dialog to replace the texture with another file
119
- * @param force If true, no warning appears of the texture has unsaved changes
120
- */
121
- reopen(force: boolean): void;
122
- /**
123
- * Reloads the texture. Only works in the desktop app
124
- */
125
- reloadTexture(): void;
126
- getMaterial(): THREE.MeshLambertMaterial;
127
- select(event?: Event): this;
128
- /**
129
- * Adds texture to the textures list and initializes it
130
- * @param undo If true, an undo point is created
131
- */
132
- add(undo?: boolean): Texture;
133
- /**
134
- * Removes the texture
135
- * @param no_update If true, the texture is silently removed. The interface is not updated, no undo point is created
136
- */
137
- remove(no_update?: boolean): void;
138
- toggleVisibility(): this;
139
- enableParticle(): this;
140
- /**
141
- * Enables 'particle' on this texture if it is not enabled on any other texture
142
- */
143
- fillParticle(): this;
144
- /**
145
- * Applies the texture to the selected elements
146
- * @param all If true, the texture is applied to all faces of the elements. If 'blank', the texture is only applied to blank faces
147
- */
148
- apply(all: true | false | 'blank'): this;
149
- /**
150
- * Shows the texture file in the file explorer
151
- */
152
- openFolder(): this;
153
- /**
154
- * Opens the texture in the configured image editor
155
- */
156
- openEditor(): this;
157
- showContextMenu(event: MouseEvent): void;
158
- openMenu(): void;
159
- resizeDialog(): this;
160
- /**
161
- * Scroll the texture list to this texture
162
- */
163
- scrollTo(): void;
164
- save(as: any): this;
165
- /**
166
- * Returns the content of the texture as a base64 encoded string
167
- */
168
- getBase64(): string;
169
- /**
170
- * Wrapper to do edits to the texture.
171
- * @param callback
172
- * @param options Editing options
173
- */
174
- edit(callback: (instance: HTMLCanvasElement | object) => void | HTMLCanvasElement, options: TextureEditOptions): void;
175
- menu: Menu
176
-
177
- static all: Texture[]
178
- static getDefault(): Texture
48
+ constructor(data: TextureData, uuid?: string)
49
+ readonly frameCount: number | undefined
50
+ readonly display_height: number
51
+ readonly ratio: number
52
+
53
+ path?: string
54
+ name: string
55
+ /** Relative path to the file's directory, used by some formats such as Java Block/Item*/
56
+ folder: string
57
+ namespace: string
58
+ /** Texture ID or key, used by some formats. By default this is a number that increases with every texture that is added */
59
+ id: string
60
+ /** Whether the texture is used for the models particle system. Used by some formats such as Java Block/Item */
61
+ particle: boolean
62
+ render_mode: 'default' | 'emissive' | 'additive' | 'layered' | string
63
+ render_sides: 'auto' | 'front' | 'double' | string
64
+
65
+ /** Texture animation frame time */
66
+ frame_time: number
67
+ frame_order_type: 'custom' | 'loop' | 'backwards' | 'back_and_forth'
68
+ /** Custom frame order */
69
+ frame_order: string
70
+ /** Interpolate between frames */
71
+ frame_interpolate: boolean
72
+
73
+ /** HTML-style source of the texture's displayed data. Can be a path (desktop app only), or a base64 data URL */
74
+ source: string
75
+ selected?: boolean
76
+ show_icon: boolean
77
+ error: number
78
+ /** Whether the texture is visible. Used for layered textures mode */
79
+ visible: boolean
80
+
81
+ width: number
82
+ height: number
83
+ uv_width: number
84
+ uv_height: number
85
+ currentFrame: number
86
+ saved: boolean
87
+ /**
88
+ * Whether the latest version of the texture is currently loaded from and linked to a file on disk, or held in memory as bitmap data
89
+ * @deprecated Use texture.internal instead
90
+ */
91
+ mode: 'link' | 'bitmap'
92
+ /**
93
+ * If true, the texture is loaded internally. If false, the texture is loaded directly from a file
94
+ */
95
+ internal: boolean
96
+ uuid: UUID
97
+
98
+ /**
99
+ * Texture selection in paint mode
100
+ */
101
+ selection: IntMatrix
102
+ layers: TextureLayer[]
103
+ layers_enabled: boolean
104
+ /**
105
+ * The UUID of the project to sync the texture to
106
+ */
107
+ sync_to_project: UUID | ''
108
+
109
+ /**
110
+ * The texture's associated canvas. Since 4.9, this is the main source of truth for textures in internal mode.
111
+ */
112
+ canvas: HTMLCanvasElement
113
+ /**
114
+ * The 2D context of the texture's associated canvas.
115
+ */
116
+ ctx: CanvasRenderingContext2D
117
+ /**
118
+ * Texture image element
119
+ */
120
+ img: HTMLImageElement
121
+
122
+ relative_path?: string
123
+
124
+ getErrorMessage(): string
125
+ extend(data: TextureData): this
126
+
127
+ /**
128
+ * Get the UV width of the texture if the format uses per texture UV size, otherwise get the project texture width
129
+ */
130
+ getUVWidth(): number
131
+ /**
132
+ * Get the UV height of the texture if the format uses per texture UV size, otherwise get the project texture height
133
+ */
134
+ getUVHeight(): number
135
+ getUndoCopy(bitmap?: boolean): any
136
+ getSaveCopy(bitmap?: boolean): any
137
+ /**
138
+ * Start listening for changes to the linked file. Desktop only
139
+ */
140
+ startWatcher(): void
141
+ /**
142
+ * Stop listening for changes to the linked file. Desktop only
143
+ */
144
+ stopWatcher(): void
145
+ /**
146
+ * Generate the Java Block/Item folder property from the file path
147
+ */
148
+ generateFolder(): void
149
+ /**
150
+ * Loads the texture from it's current source
151
+ * @param cb Callback function
152
+ */
153
+ load(cb?: () => {}): this
154
+ fromJavaLink(link: string, path_array: string[]): this
155
+ fromFile(file: { name: string; content?: string; path: string }): this
156
+ fromPath(path: string): this
157
+ fromDataURL(data_url: string): this
158
+ fromDefaultPack(): true | undefined
159
+ /**
160
+ * Loads the default white error texture
161
+ * @param error_id Sets the error ID of the texture
162
+ */
163
+ loadEmpty(error_id?: number): this
164
+
165
+ updateSource(dataUrl: string): this
166
+ updateMaterial(): this
167
+
168
+ /**
169
+ * Opens a dialog to replace the texture with another file
170
+ * @param force If true, no warning appears of the texture has unsaved changes
171
+ */
172
+ reopen(force: boolean): void
173
+ /**
174
+ * Reloads the texture. Only works in the desktop app
175
+ */
176
+ reloadTexture(): void
177
+ getMaterial(): THREE.MeshLambertMaterial
178
+ select(event?: Event): this
179
+ /**
180
+ * Adds texture to the textures list and initializes it
181
+ * @param undo If true, an undo point is created
182
+ */
183
+ add(undo?: boolean): Texture
184
+ /**
185
+ * Removes the texture
186
+ * @param no_update If true, the texture is silently removed. The interface is not updated, no undo point is created
187
+ */
188
+ remove(no_update?: boolean): void
189
+ toggleVisibility(): this
190
+ enableParticle(): this
191
+ /**
192
+ * Enables 'particle' on this texture if it is not enabled on any other texture
193
+ */
194
+ fillParticle(): this
195
+ /**
196
+ * Applies the texture to the selected elements
197
+ * @param all If true, the texture is applied to all faces of the elements. If 'blank', the texture is only applied to blank faces
198
+ */
199
+ apply(all: true | false | 'blank'): this
200
+ /**
201
+ * Shows the texture file in the file explorer
202
+ */
203
+ openFolder(): this
204
+ /**
205
+ * Opens the texture in the configured image editor
206
+ */
207
+ openEditor(): this
208
+ showContextMenu(event: MouseEvent): void
209
+ openMenu(): void
210
+ resizeDialog(): this
211
+ /**
212
+ * Scroll the texture list to this texture
213
+ */
214
+ scrollTo(): void
215
+ save(as: any): this
216
+ /**
217
+ * Returns the content of the texture as PNG as a base64 encoded string
218
+ */
219
+ getBase64(): string
220
+ /**
221
+ * Returns the content of the texture as PNG as a base64 encoded data URL
222
+ */
223
+ getDataURL(): string
224
+ /**
225
+ * Wrapper to do edits to the texture.
226
+ * @param callback
227
+ * @param options Editing options
228
+ */
229
+ edit(
230
+ callback: (instance: HTMLCanvasElement | any) => void | HTMLCanvasElement,
231
+ options: TextureEditOptions
232
+ ): void
233
+ menu: Menu
234
+ /**
235
+ * Get the selected layer. If no layer is selected, returns the bottom layer
236
+ */
237
+ getActiveLayer(): TextureLayer
238
+ activateLayers(undo?: boolean): void
239
+ /**
240
+ * Turns the texture selection into a layer
241
+ * @param undo Whether to create an undo entry
242
+ * @param clone When true, the selection is copied into the new layer and also left on the original layer
243
+ */
244
+ selectionToLayer(undo?: boolean, clone?: boolean): void
245
+ javaTextureLink(): string
246
+
247
+ getMCMetaContent(): {
248
+ animation?: {
249
+ frametime: number
250
+ width?: number
251
+ height?: number
252
+ interpolate?: boolean
253
+ frames?: number[]
254
+ }
255
+ }
256
+ getAnimationFrameIndices(): number[]
257
+
258
+ exportEmissionMap(): void
259
+
260
+ convertToInternal(data_url?: string): this
261
+ /**
262
+ * Redraws the texture content from the layers
263
+ * @param update_data_url If true, the texture source gets updated as well. This is slower, but is necessary at the end of an edit. During an edit, to preview changes, this can be false
264
+ */
265
+ updateLayerChanges(update_data_url?: boolean): void
266
+ /**
267
+ * Update everything after a content edit to the texture or one of the layers. Updates the material, the layers, marks the texture as unsaved, syncs changes to other projects
268
+ */
269
+ updateChangesAfterEdit(): void
270
+ /**
271
+ * Update the attached img element with the content from the texture's canvas
272
+ */
273
+ updateImageFromCanvas(): void
274
+ /**
275
+ * If layers are enabled, returns the active layer, otherwise returns the texture. Either way, the 'canvas', 'ctx', and 'offset' properties can be used from the returned object
276
+ */
277
+ getActiveCanvas(): Texture | TextureLayer
278
+ /**
279
+ * When editing the same texture in different tabs (via Edit In Blockbench option), sync changes that were made to the texture to other projects
280
+ */
281
+ syncToOtherProject(): this
282
+
283
+ getUndoCopy(): Texture
284
+
285
+ static all: Texture[]
286
+ static getDefault(): Texture
179
287
  }
180
288
  /**
181
289
  * Saves all textures
182
290
  * @param lazy If true, the texture isn't saved if it doesn't have a local file to save to
183
291
  */
184
- declare function saveTextures(lazy?: boolean): void;
292
+ declare function saveTextures(lazy?: boolean): void
185
293
  /**
186
294
  * Update the draggable/sortable functionality of the texture list
187
295
  */
188
- declare function loadTextureDraggable(): void;
296
+ declare function loadTextureDraggable(): void
189
297
  /**
190
298
  * Unselect all textures
191
299
  */
192
- declare function unselectTextures(): void;
300
+ declare function unselectTextures(): void
301
+
302
+ /**
303
+ * An Int Matrix holds an int (unsigned 8 bit) for each pixel in a matrix, via array. The override property can be used to set an override value for the entire area. This is used for texture selections.
304
+ */
305
+ declare class IntMatrix {
306
+ constructor(width: number, height: number)
307
+ width: number
308
+ height: number
309
+ array: null | Int8Array
310
+ /**
311
+ * The override can be set to true to indicate that the whole texture is selected, or false, which indicates that nothing is selected. Null indicates a custom selection
312
+ */
313
+ override: boolean | null
314
+ /**
315
+ * True if there is a custom selection
316
+ */
317
+ readonly is_custom: boolean
318
+ /**
319
+ * The array does not exist by default to save memory, this activates it.
320
+ */
321
+ activate(): void
322
+ /**
323
+ * Get the value at the specified pixel
324
+ * @param x X coordinate
325
+ * @param y Y coordinate
326
+ * @returns The value of the targeted pixel
327
+ */
328
+ get(x: number, y: number): number | boolean
329
+ /**
330
+ * Test whether painting is allowed at a specific pixel
331
+ * @param x X coordinate
332
+ * @param y Y coordinate
333
+ * @returns Boolean or value of the pixel
334
+ */
335
+ allow(x: number, y: number): number | boolean
336
+ /**
337
+ * Get the value at the specified pixel directly without override and bounds check
338
+ * @param x X coordinate
339
+ * @param y Y coordinate
340
+ * @returns
341
+ */
342
+ getDirect(x: number, y: number): number
343
+ /**
344
+ * Return the smallest possible rectangle that contains all of the selection
345
+ * @param respect_empty If true, if there is no selection, the bounding box will still cover the entire area
346
+ */
347
+ getBoundingRect(respect_empty: boolean): Rectangle
348
+ /**
349
+ * Checks whether a selection is present and contains selected pixels
350
+ */
351
+ hasSelection(): boolean
352
+ /**
353
+ * Set the value at a specified pixel
354
+ * @param {*} x X coordinate
355
+ * @param {*} y Y coordinate
356
+ * @param {number} value
357
+ */
358
+ set(x: number, y: number, value: number): void
359
+ /**
360
+ * If there was a selection, whether override or not, clear it
361
+ */
362
+ clear(): void
363
+ /**
364
+ * Change override mode
365
+ * @param {true|false|null} value
366
+ * @returns
367
+ */
368
+ setOverride(value: boolean | null): void
369
+ /**
370
+ * Change the size of the matrix. Unless using overrides, the selection gets lost.
371
+ * @param {number} width
372
+ * @param {number} height
373
+ * @returns {boolean} Whether the size had to be changed
374
+ */
375
+ changeSize(width: number, height: number): void
376
+ /**
377
+ * Run a method on each pixel, whether selected or not
378
+ * @param callback Function to run per pixel
379
+ */
380
+ forEachPixel(callback: (x: number, y: number, value: number, index: number) => void): void
381
+ /**
382
+ * Shift custom selections by a specified offset
383
+ * @param offset_x
384
+ * @param offset_y
385
+ */
386
+ translate(offset_x: number, offset_y: number): void
387
+ /**
388
+ * Return the selection simplified into non-overlapping boxes. Boxes are [x, y, width, height].
389
+ */
390
+ toBoxes(): [number, number, number, number][]
391
+ /**
392
+ * Mask the provided canvas using the selection
393
+ * @param ctx Canvas 2D context
394
+ * @param offset Position offset of the canvas, e. g. when using a layer
395
+ */
396
+ maskCanvas(ctx: CanvasRenderingContext2D, offset: ArrayVector2): void
397
+ }
193
398
 
194
399
  /**
195
400
  * Handles playback of animated textures
196
401
  */
197
402
  declare namespace TextureAnimator {
198
- const isPlaying: boolean
199
- const interval: any
200
- function start(): void
201
- function stop(): void
202
- function toggle(): void
203
- function updateSpeed(): void
204
- function nextFrame(): void
205
- function reset(): void
206
- function updateButton(): void
207
- }
403
+ const isPlaying: boolean
404
+ const interval: any
405
+ function start(): void
406
+ function stop(): void
407
+ function toggle(): void
408
+ function updateSpeed(): void
409
+ function nextFrame(): void
410
+ function reset(): void
411
+ function updateButton(): void
412
+ }