import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import*as selectors from"../utils/selectors";import{EXCLUDED_ENTITIES}from"../playerAbilities";import{ATTACK_DAMAGE}from"./bluff";export function eventBehavior(o){const e=o.entity;if("register"===o.eventId){if(void 0!==e.getDynamicProperty("hf_mzs:has_appeared"))return void e.triggerEvent("break");mc.system.runTimeout((()=>{const o=selectors.union({location:e.location,maxDistance:1.3,excludeFamilies:["inanimate","hf_mzs_bluff"],excludeTypes:EXCLUDED_ENTITIES},[],e.dimension,e.id);for(let r of o){if(!r.isValid())continue;const o={x:e.getDynamicProperty("hf_mzs:x_dir"),z:e.getDynamicProperty("hf_mzs:z_dir")};r.applyKnockback(o.x,o.z,2,4),e.getDynamicProperty("hf_mzs:shooter")?r.applyDamage(ATTACK_DAMAGE,{cause:"entityAttack",damagingEntity:mc.world.getEntity(e.getDynamicProperty("hf_mzs:shooter"))}):r.applyDamage(ATTACK_DAMAGE,{cause:"entityAttack"})}}),2);const o={x:Math.floor(e.location.x)+.5,y:e.location.y,z:Math.floor(e.location.z)+.5};return e.runCommand(`/fill ${vector.string(o)} ${vector.string(o)} hf_mzs:bluff_boulder [] replace air`),e.runCommand("/playsound hf_mzs:mob.bluff.rock_appear @a[r=16] ~~~"),e.runCommand("/particle hf_mzs:bluff_boulder2 ~~~"),void e.setDynamicProperty("hf_mzs:has_appeared",!0)}if("break"===o.eventId){e.runCommand("/playsound hf_mzs:mob.bluff.rock_explode @a[r=16] ~~~"),e.runCommand("/particle hf_mzs:bluff_boulder_break ~~~");const o={x:Math.floor(e.location.x)+.5,y:e.location.y,z:Math.floor(e.location.z)+.5};return e.runCommand(`/fill ${vector.string(o)} ${vector.string(o)} air [] replace hf_mzs:bluff_boulder`),void e.remove()}}