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

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

const ItemArray = [
    new loreItem("omni_science:music_disc_chaos", ["§r§7Excited Studios - Chaos"]),
];

system.runInterval(() => {
    for (const player of world.getPlayers()) {
        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 || lore?.length != 0) continue
            // Un-comment below to check character lenght on lore. Change the [0] to match the index of the array.
            // Each string in the lore is an index in the array. [0,1,2] => ["sting 1","string 2","string 3"] 
            // console.warn(findLore.lore[11].length)
            item.setLore(findLore.lore);
            playerContainer.setItem(i, item);
        }
    }
}, 1);