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

world.afterEvents.itemCompleteUse.subscribe(eventData => {
  const player = eventData.source;
  const itemUsed = eventData.itemStack;
	const customFoods = [
    "nicothekid:amethyst_apple",
    "nicothekid:apple_pie",
    "nicothekid:bamboo_tumbler_chocolate",
    "nicothekid:bamboo_tumbler_glow_berry",
    "nicothekid:bamboo_tumbler_milk",
    "nicothekid:bamboo_tumbler_sweet_berry",
    "nicothekid:blazing_apple",
    "nicothekid:cactus_stew",
    "nicothekid:carrot_soup",
    "nicothekid:cheese",
    "nicothekid:cheese_bread",
    "nicothekid:chocolate_bar",
    "nicothekid:clurve_raw",
    "nicothekid:crimson_stew",
    "nicothekid:diamond_apple",
    "nicothekid:egg_sandwich",
    "nicothekid:emerald_apple",
    "nicothekid:glow_berry_cookie",
    "nicothekid:glow_berry_pie",
    "nicothekid:glow_lichen_stew",
    "nicothekid:iron_apple",
    "nicothekid:jar_chocolate_full",
    "nicothekid:jar_chocolate_half",
    "nicothekid:jar_glow_berry_juice_full",
    "nicothekid:jar_glow_berry_juice_half",
    "nicothekid:jar_honey_full",
    "nicothekid:jar_honey_half",
    "nicothekid:jar_milk_full",
    "nicothekid:jar_milk_half",
    "nicothekid:jar_sweet_berry_juice_full",
    "nicothekid:jar_sweet_berry_juice_half",
    "nicothekid:lapis_lazuli_apple",
    "nicothekid:moa_raw",
    "nicothekid:moss_berry_cookie",
    "nicothekid:moss_berry_pie",
    "nicothekid:mosshroom_stew",
    "nicothekid:netherite_apple",
    "nicothekid:pea_stew",
    "nicothekid:potato_soup",
    "nicothekid:pumpkin_slice",
    "nicothekid:rat_raw",
    "nicothekid:rotten_brute_flesh",
    "nicothekid:seagrass_stew",
    "nicothekid:soup",
    "nicothekid:squirrel_raw",
    "nicothekid:sweet_berry_cookie",
    "nicothekid:sweet_berry_pie",
    "nicothekid:warped_stew"
  ]
	if (customFoods.includes(itemUsed.typeId)) {
    if (itemUsed.typeId === "nicothekid:amethyst_apple") {
      player.addEffect("night_vision", 1200, {amplifier: 0, showParticles: true })
      player.addEffect("regeneration", 100, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:apple_pie") {
      player.addEffect("instant_health", 200, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:bamboo_tumbler_chocolate") {
      player.removeEffect("slowness")
    }
    if (itemUsed.typeId === "nicothekid:bamboo_tumbler_glow_berry") {
      player.removeEffect("blindness")
    }
    if (itemUsed.typeId === "nicothekid:bamboo_tumbler_milk") {
      player.removeEffect("nausea")
      player.removeEffect("fatal_poison")
      player.removeEffect("levitation")
      player.removeEffect("poison")
      player.removeEffect("weakness")
    }
    if (itemUsed.typeId === "nicothekid:bamboo_tumbler_sweet_berry") {
      player.removeEffect("hunger")
    }
    if (itemUsed.typeId === "nicothekid:blazing_apple") {
      player.addEffect("fire_resistance", 1200, {amplifier: 0, showParticles: true })
      player.addEffect("regeneration", 100, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:cactus_stew") {
      let nauseaChance = Math.random();
      if (nauseaChance <= 0.5) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:carrot_soup") {
      player.removeEffect("hunger")
      player.removeEffect("nausea")
    }
    if (itemUsed.typeId === "nicothekid:cheese") {
      let nauseaChance = Math.random();
      if (nauseaChance <= 0.1) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:cheese_bread") {
      let regenerationChance = Math.random();
      if (regenerationChance <= 0.05) {
        player.addEffect("regeneration", 200, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:chocolate_bar") {
      let speedChance = Math.random();
      if (speedChance <= 0.5) {
        player.addEffect("speed", 400, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:clurve_raw") {
      let blindnessChance = Math.random();
      if (blindnessChance <= 0.3) {
        player.addEffect("blindness", 400, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:crimson_stew") {
      let nauseaChance = Math.random();
      let poisonChance = Math.random();
      if (nauseaChance <= 0.25) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
      if (poisonChance <= 0.1) {
        player.addEffect("poison", 200, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:diamond_apple") {
      player.addEffect("resistance", 3600, {amplifier: 2, showParticles: true })
      player.addEffect("absorption", 1200, {amplifier: 1, showParticles: true })
      player.addEffect("health_boost", 600, {amplifier: 0, showParticles: true })
      player.addEffect("regeneration", 300, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:egg_sandwich") {
      let regenerationChance = Math.random();
      if (regenerationChance <= 0.05) {
        player.addEffect("regeneration", 100, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:emerald_apple") {
      player.addEffect("haste", 1200, {amplifier: 1, showParticles: true })
      player.addEffect("regeneration", 300, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:glow_berry_cookie") {
      player.addEffect("night_vision", 200, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:glow_berry_pie") {
      player.addEffect("night_vision", 900, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:glow_lichen_stew") {
      player.addEffect("night_vision", 500, {amplifier: 0, showParticles: true })
      player.addEffect("mining_fatigue", 400, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:iron_apple") {
      player.addEffect("strength", 1200, {amplifier: 1, showParticles: true })
      player.addEffect("regeneration", 300, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:jar_chocolate_full") {
      player.removeEffect("slowness")
    }
    if (itemUsed.typeId === "nicothekid:jar_chocolate_half") {
      player.removeEffect("slowness")
    }
    if (itemUsed.typeId === "nicothekid:jar_glow_berry_juice_full") {
      player.removeEffect("blindness")
    }
    if (itemUsed.typeId === "nicothekid:jar_glow_berry_juice_half") {
      player.removeEffect("blindness")
    }
    if (itemUsed.typeId === "nicothekid:jar_honey_full") {
      player.removeEffect("poison")
      player.removeEffect("fatal_poison")
    }
    if (itemUsed.typeId === "nicothekid:jar_honey_half") {
      player.removeEffect("poison")
      player.removeEffect("fatal_poison")
    }
    if (itemUsed.typeId === "nicothekid:jar_milk_full") {
      player.removeEffect("fatal_poison")
      player.removeEffect("levitation")
      player.removeEffect("mining_fatigue")
      player.removeEffect("nausea")
      player.removeEffect("poison")
      player.removeEffect("weakness")
    }
    if (itemUsed.typeId === "nicothekid:jar_milk_half") {
      player.removeEffect("fatal_poison")
      player.removeEffect("levitation")
      player.removeEffect("mining_fatigue")
      player.removeEffect("nausea")
      player.removeEffect("poison")
      player.removeEffect("weakness")
    }
    if (itemUsed.typeId === "nicothekid:jar_sweet_berry_juice_full") {
      player.removeEffect("hunger")
    }
    if (itemUsed.typeId === "nicothekid:jar_sweet_berry_juice_half") {
      player.removeEffect("hunger")
    }
    if (itemUsed.typeId === "nicothekid:lapis_lazuli_apple") {
      player.addEffect("speed", 1200, {amplifier: 1, showParticles: true })
      player.addEffect("regeneration", 300, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:moss_berry_cookie") {
      player.addEffect("regeneration", 200, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:moss_berry_pie") {
      player.addEffect("regeneration", 400, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:mosshroom_stew") {
      player.addEffect("regeneration", 300, {amplifier: 0, showParticles: true })
      player.addEffect("mining_fatigue", 300, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:moa_raw") {
      let hungerChance = Math.random();
      if (hungerChance <= 0.3) {
        player.addEffect("hunger", 600, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:netherite_apple") {
      player.addEffect("resistance", 4800, {amplifier: 2, showParticles: true })
      player.addEffect("absorption", 3600, {amplifier: 1, showParticles: true })
      player.addEffect("strength", 3600, {amplifier: 1, showParticles: true })
      player.addEffect("regeneration", 1200, {amplifier: 1, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:pea_stew") {
      let nauseaChance = Math.random();
      if (nauseaChance <= 0.1) {
        player.addEffect("nausea", 200, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:potato_soup") {
      player.removeEffect("hunger")
      player.removeEffect("nausea")
    }
    if (itemUsed.typeId === "nicothekid:pumpkin_slice") {
      let nauseaChance = Math.random();
      if (nauseaChance <= 0.25) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:rat_raw") {
      let hungerChance = Math.random();
      if (hungerChance <= 0.3) {
        player.addEffect("hunger", 600, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:rotten_brute_flesh") {
      player.addEffect("strength", 2400, {amplifier: 0, showParticles: true })
      player.addEffect("hunger", 600, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:seagrass_stew") {
      let nauseaChance = Math.random();
      if (nauseaChance <= 0.25) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:soup") {
      player.removeEffect("hunger")
    }
    if (itemUsed.typeId === "nicothekid:squirrel_raw") {
      let hungerChance = Math.random();
      if (hungerChance <= 0.3) {
        player.addEffect("hunger", 600, {amplifier: 0, showParticles: true })
      }
    }
    if (itemUsed.typeId === "nicothekid:sweet_berry_cookie") {
      player.addEffect("regeneration", 200, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:sweet_berry_pie") {
      player.addEffect("regeneration", 300, {amplifier: 0, showParticles: true })
    }
    if (itemUsed.typeId === "nicothekid:warped_stew") {
      let nauseaChance = Math.random();
      let poisonChance = Math.random();
      if (nauseaChance <= 0.25) {
        player.addEffect("nausea", 300, {amplifier: 0, showParticles: true })
      }
      if (poisonChance <= 0.1) {
        player.addEffect("poison", 200, {amplifier: 0, showParticles: true })
      }
    }
	}
	else return;
});