import * as mc from "@minecraft/server";
import * as vector from "../utils/vector";

export function useMobRemover(event) {
  const entity = event.damagingEntity;
  const target = event.hitEntity;

  if (entity.typeId === "minecraft:player") {
    const item = entity.getComponent("equippable").getEquipment(mc.EquipmentSlot.Mainhand);
    if (item && item.typeId === "hf_mzs:mob_remover") {
      mc.system.run(() => {
        if (target && target.isValid()) {
          const [identifier, namespace] = target.typeId.split(":");
          if (identifier === "hf_mzs") {
            if (target.typeId === "hf_mzs:boulder") {
              target.triggerEvent("hf_mzs:on_hit");
              return;
            }
            target.dimension.spawnParticle("hf_mzs:death_small", target.location);
            target.dimension.playSound("random.pop", target.location, { volume: 1.0, pitch: 0.75 });
            target.remove();
          }
        }
      });
    }
  }
}
