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

// Simple temple rune system - NO ESSENCE REQUIRED
let activeTemples = new Map();
let lastCheck = 0;

// Convert blocks - MASSIVE CONVERSION
function convertBlocks(position, dimension) {
    const conversions = {
        // Terrain blocks
        'minecraft:grass_block': 'myw:ancient_mythril_grass',
        'minecraft:dirt': 'myw:ancient_mythril_dirt',
        'minecraft:coarse_dirt': 'myw:ancient_mythril_dirt',
        'minecraft:podzol': 'myw:ancient_mythril_dirt',
        'minecraft:rooted_dirt': 'myw:ancient_mythril_dirt',
        'minecraft:mycelium': 'myw:ancient_mythril_grass',
        'minecraft:crimson_nylium': 'myw:ancient_mythril_grass',
        'minecraft:warped_nylium': 'myw:ancient_mythril_grass',
        
        // All logs
        'minecraft:oak_log': 'myw:ancient_mythril_log',
        'minecraft:birch_log': 'myw:ancient_mythril_log',
        'minecraft:spruce_log': 'myw:ancient_mythril_log',
        'minecraft:jungle_log': 'myw:ancient_mythril_log',
        'minecraft:acacia_log': 'myw:ancient_mythril_log',
        'minecraft:dark_oak_log': 'myw:ancient_mythril_log',
        'minecraft:mangrove_log': 'myw:ancient_mythril_log',
        'minecraft:cherry_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_oak_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_birch_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_spruce_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_jungle_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_acacia_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_dark_oak_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_mangrove_log': 'myw:ancient_mythril_log',
        'minecraft:stripped_cherry_log': 'myw:ancient_mythril_log',
        'minecraft:crimson_stem': 'myw:ancient_mythril_log',
        'minecraft:warped_stem': 'myw:ancient_mythril_log',
        'minecraft:stripped_crimson_stem': 'myw:ancient_mythril_log',
        'minecraft:stripped_warped_stem': 'myw:ancient_mythril_log',
        
        // All leaves
        'minecraft:oak_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:birch_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:spruce_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:jungle_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:acacia_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:dark_oak_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:mangrove_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:cherry_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:crimson_hyphae': 'myw:ancient_mythril_leaves',
        'minecraft:warped_hyphae': 'myw:ancient_mythril_leaves',
        'minecraft:stripped_crimson_hyphae': 'myw:ancient_mythril_leaves',
        'minecraft:stripped_warped_hyphae': 'myw:ancient_mythril_leaves',
        'minecraft:nether_wart_block': 'myw:ancient_mythril_leaves',
        'minecraft:warped_wart_block': 'myw:ancient_mythril_leaves',
        
        // All plants
        'minecraft:grass': 'myw:ancient_mythril_talor',
        'minecraft:fern': 'myw:ancient_mythril_sapplig',
        'minecraft:dead_bush': 'myw:ancient_mythril_emberlon',
        'minecraft:dandelion': 'myw:ancient_mythril_talor',
        'minecraft:poppy': 'myw:ancient_mythril_sapplig',
        'minecraft:blue_orchid': 'myw:ancient_mythril_emberlon',
        'minecraft:allium': 'myw:ancient_mythril_talor',
        'minecraft:azure_bluet': 'myw:ancient_mythril_sapplig',
        'minecraft:red_tulip': 'myw:ancient_mythril_emberlon',
        'minecraft:orange_tulip': 'myw:ancient_mythril_talor',
        'minecraft:white_tulip': 'myw:ancient_mythril_sapplig',
        'minecraft:pink_tulip': 'myw:ancient_mythril_emberlon',
        'minecraft:oxeye_daisy': 'myw:ancient_mythril_talor',
        'minecraft:cornflower': 'myw:ancient_mythril_sapplig',
        'minecraft:lily_of_the_valley': 'myw:ancient_mythril_emberlon',
        'minecraft:sunflower': 'myw:ancient_mythril_talor',
        'minecraft:lilac': 'myw:ancient_mythril_sapplig',
        'minecraft:rose_bush': 'myw:ancient_mythril_emberlon',
        'minecraft:peony': 'myw:ancient_mythril_talor',
        'minecraft:tall_grass': 'myw:ancient_mythril_sapplig',
        'minecraft:large_fern': 'myw:ancient_mythril_emberlon',
        'minecraft:crimson_fungus': 'myw:ancient_mythril_emberlon',
        'minecraft:warped_fungus': 'myw:ancient_mythril_talor',
        'minecraft:crimson_roots': 'myw:ancient_mythril_sapplig',
        'minecraft:warped_roots': 'myw:ancient_mythril_emberlon',
        'minecraft:nether_sprouts': 'myw:ancient_mythril_talor',
        'minecraft:weeping_vines': 'myw:ancient_mythril_sapplig',
        'minecraft:twisting_vines': 'myw:ancient_mythril_emberlon',
        'minecraft:vine': 'myw:ancient_mythril_sapplig',
        'minecraft:glow_lichen': 'myw:ancient_mythril_talor',
        'minecraft:moss_carpet': 'myw:ancient_mythril_sapplig',
        'minecraft:small_dripleaf': 'myw:ancient_mythril_emberlon',
        'minecraft:big_dripleaf': 'myw:ancient_mythril_talor',
        'minecraft:spore_blossom': 'myw:ancient_mythril_sapplig',
        'minecraft:azalea': 'myw:ancient_mythril_emberlon',
        'minecraft:flowering_azalea': 'myw:ancient_mythril_talor',
        'minecraft:mangrove_propagule': 'myw:ancient_mythril_sapplig',
        'minecraft:cherry_sapling': 'myw:ancient_mythril_emberlon',
        'minecraft:oak_sapling': 'myw:ancient_mythril_talor',
        'minecraft:birch_sapling': 'myw:ancient_mythril_sapplig',
        'minecraft:spruce_sapling': 'myw:ancient_mythril_emberlon',
        'minecraft:jungle_sapling': 'myw:ancient_mythril_talor',
        'minecraft:acacia_sapling': 'myw:ancient_mythril_sapplig',
        'minecraft:dark_oak_sapling': 'myw:ancient_mythril_emberlon',
        'minecraft:red_mushroom': 'myw:ancient_mythril_talor',
        'minecraft:brown_mushroom': 'myw:ancient_mythril_sapplig',
        'minecraft:crimson_fungus': 'myw:ancient_mythril_emberlon',
        'minecraft:warped_fungus': 'myw:ancient_mythril_talor',
        
        // Stone blocks
        'minecraft:stone': 'myw:ancient_mythril_bricks',
        'minecraft:cobblestone': 'myw:ancient_mythril_bricks_2',
        'minecraft:stone_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:mossy_stone_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:cracked_stone_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:chiseled_stone_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:granite': 'myw:ancient_mythril_bricks',
        'minecraft:polished_granite': 'myw:ancient_mythril_bricks_2',
        'minecraft:diorite': 'myw:ancient_mythril_bricks',
        'minecraft:polished_diorite': 'myw:ancient_mythril_bricks_2',
        'minecraft:andesite': 'myw:ancient_mythril_bricks',
        'minecraft:polished_andesite': 'myw:ancient_mythril_bricks_2',
        'minecraft:deepslate': 'myw:ancient_mythril_bricks',
        'minecraft:cobbled_deepslate': 'myw:ancient_mythril_bricks_2',
        'minecraft:deepslate_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:cracked_deepslate_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:deepslate_tiles': 'myw:ancient_mythril_bricks',
        'minecraft:cracked_deepslate_tiles': 'myw:ancient_mythril_bricks_2',
        'minecraft:chiseled_deepslate': 'myw:ancient_mythril_bricks_2',
        'minecraft:calcite': 'myw:ancient_mythril_bricks',
        'minecraft:tuff': 'myw:ancient_mythril_bricks_2',
        'minecraft:dripstone_block': 'myw:ancient_mythril_bricks',
        'minecraft:pointed_dripstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:basalt': 'myw:ancient_mythril_bricks',
        'minecraft:polished_basalt': 'myw:ancient_mythril_bricks_2',
        'minecraft:smooth_basalt': 'myw:ancient_mythril_bricks',
        'minecraft:blackstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:polished_blackstone': 'myw:ancient_mythril_bricks',
        'minecraft:polished_blackstone_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:cracked_polished_blackstone_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:chiseled_polished_blackstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:gilded_blackstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:netherrack': 'myw:ancient_mythril_bricks',
        'minecraft:crimson_nylium': 'myw:ancient_mythril_grass',
        'minecraft:warped_nylium': 'myw:ancient_mythril_grass',
        'minecraft:nether_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:cracked_nether_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:chiseled_nether_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:red_nether_bricks': 'myw:ancient_mythril_bricks',
        'minecraft:end_stone': 'myw:ancient_mythril_bricks',
        'minecraft:end_stone_bricks': 'myw:ancient_mythril_bricks_2',
        'minecraft:purpur_block': 'myw:ancient_mythril_bricks',
        'minecraft:purpur_pillar': 'myw:ancient_mythril_bricks_2',
        'minecraft:obsidian': 'myw:ancient_mythril_bricks',
        'minecraft:crying_obsidian': 'myw:ancient_mythril_bricks_2',
        'minecraft:respawn_anchor': 'myw:ancient_mythril_bricks',
        'minecraft:ancient_debris': 'myw:ancient_mythril_bricks',
        'minecraft:netherite_block': 'myw:ancient_mythril_bricks_2',
        
        // Sand and gravel
        'minecraft:sand': 'myw:ancient_mythril_dirt',
        'minecraft:red_sand': 'myw:ancient_mythril_dirt',
        'minecraft:sandstone': 'myw:ancient_mythril_bricks',
        'minecraft:chiseled_sandstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:cut_sandstone': 'myw:ancient_mythril_bricks',
        'minecraft:smooth_sandstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:red_sandstone': 'myw:ancient_mythril_bricks',
        'minecraft:chiseled_red_sandstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:cut_red_sandstone': 'myw:ancient_mythril_bricks',
        'minecraft:smooth_red_sandstone': 'myw:ancient_mythril_bricks_2',
        'minecraft:gravel': 'myw:ancient_mythril_dirt',
        'minecraft:clay': 'myw:ancient_mythril_dirt',
        'minecraft:terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:white_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:orange_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:magenta_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:light_blue_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:yellow_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:lime_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:pink_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:gray_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:light_gray_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:cyan_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:purple_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:blue_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:brown_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:green_terracotta': 'myw:ancient_mythril_bricks',
        'minecraft:red_terracotta': 'myw:ancient_mythril_bricks_2',
        'minecraft:black_terracotta': 'myw:ancient_mythril_bricks',
        
        // Concrete
        'minecraft:white_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:orange_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:magenta_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:light_blue_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:yellow_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:lime_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:pink_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:gray_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:light_gray_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:cyan_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:purple_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:blue_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:brown_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:green_concrete': 'myw:ancient_mythril_bricks_2',
        'minecraft:red_concrete': 'myw:ancient_mythril_bricks',
        'minecraft:black_concrete': 'myw:ancient_mythril_bricks_2',
        
        // Wool
        'minecraft:white_wool': 'myw:ancient_mythril_bricks',
        'minecraft:orange_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:magenta_wool': 'myw:ancient_mythril_bricks',
        'minecraft:light_blue_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:yellow_wool': 'myw:ancient_mythril_bricks',
        'minecraft:lime_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:pink_wool': 'myw:ancient_mythril_bricks',
        'minecraft:gray_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:light_gray_wool': 'myw:ancient_mythril_bricks',
        'minecraft:cyan_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:purple_wool': 'myw:ancient_mythril_bricks',
        'minecraft:blue_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:brown_wool': 'myw:ancient_mythril_bricks',
        'minecraft:green_wool': 'myw:ancient_mythril_bricks_2',
        'minecraft:red_wool': 'myw:ancient_mythril_bricks',
        'minecraft:black_wool': 'myw:ancient_mythril_bricks_2',
        
        // Leaves and organic blocks
        'minecraft:azalea_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:flowering_azalea_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:mangrove_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:cherry_leaves': 'myw:ancient_mythril_leaves',
        'minecraft:azalea': 'myw:ancient_mythril_leaves',
        'minecraft:flowering_azalea': 'myw:ancient_mythril_leaves',
        'minecraft:moss_block': 'myw:ancient_mythril_grass',
        'minecraft:moss_carpet': 'myw:ancient_mythril_grass',
        'minecraft:sculk': 'myw:ancient_mythril_bricks',
        'minecraft:sculk_vein': 'myw:ancient_mythril_bricks_2',
        'minecraft:sculk_catalyst': 'myw:ancient_mythril_bricks',
        'minecraft:sculk_shrieker': 'myw:ancient_mythril_bricks_2',
        'minecraft:sculk_sensor': 'myw:ancient_mythril_bricks',
        'minecraft:sculk_block': 'myw:ancient_mythril_bricks_2',
        
        // Wood blocks
        'minecraft:oak_planks': 'myw:ancient_mythril_bricks',
        'minecraft:birch_planks': 'myw:ancient_mythril_bricks_2',
        'minecraft:spruce_planks': 'myw:ancient_mythril_bricks',
        'minecraft:jungle_planks': 'myw:ancient_mythril_bricks_2',
        'minecraft:acacia_planks': 'myw:ancient_mythril_bricks',
        'minecraft:dark_oak_planks': 'myw:ancient_mythril_bricks_2',
        'minecraft:mangrove_planks': 'myw:ancient_mythril_bricks',
        'minecraft:cherry_planks': 'myw:ancient_mythril_bricks_2',
        'minecraft:crimson_planks': 'myw:ancient_mythril_bricks',
        'minecraft:warped_planks': 'myw:ancient_mythril_bricks_2',
        'minecraft:oak_wood': 'myw:ancient_mythril_bricks',
        'minecraft:birch_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:spruce_wood': 'myw:ancient_mythril_bricks',
        'minecraft:jungle_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:acacia_wood': 'myw:ancient_mythril_bricks',
        'minecraft:dark_oak_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:mangrove_wood': 'myw:ancient_mythril_bricks',
        'minecraft:cherry_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:crimson_hyphae': 'myw:ancient_mythril_bricks',
        'minecraft:warped_hyphae': 'myw:ancient_mythril_bricks_2',
        'minecraft:stripped_oak_wood': 'myw:ancient_mythril_bricks',
        'minecraft:stripped_birch_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:stripped_spruce_wood': 'myw:ancient_mythril_bricks',
        'minecraft:stripped_jungle_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:stripped_acacia_wood': 'myw:ancient_mythril_bricks',
        'minecraft:stripped_dark_oak_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:stripped_mangrove_wood': 'myw:ancient_mythril_bricks',
        'minecraft:stripped_cherry_wood': 'myw:ancient_mythril_bricks_2',
        'minecraft:stripped_crimson_hyphae': 'myw:ancient_mythril_bricks',
        'minecraft:stripped_warped_hyphae': 'myw:ancient_mythril_bricks_2',
        
        // More organic blocks
        'minecraft:hay_block': 'myw:ancient_mythril_bricks',
        'minecraft:dried_kelp_block': 'myw:ancient_mythril_bricks_2',
        'minecraft:target': 'myw:ancient_mythril_bricks',
        'minecraft:bee_nest': 'myw:ancient_mythril_bricks_2',
        'minecraft:beehive': 'myw:ancient_mythril_bricks',
        'minecraft:honeycomb_block': 'myw:ancient_mythril_bricks_2',
        'minecraft:slime_block': 'myw:ancient_mythril_bricks',
        'minecraft:honey_block': 'myw:ancient_mythril_bricks_2',
        'minecraft:composter': 'myw:ancient_mythril_bricks',
        'minecraft:barrel': 'myw:ancient_mythril_bricks_2',
        'minecraft:chest': 'myw:ancient_mythril_bricks',
        'minecraft:trapped_chest': 'myw:ancient_mythril_bricks_2',
        'minecraft:ender_chest': 'myw:ancient_mythril_bricks',
        'minecraft:shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:white_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:orange_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:magenta_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:light_blue_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:yellow_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:lime_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:pink_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:gray_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:light_gray_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:cyan_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:purple_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:blue_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:brown_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:green_shulker_box': 'myw:ancient_mythril_bricks_2',
        'minecraft:red_shulker_box': 'myw:ancient_mythril_bricks',
        'minecraft:black_shulker_box': 'myw:ancient_mythril_bricks_2'
    };
    
    let converted = 0;
    
    // Convert 90 random blocks within 50 blocks - EXTREME SPEED (3X FASTER)
    for (let i = 0; i < 90; i++) {
        const randomPos = {
            x: position.x + Math.floor((Math.random() - 0.5) * 100),
            y: position.y + Math.floor((Math.random() - 0.3) * 20), // Reduced vertical range - more above, less below
            z: position.z + Math.floor((Math.random() - 0.5) * 100)
        };
        
        const block = dimension.getBlock(randomPos);
        if (block && conversions[block.typeId]) {
            try {
                block.setType(conversions[block.typeId]);
                converted++;
            } catch (error) {
                // Ignore errors
            }
        }
    }
    
    return converted;
}

// Send message to player
function sendMessage(player, message) {
    try {
        player.onScreenDisplay.setActionBar(`§5[TEMPLE] ${message}`);
    } catch (error) {
        // Ignore errors
    }
}

// Main system loop
function updateSystem() {
    try {
        const currentTick = system.currentTick;
        
        // Check every 1 second - FAST
        if (currentTick - lastCheck < 20) return;
        lastCheck = currentTick;
        
        // Update all active temples
        for (const [key, temple] of activeTemples.entries()) {
            const { position, dimension, lastPropagation } = temple;
            
            // Check if temple still exists
            const block = dimension.getBlock(position);
            if (!block || block.typeId !== 'myw:ancient_mythril_temple_rune') {
                activeTemples.delete(key);
                continue;
            }
            
            // Convert blocks every 0.033 seconds - 3X FASTER
            if (currentTick - lastPropagation >= 1) {
                const converted = convertBlocks(position, dimension);
                if (converted > 0) {
                    temple.lastPropagation = currentTick;
                    // Send message to nearby players
                    const players = world.getAllPlayers();
                    for (const player of players) {
                        const distance = Math.sqrt(
                            Math.pow(player.location.x - position.x, 2) +
                            Math.pow(player.location.y - position.y, 2) +
                            Math.pow(player.location.z - position.z, 2)
                        );
                        if (distance <= 20) {
                            sendMessage(player, `Biome: +${converted} blocks`);
                        }
                    }
                }
            }
        }
    } catch (error) {
        // Ignore errors
    }
}

// Handle block placement - AUTO ACTIVATE
function handleBlockPlace(event) {
    const { block, player } = event;
    if (block.typeId === 'myw:ancient_mythril_temple_rune') {
        const key = `${block.location.x},${block.location.y},${block.location.z}`;
        
        // Auto activate temple
        activeTemples.set(key, {
            position: block.location,
            dimension: player.dimension,
            lastPropagation: system.currentTick
        });
        
        sendMessage(player, 'Temple activated - Biome spreading!');
    }
}

// Handle block break
function handleBlockBreak(event) {
    const { block } = event;
    if (block.typeId === 'myw:ancient_mythril_temple_rune') {
        const key = `${block.location.x},${block.location.y},${block.location.z}`;
        activeTemples.delete(key);
    }
}

// Export functions
export function registerTempleRuneSystem() {
    // System registered
}

export function initializeTempleRuneSystem() {
    // Register events
    world.afterEvents.playerPlaceBlock.subscribe(handleBlockPlace);
    world.afterEvents.playerBreakBlock.subscribe(handleBlockBreak);
    
    // Main loop - FAST
    system.runInterval(updateSystem, 20);
}