import*as mc from"@minecraft/server";const immuneToFreezing=["hf_mzs:frostmaw","minecraft:rabbit","minecraft:endermite","minecraft:silverfish","minecraft:shulker","minecraft:vex","minecraft:fox","minecraft:polar_bear","minecraft:stray"];export function checkIfImmuneToFreezing(e){for(var t=0;t<immuneToFreezing.length;t++)if(immuneToFreezing[t]===e)return!0;return!1}var e=[];function clear(t){if(void 0!==t)for(var r=0;r<e.length;r++)if(e[r].id===t.id)return void e.splice(r,1)}function check(t){if(void 0===t)return!1;for(var r=0;r<e.length;r++)if(e[r].id===t.id)return!0;return!1}function register(t){check(t)||e.push(t)}function init(e,t){void 0===e.getDynamicProperty(t)&&e.setDynamicProperty(t,0)}export function onEntityHurt(e){e.hurtEntity.isValid()&&check(e.hurtEntity)&&("fire"===e.damageSource.cause||"campfire"===e.damageSource.cause||"fireTick"===e.damageSource.cause)&&(e.hurtEntity.getDynamicProperty("hf_mzs:cold")&&e.hurtEntity.setDynamicProperty("hf_mzs:cold",0),e.hurtEntity.getDynamicProperty("hf_mzs:freezing")&&e.hurtEntity.setDynamicProperty("hf_mzs:freezing",1))}export function applyFreezeEffect(e,t){if(!checkIfImmuneToFreezing(e.typeId)&&("minecraft:player"!==e.typeId||e.getGameMode()!==mc.GameMode.creative&&e.getGameMode()!==mc.GameMode.spectator))if(register(e),init(e,"hf_mzs:freezing"),0===e.getDynamicProperty("hf_mzs:freezing")&&e.runCommand("/playsound hf_mzs:misc.freeze @a[r=16] ~~~"),e.setDynamicProperty("hf_mzs:freezing",t),e.addTag("hf_mzs_frozen"),"minecraft:player"!==e.typeId){e.removeEffect("slowness"),e.addEffect("slowness",20*t,{amplifier:10,showParticles:!1}),e.addEffect("weakness",20*t,{amplifier:10,showParticles:!1}),void 0!==e?.getProperty("hf_mzs:attack_mode")&&(e?.setProperty("hf_mzs:attack_mode","frozen"),e?.setDynamicProperty("hf_mzs:frozen",!0),mc.system.runTimeout((()=>{e?.isValid()&&!e?.hasTag("hf_mzs_frozen")&&(e?.setProperty("hf_mzs:attack_mode","none"),e?.setDynamicProperty("hf_mzs:frozen",!1))}),2*t));try{e?.triggerEvent("freeze"),e?.setDynamicProperty("hf_mzs:frozen",!0),mc.system.runTimeout((()=>{e?.isValid()&&!e?.hasTag("hf_mzs_frozen")&&(e?.triggerEvent("unfreeze"),e?.setDynamicProperty("hf_mzs:frozen",!1))}),2*t)}catch{}mc.system.runTimeout((()=>{e?.removeTag("hf_mzs_frozen")}),5)}else e.runCommand("/function hf/mzs/effect/freeze")}export function applyColdEffect(e,t){checkIfImmuneToFreezing(e.typeId)||(register(e),init(e,"hf_mzs:cold"),5===e.getDynamicProperty("hf_mzs:cold")&&applyFreezeEffect(e,60),e.setDynamicProperty("hf_mzs:cold",Math.min(e.getDynamicProperty("hf_mzs:cold")+t,5)))}export function applyPoisonResistance(e,t){checkIfImmuneToFreezing(e.typeId)||(register(e),init(e,"hf_mzs:poison_resistance"),e.setDynamicProperty("hf_mzs:poison_resistance",e.getDynamicProperty("hf_mzs:poison_resistance")+t))}export function removeEntity(e){void 0===e.deadEntity||"player"===e.deadEntity.typeId?"death"===e.eventId&&e.entity.getComponent("minecraft:type_family").hasTypeFamily("hf_mzs_mob")&&clear(e.entity):clear(e.deadEntity)}export function tick20(){if(!(e.length<1))for(let r=0;r<e.length;r++){var t=e[r];void 0!==t&&t.isValid()&&(t.getDynamicProperty("hf_mzs:cold")>0&&(t.addEffect("slowness",20,{amplifier:1,showParticles:!1}),t.setDynamicProperty("hf_mzs:cold",t.getDynamicProperty("hf_mzs:cold")-1)),t.getDynamicProperty("hf_mzs:poison_resistance")>1&&(t.setDynamicProperty("hf_mzs:poison_resistance",t.getDynamicProperty("hf_mzs:poison_resistance")-1),t.runCommand("/particle hf_mzs:poison_resistance"),t.removeEffect("poison")),11==t.getDynamicProperty("hf_mzs:poison_resistance")&&t.runCommand('/tellraw @s {"rawtext":[{"translate":"message.hf_mzs.poison_resistance_10"}]}'),1==t.getDynamicProperty("hf_mzs:poison_resistance")&&(t.runCommand('/tellraw @s {"rawtext":[{"translate":"message.hf_mzs.poison_resistance_expired"}]}'),t.runCommand("/function hf/mzs/effect/unfreeze"),t.setDynamicProperty("hf_mzs:poison_resistance",0)))}}export function tick1(){if(!(e.length<1))for(const t of e)void 0!==t&&t.isValid()&&(t.getDynamicProperty("hf_mzs:freezing")>=1&&(t.setDynamicProperty("hf_mzs:freezing",t.getDynamicProperty("hf_mzs:freezing")-1),t.runCommand("/particle hf_mzs:frozen1"),t.runCommand("/particle hf_mzs:frozen2"),t.teleport(t.location)),1==t.getDynamicProperty("hf_mzs:freezing")&&(t.runCommand("/function hf/mzs/effect/unfreeze"),t.runCommand("/playsound hf_mzs:misc.unfreeze @a[r=16] ~~~"),t.setDynamicProperty("hf_mzs:freezing",0),t.setDynamicProperty("hf_mzs:cold",0),t.removeEffect("slowness")))}