// --- CONFIGURATION SETTINGS ---
const DOOR_SCROLL_CHANCE = 0.05;
const BED_SCROLL_CHANCE = 0.08;

// --- EVENT 1: INTERACTING WITH DOORS ---
BlockEvents.rightClicked(event => {
    const { block, player, level, server } = event;
    
    if (level.isClientSide()) return;

    if (block.hasTag('minecraft:doors')) {
        if (!block.blockState.getValue(BlockProperties.OPEN)) {
            if (Math.random() < DOOR_SCROLL_CHANCE) {
                // 1. Force the server to run the precise high-volume stalker mod command at the player's position
                server.runCommandSilent(`playsound stalker:throw player ${player.username} ${player.x} ${player.y} ${player.z} 557 0.5`);
                
                // 2. Alert the player above their hotbar
                player.displayClientMessage(Component.darkRed("This is the wrong room."), true);
                
                // 3. Prevent the door from opening
                event.cancel();
            }
        }
    }
});

// --- EVENT 2: TRYING TO SLEEP ---
BlockEvents.rightClicked(event => {
    const { block, player, level, server } = event;
    
    if (level.isClientSide()) return;

    if (block.hasTag('minecraft:beds')) {
        if (Math.random() < BED_SCROLL_CHANCE) {
            // 1. Bumps up the default cave ambient volume and drops pitch down significantly to sound monstrous
            server.runCommandSilent(`playsound stalker:go_throw master ${player.username} ${player.x} ${player.y} ${player.z} 100 0.4`);
            
            // 2. Alert the player above their hotbar
            player.displayClientMessage(Component.darkRed("You hear its song."), true);
            
            // 3. Stop them from sleeping
            event.cancel();
        }
    }
});