import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import{spawnXp}from"../entities";export function eventBehavior(t){if("minecraft:entity_spawned"!==t.eventId)if("register"!==t.eventId)if("death_no_drop"===t.eventId&&(t.entity.setProperty("hf_mzs:no_drop",!0),t.entity.setProperty("hf_mzs:death",!0)),"drop"===t.eventId&&mc.world.gameRules.doMobLoot){if(!t.entity.getProperty("hf_mzs:no_drop")){spawnXp(t.entity.location,4,t.entity.dimension);const e=new mc.ItemStack("minecraft:diamond",t.entity.getDynamicProperty("hf_mzs:drop_amount"));t.entity.dimension.spawnItem(e,t.entity.location)}t.entity.remove()}else if("attempt_flee"!==t.eventId);else{if(void 0===t.entity.dimension.getBlockFromRay(t.entity.location,vector.down,{includeTypes:["minecraft:grass_block","minecraft:dirt","minecraft:stone","minecraft:deepslate"],maxDistance:1.5}))return;t.entity.triggerEvent("hide")}else t.entity.setDynamicProperty("hf_mzs:ding_cooldown",0);else t.entity.location.y<3&&t.entity.setProperty("hf_mzs:deepslate",!0)}export function hurtBehavior(t){if(void 0===t.damageSource.damagingEntity||!t.damageSource.damagingEntity.isValid()||"minecraft:player"!==t.damageSource.damagingEntity.typeId)return;const e=t.damageSource.damagingEntity.getComponent("equippable")?.getEquipment("Mainhand");if(e?.getComponent("enchantable").hasEnchantment("silk_touch")){if(t.hurtEntity.getProperty("hf_mzs:deepslate")){t.hurtEntity.runCommand("/particle hf_mzs:grottol_break ~~~"),t.hurtEntity.runCommand("/playsound dig.deepslate @a[r=16] ~~~ 2");const e=new mc.ItemStack("hf_mzs:captured_grottol_deep");t.hurtEntity.dimension.spawnItem(e,t.hurtEntity.location)}else{t.hurtEntity.runCommand("/particle hf_mzs:grottol_break ~~~"),t.hurtEntity.runCommand("/playsound dig.stone @a[r=16] ~~~ 5");const e=new mc.ItemStack("hf_mzs:captured_grottol");t.hurtEntity.dimension.spawnItem(e,t.hurtEntity.location)}t.hurtEntity.remove()}else t.hurtEntity.setProperty("hf_mzs:death",!0),e?.getComponent("enchantable").hasEnchantment("fortune")?t.hurtEntity.setDynamicProperty("hf_mzs:drop_amount",Math.ceil(e.getComponent("enchantable").getEnchantment("fortune")?.level/2+1)):t.hurtEntity.setDynamicProperty("hf_mzs:drop_amount",1),t.hurtEntity.triggerEvent("death")}