Blockbench Reference Docs
    Preparing search index...

    Module custom/shared_actions

    Shared Actions is a system in Blockbench to allow actions (including in toolbars, menus, via action control, or keybinding) to run different code in different cases, such as in different modes or different panels. As an example, the "Duplicate" action runs code to duplicate elements when used in the outliner, and duplicates textures when used in the textures panel.

    Handlers can be added for existing actions like this:

    // Duplicate layers when using "Duplicate" in the layers panel
    SharedActions.add('duplicate', {
    subject: 'layer',
    condition: () => Prop.active_panel == 'layers' && TextureLayer.selected,
    run() {
    let texture = Texture.selected;
    let original = texture.getActiveLayer();
    let copy = original.getUndoCopy(true);
    copy.name += '-copy';
    Undo.initEdit({textures: [texture]});
    let layer = new TextureLayer(copy, texture);
    layer.addForEditing();
    Undo.finishEdit('Duplicate layer');
    }
    })

    Namespaces

    SharedActions

    Interfaces

    SharedActionHandler

    Type Aliases

    SharedActionID