import { world, system, Player, Entity, Vector} from "@minecraft/server";
system.afterEvents.scriptEventReceive.subscribe((e)=>{
    if(e.id=="bd:entity_move"){
        const viewVector = e.sourceEntity.getViewDirection();
        const parm = e.message.split(" ");
        const front = parseFloat(parm[2]); 
        const side = parseFloat(parm[0]);
        const up_down = parseFloat(parm[1]);
        const vec_1 = {x:viewVector.x*front,z:viewVector.z*front}
        const vec_2 = {x:(-1)*viewVector.z*side,z:viewVector.x*side}
        const vec = {x:vec_1.x+vec_2.x,z:vec_1.z+vec_2.z}
        
        e.sourceEntity.applyImpulse(new Vector(vec.x , up_down, vec.z));
    }
});
world.afterEvents.entityHurt.subscribe((e) => {
  const damager = e.damageSource.damagingEntity
  const damaged = e.hurtEntity
  if (damaged.typeId != 'minecraft:player' && damager.typeId == 'ho:sirenhead')
  damaged.applyImpulse(new Vector(damager.getViewDirection().x * 2, damager.getViewDirection().y * 2, damager.getViewDirection().z * 2))
});
system.beforeEvents.watchdogTerminate.subscribe((event) => {
  event.cancel = true;
});