refactor(cli): migrate construct command into Command pipeline and split itemUse handler

This commit is contained in:
ForestOfLight
2026-05-19 21:21:32 -07:00
Unverified
parent aae9fd2f4b
commit 4d07e2e1ae
6 changed files with 72 additions and 54 deletions
@@ -0,0 +1,27 @@
import { world, system } from '@minecraft/server';
import { MENU_ITEM } from '../consts';
import { MenuForm } from './MenuForm';
import { structureCollection } from './Structure/StructureCollection';
import { Builders } from './Builder/Builders';
world.beforeEvents.itemUse.subscribe((event) => {
if (!event.source || event.itemStack?.typeId !== MENU_ITEM) return;
event.cancel = true;
const builder = Builders.get(event.source.id);
system.run(() => {
if (builder.isFlexibleInstanceMoving())
return;
openMenu(event.source, event);
});
});
function openMenu(player, event = void 0) {
const options = { jumpToInstance: true };
if (event) {
const instanceNames = structureCollection.getInstanceNames();
const instanceName = event.itemStack?.nameTag;
if (instanceNames.includes(instanceName))
options.instanceName = instanceName;
}
new MenuForm(player, options);
}