// MeatEffects.js

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

const ItemMeatEffectsComponent = {
    onConsume({ itemStack, source }) {
        if (itemStack.typeId === "fw:raw_deathclaw_meat") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +6 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 6").catch(() => {
            });
        } else if (itemStack.typeId === "fw:cooked_deathclaw_meat") {
            // Add +3 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 3").catch(() => {
            });
        } else if (itemStack.typeId === "fw:raw_brahmin_meat") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +5 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 5").catch(() => {
            });
        } else if (itemStack.typeId === "fw:cooked_brahmin_meat") {
            // Add +2 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 2").catch(() => {
            });
        } else if (itemStack.typeId === "fw:raw_bloatfly_meat") {
            // Hunger for 5 seconds
            source.addEffect("minecraft:hunger", 50, {
                amplifier: 1,
                showParticles: false,
            });
            // Add +4 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 4").catch(() => {
            });
        } else if (itemStack.typeId === "fw:cooked_bloatfly_meat") {
            // Add +2 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 2").catch(() => {
            });
        } else if (itemStack.typeId === "fw:raw_radroach_meat") {
            // 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:cooked_radroach_meat") {
            // Add +1 to Rads score
            source.runCommandAsync("scoreboard players add @s Rads 1").catch(() => {
            });
        }
    },
};

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