+
{{ selectionStatus() }}
+
+
+
+
+
+
+
+
+
+
+ `,
+ },
+ });
+}
+
+/**
+ * @param {number} tintIndex
+ * @param {string} color
+ */
+function applyTintToSelection(tintIndex, color) {
+ const selection = getSelectedCubeFaces();
+ if (!selection.faces.length) {
+ Blockbench.showQuickMessage(addTintText('select_faces'), 2500);
+ return;
+ }
+
+ const index = Math.max(0, Math.round(tintIndex));
+ saveTintColor(index, color);
+ Undo.initEdit({elements: selection.cubes, uv_only: true});
+ selection.faces.forEach(({cube, faceKey}) => {
+ cube.faces[faceKey].tint = index;
+ });
+ Undo.finishEdit(addTintText('undo_set_tint', {index}));
+ refreshTintPreview();
+ Blockbench.showQuickMessage(
+ addTintText('tint_applied', {index, count: selection.faces.length}),
+ 2200,
+ );
+}
+
+function removeTintFromSelection() {
+ const selection = getSelectedCubeFaces();
+ if (!selection.faces.length) {
+ Blockbench.showQuickMessage(addTintText('select_faces'), 2500);
+ return;
+ }
+
+ Undo.initEdit({elements: selection.cubes, uv_only: true});
+ selection.faces.forEach(({cube, faceKey}) => {
+ cube.faces[faceKey].tint = -1;
+ });
+ Undo.finishEdit(addTintText('undo_remove_tint'));
+ refreshTintPreview();
+ Blockbench.showQuickMessage(
+ addTintText('tint_removed', {count: selection.faces.length}),
+ 2200,
+ );
+}
+
+function openAddTintDialog() {
+ const selection = getSelectedCubeFaces();
+ if (!selection.faces.length) {
+ Blockbench.showQuickMessage(addTintText('select_faces'), 2500);
+ return;
+ }
+
+ const firstFace = selection.faces[0].cube.faces[selection.faces[0].faceKey];
+ const initialIndex = firstFace.tint >= 0 ? firstFace.tint : 0;
+
+ new Dialog({
+ id: 'add_tint_dialog',
+ title: 'addTint',
+ icon: 'format_color_fill',
+ form: {
+ mode: {
+ label: addTintText('operation'),
+ type: 'select',
+ value: 'apply',
+ options: {
+ apply: addTintText('apply_update_tint'),
+ remove: addTintText('remove_tint'),
+ },
+ },
+ tint_index: {
+ label: addTintText('tint_index_label'),
+ description: addTintText('tint_index_description'),
+ type: 'number',
+ value: initialIndex,
+ min: 0,
+ step: 1,
+ force_step: true,
+ },
+ preview_color: {
+ label: addTintText('preview_color'),
+ description: addTintText('preview_color_description'),
+ type: 'color',
+ value: getTintColor(initialIndex),
+ },
+ preview_enabled: {
+ label: addTintText('enable_preview'),
+ type: 'checkbox',
+ value: isPreviewEnabled(),
+ },
+ note: {
+ type: 'info',
+ text: addTintText('preview_note'),
+ },
+ },
+ onConfirm(result) {
+ savePreviewEnabled(Boolean(result.preview_enabled));
+ if (result.mode === 'remove') {
+ removeTintFromSelection();
+ } else {
+ applyTintToSelection(Number(result.tint_index), String(result.preview_color));
+ }
+ refreshTintPreview();
+ },
+ }).show();
+}
+
+function registerAddTintListeners() {
+ addTintListeners.push(
+ Blockbench.addListener('update_view', () => {
+ if (isJavaModel() && isPreviewEnabled()) Cube.all.forEach(applyTintPreview);
+ }),
+ Blockbench.addListener('finished_edit', refreshTintPreview),
+ Blockbench.addListener('undo', refreshTintPreview),
+ Blockbench.addListener('redo', refreshTintPreview),
+ Blockbench.addListener('select_project', refreshTintPreview),
+ Blockbench.addListener('update_settings', refreshTintPreview),
+ Blockbench.addListener('update_selection', refreshAddTintPanel),
+ Blockbench.addListener('finished_selection_change', refreshAddTintPanel),
+ Blockbench.addListener('finished_edit', refreshAddTintPanel),
+ );
+}
+
+// @ts-expect-error The DOM `Plugin` type shadows Blockbench's global Plugin API.
+Plugin.register('add_tint', {
+ title: 'addTint',
+ author: 'YOHEMAL',
+ description: addTintText('plugin_description'),
+ icon: 'format_color_fill',
+ version: '0.4.2',
+ min_version: '5.0.0',
+ variant: 'both',
+ tags: ['Minecraft: Java Edition', 'Utility'],
+
+ onload() {
+ addTintAction = new Action('add_tint_open', {
+ name: addTintText('action_set_tint'),
+ description: addTintText('action_set_tint_description'),
+ icon: 'format_color_fill',
+ category: 'filter',
+ condition: () => isJavaModel() && Cube.selected.length > 0,
+ click: openAddTintDialog,
+ });
+ MenuBar.addAction(addTintAction, 'filter');
+
+ grayscaleTintAction = new Action('add_tint_grayscale_textures', {
+ name: addTintText('action_grayscale'),
+ description: addTintText('action_grayscale_description'),
+ icon: 'filter_b_and_w',
+ category: 'filter',
+ condition: () => isJavaModel() && Cube.selected.length > 0,
+ click: openGrayscaleTintDialog,
+ });
+ MenuBar.addAction(grayscaleTintAction, 'filter');
+
+ editTintColorsAction = new Action('add_tint_edit_preview_colors', {
+ name: addTintText('action_edit_colors'),
+ description: addTintText('action_edit_colors_description'),
+ icon: 'palette',
+ category: 'filter',
+ condition: () => isJavaModel() && Cube.all.length > 0,
+ click: openTintColorEditor,
+ });
+ MenuBar.addAction(editTintColorsAction, 'filter');
+
+ registerUvContextMenu();
+ registerAddTintPanel();
+
+ registerAddTintListeners();
+ refreshTintPreview();
+ },
+
+ onunload() {
+ addTintListeners.forEach((listener) => listener.delete());
+ addTintListeners = [];
+ addTintAction?.delete();
+ addTintAction = undefined;
+ grayscaleTintAction?.delete();
+ grayscaleTintAction = undefined;
+ editTintColorsAction?.delete();
+ editTintColorsAction = undefined;
+ if (addTintUvContextMenuRegistered) {
+ UVEditor.menu.removeAction('add_tint_uv_context');
+ addTintUvContextMenuRegistered = false;
+ }
+ addTintPanel?.delete();
+ addTintPanel = undefined;
+ addTintPanelStyles?.delete();
+ addTintPanelStyles = undefined;
+ disposeTintMaterials();
+
+ if (Project && Cube.all) {
+ Cube.all.forEach((cube) => cube.preview_controller.updateFaces(cube));
+ }
+ },
+});