import { system, world, EquipmentSlot } from "@minecraft/server"

class loreItem {
    constructor(itemId, lore) {
        this.itemId = itemId;
        this.lore = lore;
    }
}

const DeadKingScytheLore0 = '§9+ Crouch and Use item to swap ability'
const DeadKingScytheLore1 = '§r§9+ Crouch and hit an entity to use ability'
const DeadKingScytheLore2 = '\n§r§9- On Use:'
const DeadKingScytheLore3_1 = '§9Perform a spin attack, damaging'
const DeadKingScytheLore3_2 = '§9mobs all around you'

export {
    DeadKingScytheLore0,
    DeadKingScytheLore1,
    DeadKingScytheLore2,
    DeadKingScytheLore3_1,
    DeadKingScytheLore3_2
}

const ItemArray = [
    new loreItem("darkw_fallenking:erius_loot_sword", [DeadKingScytheLore2, DeadKingScytheLore3_1, DeadKingScytheLore3_2]),
    new loreItem("darkw_fallenking:erius_spawner_p2", ["\n§r§dCreative Only"])
]

system.runInterval(() => { // Lore Controls
    for (const player of world.getPlayers()) { // Gets all players
        const playerContainer = player.getComponent("inventory").container; //
        for (let i = 0; i < playerContainer.size; i++) {
            const item = playerContainer.getItem(i);
            const findLore = ItemArray.find(x => x.itemId == item?.typeId);
            const lore = item?.getLore();
            if (!findLore || !item?.amount || lore?.length != 0) continue;
            item.setLore(findLore.lore);
            playerContainer.setItem(i, item);
        }
    }
}, 1);
// Weapon Functions