// foodEffects.js

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

const ItemFoodEffectsComponent = {
    onConsume({ itemStack, source }) {
        if (itemStack.typeId === "fw:stimpack") {

            // Regeneration II for 5 seconds
            source.addEffect("minecraft:regeneration", 100, {
                amplifier: 2,
                showParticles: false,
            });

            // Resistance II for 7.5 seconds
            source.addEffect("minecraft:resistance", 150, {
                amplifier: 2,
                showParticles: false,
            });

        } else if (itemStack.typeId === "fw:cram") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:pork_n_beans") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +2 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 2").catch(() => {
            });
        } else if (itemStack.typeId === "fw:pork_n_beans_cooked") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:resistance", 150, {
                amplifier: 0,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:nuka_quantum_pie") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:regeneration", 300, {
                amplifier: 2,
                showParticles: false,
            });
            // Hunger for 5 seconds
            source.addEffect("minecraft:resistance", 200, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +6 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 6").catch(() => {
            });
        } else if (itemStack.typeId === "fw:nuka_cola_pie") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:resistance", 200, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +4 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 4").catch(() => {
            });
        } else if (itemStack.typeId === "fw:pefectly_preserved_pie") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:resistance", 1200, {
                amplifier: 1,
            });
            // Hunger for 5 seconds
            source.addEffect("minecraft:regeneration", 600, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +0 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 0").catch(() => {
            });
        } else if (itemStack.typeId === "fw:bowl_of_blamco") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +3 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 3").catch(() => {
            });
        } else if (itemStack.typeId === "fw:radroach_stew") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +3 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 3").catch(() => {
            });
        } else if (itemStack.typeId === "fw:brahmin_steak") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +2 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 2").catch(() => {
            });
        } else if (itemStack.typeId === "fw:brahmin_milk") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
            // Give back empty bucket
            source.runCommandAsync("give @s bucket").catch(() => {
            });
        } else if (itemStack.typeId === "fw:fancy_lads_snack_cakes") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:nuka_cola_bottle") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // hunger for 5 seconds
            source.addEffect("minecraft:swiftness", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:nuka_quantem_bottle") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // hunger for 5 seconds
            source.addEffect("minecraft:swiftness", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +2 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 2").catch(() => {
            });
        } else if (itemStack.typeId === "fw:blood_pack") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:suger_bombs") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:mentals") {
            // Resistance for 5 seconds
            source.addEffect("minecraft:resistance", 100, {
                amplifier: 2,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:blamco_mc") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:whiskey") {
            // hunger for 5 seconds
            source.addEffect("minecraft:nausea", 300, {
                amplifier: 0,
                showParticles: false,
            });
            // hunger for 5 seconds
            source.addEffect("minecraft:strength", 400, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:cram_breakfast_with_potatos") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:wastelanders_stew") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:brahmin_burger") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:wastelanders_treat") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        } else if (itemStack.typeId === "fw:dirty_water") {
            // hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        }
    },
};

world.beforeEvents.worldInitialize.subscribe(({ itemComponentRegistry }) => {
    itemComponentRegistry.registerCustomComponent("fw:food_effects", ItemFoodEffectsComponent);
});
