import*as mc from"@minecraft/server";import*as vector from"../utils/vector";import*as selectors from"../utils/selectors";import{spawnXp}from"../entities";export function eventBehavior(t){const e=t.entity;if("drop"===t.eventId&&mc.world.gameRules.doMobLoot)spawnXp(e.location,4,e.dimension);else if("spawned_naturally"!==t.eventId)"death"!==t.eventId||mc.system.runTimeout((()=>{t.entity.isValid()&&t.entity.triggerEvent("drop")}),45);else{if(void 0!==selectors.union({location:e.location,maxDistance:6},["pig","sheep","cow","chicken"],e.dimension,e.id)[0])return void e.remove();const t=e.dimension.getBlock(vector.add(e.location,{x:0,y:-1.5,z:0}));"minecraft:grass_block"!==t.typeId&&"minecraft:dirt"!==t.typeId&&e.remove()}}export function hitBehavior(t){if(!t.hitEntity.isValid())return;const e=vector.subtract(t.hitEntity.location,t.damagingEntity.location),i=3/vector.magnitude(e);t.hitEntity.applyKnockback(e.x,e.z,i,.35),0===t.hitEntity.getComponent("health")?.currentValue&&t.damagingEntity.addEffect("regeneration",60,{amplifier:2,showParticles:!0})}