import { system, world, Vector3, BlockVolume, BlockTypes } from "@minecraft/server";

world.afterEvents.playerInteractWithBlock.subscribe((herobrine) => {

    system.run(() => {
        const block = herobrine.block;
        const location = block.location;
        const blockType = block.typeId;
        const itemStack = herobrine.itemStack;
        const player = herobrine.player;
        const dimension = player.dimension;
        const originX = {
            x: location.x - 1, y: location.y - 1, z: location.z - 1
        };
        const originZ = { x: location.x + 1, y: location.y - 1, z: location.z + 1 };
        const blockVolume = new BlockVolume(originX, originZ);

        if (blockType === "minecraft:netherrack" && itemStack.typeId === "minecraft:flint_and_steel") {
            const blocks = dimension.containsBlock(blockVolume, { includeTypes: ["minecraft:gold_block"] });
            const notBlocks = dimension.containsBlock(blockVolume, { excludeTypes: ["minecraft:gold_block"] });
            if (blocks.valueOf() == true, notBlocks.valueOf() == false) {
                dimension.spawnEntity("stupidstuff:herobrine", location);
                dimension.fillBlocks(blockVolume, "minecraft:mossy_cobblestone");
                dimension.setBlockType(location, "minecraft:brick_block");
                dimension.spawnEntity("minecraft:lightning_bolt", location);
                world.sendMessage("§eHerobrine has joined the game");
            };
        };
    })

})