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

const descItems = [
    "mm:music_disc_keeper",
    "mm:music_disc_myths_and_magic",
    "mm:music_disc_devoid",
    "mm:disc_fragment_devoid",
    "mm:music_disc_devoid_altered",
    "mm:music_disc_farewell",
    "mm:music_disc_what",

    "mm:demon_helmet",
    "mm:demon_chestplate",
    "mm:demon_leggings",
    "mm:demon_boots",
    "mm:sparkling_amulet",
    "mm:shivering_amulet",
    "mm:blazing_amulet",
    "mm:altered_amulet",
    "mm:warp_key",
    "mm:altered_key",
    "mm:ancient_texts",
    "mm:creative_scroll",

    "mm:booze_potion_waterbreathing_long",
    "mm:booze_potion_fireresistance_long",
    "mm:booze_potion_invisibility_long",
    "mm:booze_potion_nightvision_long",
    "mm:booze_potion_slowfalling_long",
    "mm:booze_potion_speed_strong",
    "mm:booze_potion_jumpboost_strong",
    "mm:booze_potion_regeneration_strong",

    "mm:booze_potion_haste",
    "mm:booze_potion_blindness",
    "mm:booze_potion_metallurgy",
    "mm:booze_potion_reduction",

    "mm:booze_potion_waterbreathing_splash",
    "mm:booze_potion_fireresistance_splash",
    "mm:booze_potion_invisibility_splash",
    "mm:booze_potion_nightvision_splash",
    "mm:booze_potion_slowfalling_splash",
    "mm:booze_potion_speed_splash",
    "mm:booze_potion_jumpboost_splash",
    "mm:booze_potion_regeneration_splash",

    "mm:booze_potion_haste_splash",
    "mm:booze_potion_metallurgy_splash",
    "mm:booze_potion_reduction_splash",
    "mm:booze_potion_blindness_splash"
]

world.afterEvents.playerInventoryItemChange.subscribe((e) => {
    const item = e.itemStack;
    const player = e.player;
    if (!item || !player) return;
    if (item.getLore().length !== 0) return;
    if (item.typeId.includes("mm:mystery_scroll")) {
        item.setLore([{ translate: "desc.mystery_scroll" }])
        var slot = e.slot
        const inventory = player.getComponent("minecraft:inventory");
        if (inventory === undefined || inventory.container === undefined) {
            return;
        }
        inventory.container.setItem(slot, item);
    } else {
        if (!descItems.includes(item.typeId)) return;
        item.setLore([{ translate: item.typeId.replace("mm:", "desc.") }])
        var slot = e.slot
        const inventory = player.getComponent("minecraft:inventory");
        if (inventory === undefined || inventory.container === undefined) {
            return;
        }
        inventory.container.setItem(slot, item);
    }
})
