import { world } from "@minecraft/server";
export class SpawnEggBlock {
    // Constructor to initialize a SpawnEggBlock with its properties
    constructor({ id, entity }) {
        this.id = id;
        this.entity = entity;
    }
    static registerBehavior(config) {
        const block = new SpawnEggBlock(config);
        this.register(block);
    }
    // Method to register a SpawnEggBlock
    static register(block) {
        SpawnEggBlock.blocks.push(block);
    }
    // Initialization method to handle block placement and summon entities
    static initialize() {
        world.afterEvents.playerPlaceBlock.subscribe((e) => {
            const { location } = e.block; // Get the location where the block was placed
            // Loop through all registered SpawnEggBlocks
            for (const entity of SpawnEggBlock.blocks) {
                // Check if the placed block matches any registered spawn egg block
                if (e.block.permutation.matches(entity.id)) {
                    // Summon the corresponding entity at the block's location
                    e.player.runCommandAsync(`summon ${entity.entity} ${location.x} ${location.y} ${location.z} 180 0 minecraft:entity_spawned`);
                    // Replace the block with air after summoning the entity
                    e.block.dimension.runCommandAsync(`setblock ${location.x} ${location.y} ${location.z} air`);
                }
            }
        });
    }
}
// Array to store all registered SpawnEggBlock instances
SpawnEggBlock.blocks = [];
