Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
}
}
21 changes: 21 additions & 0 deletions plugins/hitbox_guard/about.md
Original file line number Diff line number Diff line change
@@ -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`

102 changes: 102 additions & 0 deletions plugins/hitbox_guard/hitbox_guard.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
});
})();
Loading