import * as mc from "@minecraft/server"

mc.world.afterEvents.entitySpawn.subscribe(event=>{
    const entity = event.entity
    const cause = event.cause
})
let theDefaultHealth = [];


mc.system.runInterval(()=>{
    mc.world.getDimension("overworld").getEntities({families:['ld_eb_elemental']}).forEach(mob=>{
        const difficulty = mc.world.getDifficulty()
        const health = mob.getComponent('health')
        if(difficulty=='Easy'||difficulty=='Peaceful'){
            if(mob.getDynamicProperty('ld_eb:dif')!==1){
                health.setCurrentValue(Math.round(health.defaultValue-health.defaultValue/2.5))
                mob.setDynamicProperty('ld_eb:dif', 1)
                ////console1-console.warn(`Mob health update: ${mob.typeId}`)
            }
        }
        if(difficulty=='Normal'){
            if(mob.getDynamicProperty('ld_eb:dif')!==2){
            health.setCurrentValue(Math.round(health.defaultValue-health.defaultValue/5))
                mob.setDynamicProperty('ld_eb:dif', 2)
                ////console1-console.warn(`Mob health update: ${mob.typeId}`)
            }
        }
        if(difficulty=='Hard'){
            if(mob.getDynamicProperty('ld_eb:dif')!==3){
            health.setCurrentValue(health.defaultValue+health.defaultValue)
                mob.setDynamicProperty('ld_eb:dif', 3)
                ////console1-console.warn(`Mob health update: ${mob.typeId}`)
            }
        }
    })
})