UNPKG

@bedrock-oss/stylish

Version:

A decorator package with for developing add-ons with Script API in Minecraft Bedrock Edition

80 lines (76 loc) 1.94 kB
// src/index.ts import { system, world } from "@minecraft/server"; // src/itemRegistry.ts var registry = []; function ItemComponent(ctor) { if (!ctor.componentId) { throw new Error(`Component ${ctor.name} is missing static componentId`); } registry.push(ctor); } function registerAllItemComponents(itemComponentRegistry) { for (const Ctor of registry) { itemComponentRegistry.registerCustomComponent( Ctor.componentId, new Ctor() ); } } // src/blockRegistry.ts var registry2 = []; function BlockComponent(ctor) { if (!ctor.componentId) { throw new Error(`Component ${ctor.name} is missing static componentId`); } registry2.push(ctor); } function registerAllBlockComponents(blockComponentRegistry) { for (const Ctor of registry2) { blockComponentRegistry.registerCustomComponent( Ctor.componentId, new Ctor() ); } } // src/autobind.ts function BindThis(_target, propertyKey, descriptor) { const original = descriptor.value; return { configurable: true, enumerable: descriptor.enumerable, get() { const bound = original.bind(this); Object.defineProperty(this, propertyKey, { value: bound, configurable: true, writable: true, enumerable: false }); return bound; } }; } // src/index.ts function initV1() { world.beforeEvents.worldInitialize.subscribe((e) => { registerAllComponents(e.itemComponentRegistry, e.blockComponentRegistry); }); } function initV2() { system.beforeEvents.startup.subscribe((e) => { registerAllComponents(e.itemComponentRegistry, e.blockComponentRegistry); }); } function registerAllComponents(itemRegistry, blockRegistry) { registerAllItemComponents(itemRegistry); registerAllBlockComponents(blockRegistry); } export { BindThis, BlockComponent, ItemComponent, initV1, initV2, registerAllComponents }; //# sourceMappingURL=index.mjs.map