Blockbench
The Blockbench object provides useful variables and methods to interact with general functionality of Blockbench.
Information
Blockbench.isWebtrue if Blockbench is used in a web browserBlockbench.isMobiletrue if Blockbench is used in the mobile versionBlockbench.versionThe installed version of BlockbenchBlockbench.openTimeDate object of the time Blockbench was opened
Flags
Flags can be used to save a binary state within an instance of Blockbench.
Blockbench.addFlag( flag: String )
Blockbench.removeFlag( flag: String )
Blockbench.hasFlag( flag: String )
Import
Blockbench.import( options: Object, callback: function )
Opens the file import dialog and reads the file.
optionsstartpathPath where to start the file dialog. Only works on desktoptypeName of the file type. If unset, it will use the first extensionextensionsArray of extensions that can be importedmultipleIf true, multiple files can be selected and loadedreadtypeHow to read the imported files. Can beimage,bufferortext(default).titleTitle to use for the import dialog. Only works on desktop.errorboxWhether to display an error dialog if Blockbench can't load the file
callbackCalled after all files have been read.files: ArrayImported and read filespathPath to the file. Will only return the name in the web appnameFile namecontentContent of the file. String for plain text files, base64 string for images (only .tga images or images on the web app)
Blockbench.read( paths, options, callback )
Reads one or multiple files at a fixed path. Only available on desktop app.
paths: ArrayList of file paths.options: ObjectImport options.readtype: StringHow to read the imported files. Can beimage,bufferortext(default).errorbox: BooleanWhether to display an error dialog if Blockbench can't load the file
callback: Function. Called after all files have been read.files: Array of imported and read filespath: StringPath to the file. Will only return the name in the web appname: StringFile namecontent: StringContent of the file. String for plain text files, base64 string for images (only .tga images or images on the web app)
Export
Blockbench.export( options, callback )
Opens a file save dialog to ask where to save the file. In most browsers, the file will just get downloaded with the default name.
options: ObjectstartpathPath where to start the file dialog. Only works on desktoptypeName of the file typeextensionsArray of possible extensionsnameSuggested file name. Gets overwritten by startpath.contentContent of the file. Can be a string for plain text files or a base64 string or path for images.savetypeHow to save the file. Can betext(default),imageorzip.custom_writerIn the desktop app, you can use this to create a custom function to save the file. This can be used to merge with the old file for example. Has two arguments:contentandpath.
callback: Function. Called after the file has been exported.pathThe path the file has been exported to. Only on desktop app.
Blockbench.writeFile( path, options, callback )
Writes a file at the specified path.
path: File pathoptions: ObjectcontentContent of the file. Can be a string for plain text files or a base64 string or path for images.savetypeHow to save the file. Can betext(default),imageorzip.custom_writerIn the desktop app, you can use this to create a custom function to save the file. This can be used to merge with the old file for example. Has two arguments:contentandpath.
callback: Function. Called after the file has been exported.pathThe path the file has been exported to.
Events
Listen to and dispatch Blockbench-specific events
Blockbench.on( event_id, callback )
Runs a function when Blockbench emits a specific event
event_idEvent to listen forcallbackFunction to execute. Has one argumentdata.
Blockbench.dispatchEvent( event_id, data )
Triggers an event.
event_idName of the event,dataData to submit to the listeners
Blockbench.removeListener( event_id, callback)
Removes an event listener using the event_id and callback. Should be used in onunload in a plugin to clear event listeners.
List of Blockbench events
| Event ID | Description |
|---|---|
remove_animation | Emitted after a user removes an animation |
display_animation_frame | Emitted when Blockbench renders a frame of an animation |
before_closing | |
create_session | User creates an edit session |
join_session | User joins an edit session |
quit_session | User quits an edit session |
send_session_data | Session data is transmitted, e. G. for chat communication or model edits |
receive_session_data | Session data is received |
user_joins_session | User joins a session |
user_leaves_session | User leaves a session |
process_chat_message | |
update_settings | The settings are updated |
update_project_settings | The project settings are updated |
save_project | A project is saved as bbmodel |
load_project | A project is loaded from bbmodel |
new_project | A new project was created |
close_project | A project is closed |
saved_state_changed | A project gets marked as either saved or unsaved |
add_cube | A new cube is added via Add Cube |
add_mesh | A new mesh is added via Add Mesh |
add_group | A new group is added via Add Group |
add_texture_mesh | A new texture mesh is added via Add Texture Mesh |
group_elements | The selected are wrapped into a new group via Group Elements |
update_selection | The selection was changed and the interface gets updated |
update_keyframe_selection | The keyframe selection was changed and the interface gets updated |
select_all | The select all action was used to select all of something, depending on context |
added_to_selection | An element was selected or added to the selection |
invert_selection | The selection was inverted |
canvas_select | An element is selected by clicking in the 3D viewport |
canvas_click | |
change_texture_path | The source file of a texture was changed |
add_texture | A texture was imported |
finish_edit | An edit was just finished |
finished_edit | An edit was just finished and added to the undo history |
undo | User used Undo |
redo | User used Redo |
load_undo_save | The state of an undo save is loaded |
change_color | The main color got changed |
select_mode | A mode got selected |
unselect_mode | A mode got unselected |
change_active_panel | The panel that the user is active in was changed, e. G. by clicking inside a new panel |
resize_window | The window size is updated, by resizing the window or updating sidebars, etc. |
press_key | A key was pressed |
select_format | A format was selected |
convert_format | A model is converted into another format |
construct_format | A new format is created by a plugin |
delete_format | A format is deleted by a plugin, e. G. through uninstalling |
select_project | User selected a project |
unselect_project | User unselected a project |
setup_project | A new project is set up to load a model from a file or session |
update_project_resolution | The project texture resolution is changed |
merge_project | A project is merged into another project |
update_view | The view is updated by using the Canvas.updateView API |
update_camera_position | The camera position is updated |
render_frame | A frame was rendered |
construct_model_loader | A new model loader is created by a plugin |
delete_model_loader | A model loader is deleted by a plugin, e. G. through uninstalling |
update_recent_project_data | The list of recent projects and their data is getting updated |
update_recent_project_thumbnail | The recent project thumbnail of a project is getting updated |
load_from_recent_project_data | Cached data such as textures and animation are loaded from a recent project entry |
edit_animation_properties | The properties of an animaiton were edited by user |
select_preview_scene | A preview scene was selected |
unselect_preview_scene | A preview scene was unselected |
Drag and Drop Files
Blockbench.addDragHandler( id, options, callback )
Handles file drop events for the specified file types
idID of the handleroptions: ObjecctextensionsArray of extensions that will trigger this handlerelementaddClasspropagatereadtypeHow to read the dropped files. See Blockbench.readerrorboxWhether to show an error message if Blockbench fails to load the file.
callback: Function. Called after all files have been read.files: Array of imported and read filespathPath to the file. Will only return the name in the web appnameFile namecontentContent of the file. String for plain text files, base64 string for images (only .tga images or images on the web app)
Blockbench.removeDragHandler( id )
Removes and disables a drag handler using its ID.
Icons
Icons are used throughout Blockbench in actions, menus and plugins. Google Material icons, Font Awesome Regular, Solid and Brands as well as a set of custom Blockbench icons are available.
Blockbench.getIconNode( string[, color])
Returns a HTML node for the specified icon.
stringSpecifies the pack and name of the icon.- Strings starting with fa return Font Awesome icons. Example:
'fa-bone' - Prepend
far.orfas.to choose between regular and solid icons. Example:'fas.fa-circle' - Regular strings will return a Google Materials Icon
- Strings starting with
icon-will return custom Blockbench icons (see list below) - Base64 image strings will return an image/texture in icon format
- Passing a function will run the function and use the return value to determine the icon
- If undefined, it will return a question mark icon
- Strings starting with fa return Font Awesome icons. Example:
colorOptional. Colors the icon in a specific color. Can bex,yorzfor a generic axis color or a CSS color string for a custom color.
Available Icons
- Google Material Icons
- Font Awesome Free Icons
- Custom Blockbench icons:
icon-mirror_xicon-mirror_yicon-mirror_zicon-savedicon-playericon-player_headicon-zombieicon-baby_zombieicon-armor_standicon-armor_stand_smallicon-groundicon-hudicon-inventory_fullicon-inventory_nineicon-inventory_singleicon-bowicon-crossbowicon-x11icon-blockbenchicon-blockbench_invertedicon-vertexsnapicon-create_bitmapicon-objectsicon-bb_interfaceicon-sketchfabicon-optifine_fileicon-format_bedrockicon-format_blockicon-format_freeicon-format_javaicon-format_optifineicon-format_bedrock_legacy