import { world } from '@minecraft/server';

const summon_entity = {
    onPlace(event) {
        const block = event.block;
        const { x, y, z } = block.location;
        const dimension = block.dimension;
        if (block.typeId.includes("cabinet")) {
            dimension.runCommandAsync(`summon furnideco:storage \"Cabinet\" ${x + 0.5} ${y + 0.5} ${z + 0.5}`);
        } else if (block.typeId.includes("globe")) {
            dimension.runCommandAsync(`summon furnideco:globe_entity ${x} ${y} ${z}`);
        } else if (block.typeId.includes("mailbox")) {
            dimension.runCommandAsync(`summon furnideco:mailbox_entity \"Mailbox\" ${x} ${y + 0.75} ${z}`);
        }

    }
};

world.beforeEvents.worldInitialize.subscribe(({ blockComponentRegistry }) => {
    blockComponentRegistry.registerCustomComponent(
        "furnideco:summon_entity",
        summon_entity
    );
});