From 20bb18035db1d2ec547d3c2ee8bc062b7c11fef0 Mon Sep 17 00:00:00 2001 From: Dedou3D Date: Tue, 7 Jul 2026 19:33:26 +0200 Subject: [PATCH] Add Hitbox Guard --- plugins.json | 11 +++ plugins/hitbox_guard/about.md | 21 ++++++ plugins/hitbox_guard/hitbox_guard.js | 102 +++++++++++++++++++++++++++ 3 files changed, 134 insertions(+) create mode 100644 plugins/hitbox_guard/about.md create mode 100644 plugins/hitbox_guard/hitbox_guard.js diff --git a/plugins.json b/plugins.json index fc512b28..37981221 100644 --- a/plugins.json +++ b/plugins.json @@ -1555,5 +1555,16 @@ "website": "https://svdex.moe", "min_version": "4.8.0", "has_changelog": true + }, + "hitbox_guard": { + "title": "Hitbox Guard", + "author": "Dedou3D", + "description": "Create a hitbox for your models.", + "icon": "select_all", + "version": "1.0.0", + "variant": "both", + "min_version": "4.0.0", + "new_repository_format": true, + "tags": ["Minecraft", "ModelEngine", "Utility"] } } diff --git a/plugins/hitbox_guard/about.md b/plugins/hitbox_guard/about.md new file mode 100644 index 00000000..01b70239 --- /dev/null +++ b/plugins/hitbox_guard/about.md @@ -0,0 +1,21 @@ +# Hitbox Guard + +Hitbox Guard creates a hitbox for your models. + +It adds a hidden `hitbox` folder with a hidden `hitbox` cube sized `14 x 32 x 14`, so entity models can keep a consistent hitbox marker without rebuilding it by hand. + +## What It Does + +- Creates or reuses a `hitbox` folder +- Creates a `hitbox` cube +- Uses a `14 x 32 x 14` size +- Keeps the folder and cube hidden +- Leaves the cube unlocked +- Replaces the previous `hitbox` cube when running the action again + +## Usage + +Open your model, then run: + +`Filter > Create Hitbox` + diff --git a/plugins/hitbox_guard/hitbox_guard.js b/plugins/hitbox_guard/hitbox_guard.js new file mode 100644 index 00000000..d8ae0a24 --- /dev/null +++ b/plugins/hitbox_guard/hitbox_guard.js @@ -0,0 +1,102 @@ +(function() { + 'use strict'; + + const PLUGIN_ID = 'hitbox_guard'; + const HITBOX_GROUP_NAME = 'hitbox'; + const HITBOX_CUBE_NAME = 'hitbox'; + const HITBOX_SIZE = Object.freeze({ + x: 14, + y: 32, + z: 14 + }); + + let createHitboxAction; + + function findHitboxGroup() { + return Group.all.find(group => group.name.toLowerCase() === HITBOX_GROUP_NAME.toLowerCase()) || null; + } + + function removeExistingHitbox(group) { + group.children + .filter(child => child instanceof Cube && child.name === HITBOX_CUBE_NAME) + .forEach(cube => cube.remove()); + } + + function createHitbox() { + if (!Project) { + Blockbench.showQuickMessage('Open or create a project first.'); + return; + } + + Undo.initEdit({outliner: true, elements: []}); + + let group = findHitboxGroup(); + if (!group) { + group = new Group({ + name: HITBOX_GROUP_NAME, + origin: [0, 0, 0] + }).init(); + } else { + group.visibility = true; + } + + removeExistingHitbox(group); + + const halfX = HITBOX_SIZE.x / 2; + const halfZ = HITBOX_SIZE.z / 2; + const cube = new Cube({ + name: HITBOX_CUBE_NAME, + from: [-halfX, 0, -halfZ], + to: [halfX, HITBOX_SIZE.y, halfZ], + origin: [0, 0, 0], + color: 3, + box_uv: true, + visibility: true, + locked: false + }); + + cube.addTo(group).init(); + Canvas.updateAll(); + + cube.visibility = false; + group.visibility = false; + Undo.finishEdit('Create hitbox'); + + if (Canvas.updateVisibility) { + Canvas.updateVisibility(); + } else { + Canvas.updateAll(); + } + group.select(); + Blockbench.showQuickMessage('Hitbox created: 14 x 32 x 14'); + } + + Plugin.register(PLUGIN_ID, { + title: 'Hitbox Guard', + author: 'Dedou3D', + description: 'Create a hitbox for your models.', + icon: 'select_all', + version: '1.0.0', + variant: 'both', + min_version: '4.0.0', + new_repository_format: true, + tags: ['Minecraft', 'ModelEngine', 'Utility'], + onload() { + createHitboxAction = new Action('create_hitbox_guard_hitbox', { + name: 'Create Hitbox', + description: 'Create a hidden 14 x 32 x 14 hitbox.', + icon: 'select_all', + category: 'edit', + click: createHitbox + }); + + MenuBar.addAction(createHitboxAction, 'filter'); + }, + onunload() { + if (createHitboxAction) { + createHitboxAction.delete(); + createHitboxAction = null; + } + } + }); +})();