const phantom_size = 320;
const phantom_health = 200.0;

// Spawn the big phantom
onEvent('entity.spawned', event => {
    // Big Phantom
    if (event.entity.type == 'minecraft:phantom') { 
        // Get the full NBT of the mob
        var NBT = event.entity.fullNBT;      
        // Set the size of the phantom
        let p = Math.random();
        if (p > 0.9){
            // Set the size in the NBT
            NBT.Size = phantom_size;
            // Set the new NBT
            event.entity.fullNBT = NBT;
            // Set the other attributes
            event.entity.maxHealth = phantom_health;
            event.entity.health = phantom_health;
            event.entity.setCustomName('The Storm King');
            // Set the weather to thunder
            event.server.runCommandSilent('/weather thunder');
            event.server.tell(text.red('The Storm King appeared!'));
        };
    };
});

// Add the drop to the big phantom
onEvent('entity.drops', event => {
    if (event.entity.type == 'minecraft:phantom' && event.entity.customName == 'The Storm King') { 
        event.addDrop('2x kubejs:phantom_wing');
        event.server.runCommandSilent('/weather clear');
        event.server.tell(text.blue('Demon Vanquished!'));
    }; 
});