import "./modules/armors";
import "./modules/guidebook";
import "./modules/items";
import "./modules/monsters";
import "./modules/weapons";

import * as MC from "@minecraft/server";
import { itemLores } from "./data/lores";

/* Listen to inventory changes to set lores on custom items.
* Quantity is ignored
* Only items with the "chronicoverride_llc:lore" tag are considered.
*/
MC.world.afterEvents.playerInventoryItemChange.subscribe((event) => {
    const { player, slot, itemStack } = event;

    // Get the lore for the item.
    const lore = itemLores[itemStack.type.id];
    if (lore === null || lore?.size <= 0) {
        return;
    }

    // All conditions passed => set lore and update item
    const inventory = player.getComponent("minecraft:inventory").container;
    const count = itemStack.amount;

    const newItem = new MC.ItemStack(itemStack.type, count);
    newItem.setLore(lore);
    inventory.setItem(slot, newItem);
}, {
    ignoreQuantityChange: true,
    includeTags: ["chronicoverride_llc:lore"]
});