import { world } from "@minecraft/server";

const EntitiesDeny = [
  "minecraft:armor_stand",
  "minecraft:item",
  "minecraft:xp_orb",
  "minecraft:glow_item_frame",
  "minecraft:painting"
];

world.afterEvents.entityHitEntity.subscribe((data) => {
  const { damagingEntity, hitEntity } = data;

  if (damagingEntity.typeId !== "minecraft:player") return;
  if (hitEntity.id === damagingEntity.id) return;

  const family = hitEntity.getComponent("type_family");
  if (
    EntitiesDeny.includes(hitEntity.typeId) ||
    family?.hasTypeFamily("npc") ||
    family?.hasTypeFamily("inanimate")
  ) return;

  const equipment = damagingEntity.getComponent("equippable")?.getEquipment("Mainhand");
  if (!equipment || equipment.typeId !== "faf:light_steel_sword") return;

  hitEntity.runCommandAsync("summon minecraft:lightning_bolt");
hitEntity.runCommandAsync("execute @e[r=7,c=1,family=ice_dragon] ~~~ damage @e[r=7,c=1] 5 entity_attack");
hitEntity.runCommandAsync("execute @e[r=7,c=1,family=fire_dragon] ~~~ damage @e[r=7,c=1] 5 entity_attack");
});