//凋零强化
//每十五秒召唤一只千血20甲的凋零骷髅
//数值方面由于incontral模组增幅，所有有些不一样
NativeEvents.onEvent($LivingTickEvent, event => {
    let entity = event.entity
    if (!entity) return
    if (entity.age % 300 != 0) return
    if (entity.type == 'minecraft:wither') {
        let level = entity.level
        let spawn_entity = level.createEntity('minecraft:wither_skeleton');
        spawn_entity.setPosition(entity.x, entity.y, entity.z);
        //属性修改
        spawn_entity.modifyAttribute('minecraft:generic.armor', 'wither_skeleton_boost', 20, 'addition');
        spawn_entity.modifyAttribute('minecraft:generic.max_health', 'wither_skeleton_boost', 800, 'addition');
        //给发光buff防止找不到
        spawn_entity.potionEffects.add('minecraft:glowing', 20 * 10000, 1)
        spawn_entity.spawn();
        //阻止召唤的凋零骷髅攻击凋零
        spawn_entity.persistentData.putBoolean('owner_wither', true)
        //回血
        spawn_entity.setHealth(spawn_entity.maxHealth)
        if (spawn_entity.getMainHandItem()) {
            //给武器
            spawn_entity.setMainHandItem(Item.of('tetra:sword_renew', '{Damage:4,HideFlags:1,honing_available:1b,honing_progress:0,id:"b504a732-5ac7-40ec-9aed-e1388a350082",showModels:["item","form_1"],"sword/basic_hilt_material":"basic_hilt/undergarden_froststeel","sword/blade":"sword/katana_blade","sword/blade/settle_progress":704,"sword/blade:quality":0,"sword/blade:sword/murasama_imprv":0,"sword/echo_fuller_material":"echo_fuller/echo_fullerecho_shard","sword/fuller":"sword/echo_fuller","sword/grip_loop_material":"grip_loop/wind_iron_ingot","sword/guard":"sword/socket","sword/hilt":"sword/basic_hilt","sword/hilt/settle_progress":354,"sword/hilt:candycaneallcandycane":0,"sword/hilt:candycaneallrockcandy":0,"sword/hilt:candycaneallsweetishfish":0,"sword/hilt:quality":0,"sword/katana_blade_material":"katana_blade/witherite_ingot","sword/pommel":"sword/grip_loop","sword/socket_material":"sword_socket/socket_pristine_diamond",tetra_all_effect:[{efficiency:1.5f,level:5,name:"abilityMomentum"},{efficiency:1.0f,level:1,name:"bleeding"},{efficiency:0.0d,level:1,name:"intuit"},{efficiency:0.01f,level:3,name:"sculkTaint"},{efficiency:1.0f,level:5,name:"severing"},{efficiency:1.0f,level:4,name:"skewering"},{efficiency:1.0f,level:14,name:"sweeping"},{efficiency:0.0d,level:1,name:"truesweep"},{efficiency:0.0d,level:1,name:"wind_iron_ingot"},{efficiency:0.0d,level:1,name:"witherite_ingot"}]}'))
        }
    }
})
//凋零半血召唤凋零骷髅
function wither_hurt_1(event) {
    let entity = event.entity
    if (entity.type == 'minecraft:wither') {
        let health = entity.getHealth()
        if (health < entity.maxHealth / 2 && !entity.persistentData.contains('wither_hurt')) {
            //只召唤一次
            entity.persistentData.putBoolean('wither_hurt', true)
            let level = entity.level
            let spawn_entity = level.createEntity('minecraft:wither_skeleton');
            spawn_entity.setPosition(entity.x, entity.y, entity.z);
            //属性修改
            spawn_entity.modifyAttribute('minecraft:generic.armor', 'wither_skeleton_boost', 40, 'addition');
            spawn_entity.modifyAttribute('minecraft:generic.max_health', 'wither_skeleton_boost', 1800, 'addition');
            //给发光buff防止找不到
            spawn_entity.potionEffects.add('minecraft:glowing', 20 * 10000, 1)
            spawn_entity.spawn();
            //阻止召唤的凋零骷髅攻击凋零
            spawn_entity.persistentData.putBoolean('owner_wither', true)
            //回血
            spawn_entity.setHealth(spawn_entity.maxHealth)
            if (spawn_entity.getMainHandItem()) {
                //给武器
                spawn_entity.setMainHandItem(Item.of('tetra:sword_renew', '{Damage:0,HideFlags:1,honing_available:1b,honing_progress:0,id:"bba037f8-5736-4f2a-b8b3-2edb9b95dd11",repairCount:1,showModels:["item","form_1"],"sword/basic_hilt_material":"basic_hilt/wind_iron_ingot","sword/blade":"sword/crucible_blade","sword/blade/settle_progress":327,"sword/blade:blade_hone/speed":5,"sword/blade:quality":0,"sword/blade:settled":1,"sword/blade:sword/architect_imprv":0,"sword/crucible_blade_material":"crucible_blade/black_yellow_planks","sword/forefinger_ring_material":"forefinger_ring/blackmetal_ingot","sword/fuller":"sword/reinforced_fuller","sword/grip_loop_material":"grip_loop/wind_iron_ingot","sword/guard":"sword/forefinger_ring","sword/hilt":"sword/basic_hilt","sword/hilt/settle_progress":294,"sword/hilt:candycaneallcandycane":0,"sword/hilt:candycaneallrockcandy":0,"sword/hilt:candycaneallsweetishfish":0,"sword/hilt:hilt_hone/damage":5,"sword/hilt:quality":0,"sword/hilt:settled":2,"sword/pommel":"sword/grip_loop","sword/reinforced_fuller_material":"reinforced_fuller/wind_iron_ingot",tetra_all_effect:[{efficiency:2.0f,level:5,name:"abilityCombo"},{efficiency:2.0f,level:8,name:"abilityExhilarated"},{efficiency:0.0d,level:21,name:"armorPenetration"},{efficiency:0.0d,level:20,name:"art_of_forging:esoteric_edge"},{efficiency:0.0d,level:1,name:"art_of_forging:knockback"},{efficiency:5.0f,level:5,name:"art_of_forging:vengeance"},{efficiency:0.0d,level:1,name:"blackmetal_ingot"},{efficiency:0.0d,level:5,name:"quickStrike"},{efficiency:7.0f,level:21,name:"severing"},{efficiency:1.0f,level:18,name:"sweeping"},{efficiency:0.0d,level:1,name:"truesweep"},{efficiency:0.0d,level:3,name:"wind_iron_ingot"}]}'))
            }
        }
    }
}
//凋零召唤凋零骷髅，阻止凋零骷髅攻击凋零
function owner_wither(event) {
    let entity = event.entity
    let target = event.getNewTarget()
    if (entity.persistentData.contains('owner_wither') && target && target.type == 'minecraft:wither') {
        event.setCanceled(true);
    }
}
//凋零16格范围内有凋零骷髅，受到的伤害减少
function wither_hurt_2(event) {
    let entity1 = event.entity
    let type = entity1.type
    let source = event.source.actual
    let count = 0
    if (type != 'minecraft:wither') return
    // 获取周围实体
    let entityList = getLivingWithinRadius(entity1.getLevel(), entity1.position(), 16)
    // 遍历实体列表
    entityList.forEach(entity => {
        if (entity.persistentData.contains('owner_wither')) {
            count++
        }
    })
    event.amount = event.amount * Math.max((1 - count * 0.1), 0)
    if (event.amount == 0 && source.isPlayer()) {
        source.tell('凋零免伤已达到百分之百，请尽快击杀周围凋零骷髅')
    }
}