Creating a Tweak
Create a TypeScript file in
blockbench-plugins/src/tweaks_n_stuff/src/tweaksIts recommended that this file have the same name as the ID of your tweak.
Inside the created file start by creating a class which extends any of the base tweak classes.
tsimport { ToggleTweak } from "./base"; class MyCustomTweak extends ToggleTweak { constructor() { super("my_custom_tweak", { author: "Author", category: "interface" }); } } new MyCustomTweak();Now add functionality to your tweak by overriding the
onEnable,onDisable,onInstall, andonUninstallmethods.Finally, Import your tweak in the
ts/tweaks/index.tsfile.
ts
import "./my_custom_tweak";Example
Blockbench's plugin example using tweaks.
ts
import { ToggleTweak } from "./base";
class RandomizeHeightTweak extends ToggleTweak {
constructor() {
super("height_randomizer", { author: "Wiki", category: "interface" });
}
onEnable() {
var button = new Action("randomize_height", {
icon: "bar_chart",
click: function () {
Undo.initEdit({ elements: Cube.selected });
Cube.selected.forEach((cube) => {
cube.to[1] = cube.from[0] + Math.floor(Math.random() * 8);
});
Canvas.updateView({
elements: Cube.selected,
element_aspects: { geometry: true },
selection: true,
});
Undo.finishEdit("Randomize cube height");
},
});
MenuBar.addAction(button, "filter");
this.deleteables.push(button);
}
}
// Register your tweak.
ToggleTweak.register(new CloseActionsTweak());json
{
"settings.randomize_height": "Height Randomizer",
"settings.randomize_height.desc": "This tweak can randomize the height of all selected cubes.",
"action.randomize_height": "Randomize Height",
"action.randomize_height.desc": "Randomize the height of all selected elements"
}