import * as Minecraft from "@minecraft/server"


Minecraft.system.beforeEvents.startup.subscribe((event) => {
    event.itemComponentRegistry.registerCustomComponent("aria_ah:poisonous_food", {
        onConsume: (event) => {
            event.source.addEffect("minecraft:poison", 100)
        }
    })
/*
    event.itemComponentRegistry.registerCustomComponent("aria_ah:anti_course_food", {
        onConsume: (event) => {
            event.source.removeTag("aria_ah_cursed")
            event.source.runCommand("give @s minecraft:glass_bottle")
        }
    })

    event.itemComponentRegistry.registerCustomComponent("aria_ah:course_protection_food_i", {
        onConsume: (event) => {
            const secNr = Minecraft.world.scoreboard.getObjective("aria_ah.clock").getScore("aria_ah.sec_nr")

            event.source.addTag("aria_ah_cursed_protected")
            event.source.runCommand("give @s minecraft:glass_bottle")
            Minecraft.world.scoreboard.getObjective("aria_ah.curse_protected").setScore(event.source, (secNr + 600 >= 32000) ? 32000 - secNr : secNr + 600)
        }
    })
    event.itemComponentRegistry.registerCustomComponent("aria_ah:course_protection_food_ii", {
        onConsume: (event) => {
            const secNr = Minecraft.world.scoreboard.getObjective("aria_ah.clock").getScore("aria_ah.sec_nr")

            event.source.addTag("aria_ah_cursed_protected")
            event.source.runCommand("give @s minecraft:glass_bottle")
            Minecraft.world.scoreboard.getObjective("aria_ah.curse_protected").setScore(event.source, (secNr + 1800 >= 32000) ? 32000 - secNr : secNr + 1800)
        }
    })
    event.itemComponentRegistry.registerCustomComponent("aria_ah:course_protection_food_iii", {
        onConsume: (event) => {
            const secNr = Minecraft.world.scoreboard.getObjective("aria_ah.clock").getScore("aria_ah.sec_nr")

            event.source.addTag("aria_ah_cursed_protected")
            event.source.runCommand("give @s minecraft:glass_bottle")
            Minecraft.world.scoreboard.getObjective("aria_ah.curse_protected").setScore(event.source, (secNr + 3600 >= 32000) ? 32000 - secNr : secNr + 3600)
        }
    })

*/











    /*event.itemComponentRegistry.registerCustomComponent("aria_ah:course_food_i", {
        onConsume: (event) => {
            const secNr = Minecraft.world.scoreboard.getObjective("aria_ah.clock").getScore("aria_ah.sec_nr")

            event.source.removeTag("aria_ah_cursed")
            event.source.runCommand("give @s minecraft:glass_bottle")
            Minecraft.world.scoreboard.getObjective("aria_ah.course").setScore(event.source, (secNr + 600 >= 32000) ? 32000 - secNr : secNr + 600)
        }
    })*/
})