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


function isCropFullyGrownFromPermutation(typeId, perm) {
  if (!perm) return false;

  // wheat/carrots/potatoes: growth 0..7
  if (typeId === "minecraft:wheat" ||
    typeId === "minecraft:carrots" ||
    typeId === "minecraft:potatoes") {
    return perm.getState("growth") === 7;
  }

  // beetroots: growth 0..3
  if (typeId === "minecraft:beetroots") {
    return perm.getState("growth") === 3;
  }

  // nether wart: age 0..3
  if (typeId === "minecraft:nether_wart") {
    return perm.getState("age") === 3;
  }

  return false;
}

function isSupportedCrop(typeId) {
  return typeId === "minecraft:wheat" ||
    typeId === "minecraft:carrots" ||
    typeId === "minecraft:potatoes" ||
    typeId === "minecraft:beetroots" ||
    typeId === "minecraft:nether_wart";
}


world.afterEvents.playerBreakBlock.subscribe(e => {
  const player = e.player;
  if (!player || player.getGameMode() !== "Survival") return;

  const k = player.name;
  const insomnio = getInsomnio(player);
  const extraChance = insomnio > 50000 ? 0 : getExtraChance(player, insomnio);

  if (insomnio <= 50000) {
    if (extraChance > 0 && Math.random() < extraChance) {

      const blockId_after = e.block?.typeId ?? "undefined";
      const blockId_broken = e.brokenBlockPermutation?.type?.id ?? "undefined";

      const typeIdBefore =
        blockId_broken !== "undefined" ? blockId_broken : blockId_after;

      if (isSupportedCrop(typeIdBefore)) {
        const grown = isCropFullyGrownFromPermutation(typeIdBefore, e.brokenBlockPermutation);
        if (!grown) return;
      }

      //try {
       // e.player.sendMessage(`§c[DEBUG] after=${blockId_after} | broken=${blockId_broken}`);
     // } catch (_) { }

      const typeId = typeIdBefore;
      const cfg = VANILLA_ORE_CONFIG[typeId];

   //  try {
   //     e.player.sendMessage(`§e[DEBUG] lookup=${typeId} | cfg=${cfg ? "OK" : "MISS"}`);
   //   } catch (_) { }

      if (!cfg) return;

      handleOreDrop(e, cfg.tools, cfg.loot, cfg.xp);
    }
  }
});



export const event_mimic = {
  onPlayerBreak: (e, summonVariant) => {
    // Asegurarse de que el evento tiene la información necesaria
    if (!e.player || !e.block) return;

    // Verificar si el jugador está en modo supervivencia
    if (e.player.getGameMode() !== "Survival") return;

    // Obtener herramienta en mano principal
    const equip = e.player.getComponent(EntityEquippableComponent.componentId);
    if (!equip) return;

    const mainhand = equip.getEquipment(EquipmentSlot.Mainhand);

    // Ejecutar acción si no hay herramienta en la mano
    if (!mainhand) {
      executeRandomAction(e.block.location, e.block.dimension, summonVariant);
      return;
    }

    // Verificar si el objeto tiene el componente 'enchantable'
    const enchantable = mainhand.getComponent("enchantable");
    if (!enchantable) {
      executeRandomAction(e.block.location, e.block.dimension, summonVariant);
      return;
    }

    // Revisar si tiene el encantamiento Silk Touch
    const silkTouch = enchantable.getEnchantment("silk_touch");

    // Ejecutar acción si NO tiene Silk Touch
    if (!silkTouch) {
      executeRandomAction(e.block.location, e.block.dimension, summonVariant);
    }
  },
};

function executeRandomAction(location, dimension, summonVariant) {
  const randomChoice = Math.random();
  if (randomChoice < 0.5) {
    const summonCommand = `summon otherworldly_winter:mimic ${location.x} ${location.y} ${location.z} facing @r minecraft:make_${summonVariant}`;
    dimension.runCommand(summonCommand);
  } else {
    const lootCommand = `loot spawn ${location.x} ${location.y} ${location.z} loot "entities/mimic"`;
    dimension.runCommand(lootCommand);
  }
}

// Eventos específicos
export const event_mimic1 = { onPlayerBreak: (e) => event_mimic.onPlayerBreak(e, "variant1") };
export const event_mimic2 = { onPlayerBreak: (e) => event_mimic.onPlayerBreak(e, "variant2") };
export const event_mimic3 = { onPlayerBreak: (e) => event_mimic.onPlayerBreak(e, "variant3") };
export const event_mimic4 = { onPlayerBreak: (e) => event_mimic.onPlayerBreak(e, "variant4") };
export const event_mimic5 = { onPlayerBreak: (e) => event_mimic.onPlayerBreak(e, "variant5") };


export const event_deepslate = {
  onPlayerBreak: e => {
    let players = world.getPlayers();
    for (let player of players) {
      const item = player.getComponent('inventory')?.container.getItem(e.player.selectedSlotIndex);
      if ((e.player.getGameMode() == 'Survival') && (
        item?.typeId === 'minecraft:stone_pickaxe' ||
        item?.typeId === 'dungeon:wooden_pickaxe' ||
        item?.typeId === 'minecraft:gold_pickaxe' ||
        item?.typeId === 'minecraft:iron_pickaxe' ||
        item?.typeId === 'minecraft:diamond_pickaxe' ||
        item?.typeId === 'dungeon:cobalt_hammer' ||
        item?.typeId === 'dungeon:bone_pickaxe' ||
        item?.typeId === 'minecraft:netherite_pickaxe' ||
        item?.typeId === 'dungeon:silvirum_pickaxe' ||
        item?.typeId === 'dungeon:glimmerite_pickaxe' ||
        item?.typeId === 'dungeon:viritum_pickaxe' ||
        item?.typeId === 'dungeon:glimmerite_hammer'
      )) {
        const silk_touch = item.getComponent('enchantable')?.getEnchantment('silk_touch');
        if (!silk_touch) {
          e.block.dimension.runCommand(`loot spawn ${e.block.location.x} ${e.block.location.y} ${e.block.location.z} loot "blocks/deep_stone"`);
        } else {
          e.block.dimension.runCommand(`loot spawn ${e.block.location.x} ${e.block.location.y} ${e.block.location.z} loot "blocks/silk_deep_stone"`);
        }
      }
    }
  },
};

export const event_stone = {
  onPlayerBreak: e => {
    let players = world.getPlayers();
    for (let player of players) {
      const item = player.getComponent('inventory')?.container.getItem(e.player.selectedSlotIndex);
      if ((e.player.getGameMode() == 'Survival') && (
        item?.typeId === 'minecraft:stone_pickaxe' ||
        item?.typeId === 'minecraft:wooden_pickaxe' ||
        item?.typeId === 'minecraft:gold_pickaxe' ||
        item?.typeId === 'minecraft:iron_pickaxe' ||
        item?.typeId === 'minecraft:diamond_pickaxe' ||
        item?.typeId === 'dungeon:cobalt_hammer' ||
        item?.typeId === 'dungeon:bone_pickaxe' ||
        item?.typeId === 'minecraft:netherite_pickaxe' ||
        item?.typeId === 'dungeon:silvirum_pickaxe' ||
        item?.typeId === 'dungeon:glimmerite_pickaxe' ||
        item?.typeId === 'dungeon:viritum_pickaxe' ||
        item?.typeId === 'dungeon:glimmerite_hammer'
      )) {
        const silk_touch = item.getComponent('enchantable')?.getEnchantment('silk_touch');
        if (!silk_touch) {
          e.block.dimension.runCommand(`loot spawn ${e.block.location.x} ${e.block.location.y} ${e.block.location.z} loot "blocks/stone"`);
        } else {
          e.block.dimension.runCommand(`loot spawn ${e.block.location.x} ${e.block.location.y} ${e.block.location.z} loot "blocks/silk_stone"`);
        }
      }
    }
  },
};

// XP config (más calidad = más XP). Rango base + bonus por Fortuna
const ORE_XP = {
  farming: { baseMin: 1, baseMax: 1, bonusPerFortune: 1 },
  coal: { baseMin: 1, baseMax: 1, bonusPerFortune: 1 },
  copper: { baseMin: 1, baseMax: 1, bonusPerFortune: 1 },
  iron: { baseMin: 1, baseMax: 2, bonusPerFortune: 1 },
  redstone: { baseMin: 1, baseMax: 3, bonusPerFortune: 1 },
  lapis: { baseMin: 1, baseMax: 3, bonusPerFortune: 1 },
  gold: { baseMin: 1, baseMax: 6, bonusPerFortune: 1 },
  diamond: { baseMin: 2, baseMax: 7, bonusPerFortune: 1 },
  emerald: { baseMin: 2, baseMax: 6, bonusPerFortune: 1 },
  jade: { baseMin: 2, baseMax: 7, bonusPerFortune: 2 },
  tungsten: { baseMin: 2, baseMax: 7, bonusPerFortune: 2 },
  vitalife: { baseMin: 1, baseMax: 8, bonusPerFortune: 2 },
  glimmerite: { baseMin: 2, baseMax: 11, bonusPerFortune: 2 },
  viritum: { baseMin: 2, baseMax: 11, bonusPerFortune: 2 },
  titanium: { baseMin: 3, baseMax: 12, bonusPerFortune: 2 },
  luminarite: { baseMin: 1, baseMax: 4, bonusPerFortune: 2 },
  silver: { baseMin: 1, baseMax: 1, bonusPerFortune: 1 },
  cobalt: { baseMin: 1, baseMax: 2, bonusPerFortune: 1 },
};


const USE_XP_ORBS = true;      // true = spawnear orbes (visual). false = usar "exp puntos" (preciso)
const ORB_PER_POINT = 1;       // 1 orbe = 1 punto de exp
const MAX_ORBS_PER_BREAK = 24; // límite para evitar lag en una sola rotura
const MIXED_MODE = true;       // si la exp excede el límite de orbes, el resto en puntos (preciso)

// Dificultad base del mundo + "experto" por tag del jugador
function getDifficultyTier(player) {
  try {
    if (player?.hasTag?.("player_expert")) return "expert";

    // Bedrock Script API (estable)
    const d = world.getDifficulty(); // "peaceful" | "easy" | "normal" | "hard"
    if (d === "easy") return "easy";
    if (d === "normal") return "normal";
    if (d === "hard") return "hard";
  } catch (_) {}

  // Fallback 
  return "normal";
}

function getExtraChance(player, insomnio, fortuneLevel) {
  // Base por insomnio
  let base = 0.0;
  if (insomnio <= 25000) base = 0.1;
  else if (insomnio <= 80000) base = 0.01;
  else base = 0.0;

  const tier = getDifficultyTier(player);

  // perLevel según dificultad 
  const perLevelPct =
    tier === "easy"   ? 25 :
    tier === "normal" ? 50 :
    tier === "hard"   ? 75 :
                        100; // expert

  const perLevel = perLevelPct / 100;

  // Multiplicador extra al base según dificultad
  const baseMult =
    tier === "easy"   ? 1.00 :
    tier === "normal" ? 1.5 :
    tier === "hard"   ? 2 :
                        3; // expert (tag player_expert)

  base *= baseMult;

  const lvl = Math.min(3, Math.max(0, fortuneLevel | 0));
  const chance = base + (lvl * perLevel);

  return Math.min(1, Math.max(0.0, chance));
}

function tryCmd(executor, cmd) {
  try {
    const r = executor.runCommand(cmd);
    return { ok: true, r };
  } catch (e) {
    return { ok: false, e };
  }
}

function getInsomnio(player) {
  if (!player) return 0;

  // crear/obtener objective de forma estable (sin comandos, sin statusMessage)
  let obj = world.scoreboard.getObjective("insomnio");
  if (!obj) obj = world.scoreboard.addObjective("insomnio", "insomnio");

  const id = player.scoreboardIdentity;
  if (!id) return 0;

  const score = obj.getScore(id);
  return typeof score === "number" ? score : 0;
}

function spawnXpOrbs(dimension, location, count) {
  if (!dimension || !location || count <= 0) return;
  const capped = Math.min(count, MAX_ORBS_PER_BREAK);
  for (let i = 0; i < capped; i++) {
    const ox = location.x + (Math.random() * 0.6 - 0.3);
    const oy = location.y + (Math.random() * 0.4 + 0.2);
    const oz = location.z + (Math.random() * 0.6 - 0.3);
    tryCmd(dimension, `summon xp_orb ${ox} ${oy} ${oz}`);
  }
}

function giveXpPoints(player, amount, location, dimension) {
  if (amount <= 0) return;
  try {
    if (USE_XP_ORBS && dimension && location) {
      const desiredOrbs = Math.max(1, Math.ceil(amount * ORB_PER_POINT));
      if (desiredOrbs <= MAX_ORBS_PER_BREAK) {
        spawnXpOrbs(dimension, location, desiredOrbs);
      } else if (MIXED_MODE) {
        spawnXpOrbs(dimension, location, MAX_ORBS_PER_BREAK);
        const approxPointsFromOrbs = Math.floor(MAX_ORBS_PER_BREAK / ORB_PER_POINT);
        const remainder = Math.max(0, amount - approxPointsFromOrbs);
        if (remainder > 0) player.runCommand(`xp ${remainder}`);
      } else {
        spawnXpOrbs(dimension, location, MAX_ORBS_PER_BREAK);
      }
    } else {
      player.runCommand(`xp ${amount}`);
      player.runCommand(`playsound random.orb @s ~~~ 0.25`);
    }
  } catch (_) { }
}

const oreOnce = Object.create(null);

const clampFortune = (lvl) => (lvl < 0 ? 0 : lvl > 3 ? 3 : (lvl | 0));
const randInt = (min, max) => (Math.random() * (max - min + 1) + min) | 0;

function handleOreDrop(e, validPickaxes, lootTables, xpKey) {
  const player = e.player;
  if (!player || player.getGameMode() !== "Survival") return;

  const t = system.currentTick;
  const k = player.name;
  if (oreOnce[k] === t) return;
  oreOnce[k] = t;

  const block = e.block;
  const dim = block?.dimension;
  const loc = block?.location;
  if (!dim || !loc) return;

  const lootBase = lootTables?.default;
  if (!lootBase) return;

  const inv = player.getComponent("inventory");
  const item = inv?.container?.getItem(player.selectedSlotIndex) ?? null;
  const heldId = item?.typeId ?? "minecraft:air";

  if (validPickaxes) {
    if (validPickaxes instanceof Set) {
      if (!validPickaxes.has(heldId)) return;
    } else {
      if (!validPickaxes.includes(heldId)) return;
    }
  }

  // En minerales (validPickaxes existe) sigues exigiendo enchantable
  // En cultivos (validPickaxes null) NO bloqueas por no tener enchantable
  const ench = item?.getComponent("enchantable") ?? null;
  if (validPickaxes && !ench) return;

  if (ench?.getEnchantment("silk_touch")) return;

  const fortuneLevel = clampFortune(ench?.getEnchantment("fortune")?.level ?? 0);
  const insomnio = getInsomnio(player);

  const { x, y, z } = loc;
  const spawnLoot = (lootId) => tryCmd(dim, `loot spawn ${x} ${y} ${z} loot "${lootId}"`);

  const xpCfg = ORE_XP[xpKey];
  const giveOreXp = () => {
    if (!xpCfg) return;
    const bonus = xpCfg.bonusPerFortune * fortuneLevel;
    const min = xpCfg.baseMin + bonus;
    const max = xpCfg.baseMax + bonus;
    giveXpPoints(player, randInt(min, max), loc, dim);
  };

  spawnLoot(lootBase);
  giveOreXp();

  const extraChance = insomnio > 50000 ? 0 : getExtraChance(player, insomnio, fortuneLevel);

  if (extraChance > 0 && Math.random() < extraChance) {
    spawnLoot(lootBase);
  }

  if (fortuneLevel) {
    const lootFortune = lootTables?.[`fortune${fortuneLevel}`] || lootBase;
    spawnLoot(lootFortune);

    if (insomnio <= 50000 && extraChance > 0 && Math.random() < extraChance) {
      spawnLoot(lootFortune);
    }
  }

  if (xpCfg && insomnio >= 10000 && insomnio <= 50000) {
    giveOreXp();
  }
}


export const event_wooden_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [

      ],
      {
        fortune3: "blocks/fortune/wooden_crate3",
        fortune2: "blocks/fortune/wooden_crate2",
        fortune1: "blocks/fortune/wooden_crate1",
        default: "blocks/wooden_crate"
      },
      "coal"
    );
  }
};

export const event_cobalt_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/cobalt_crate3",
        fortune2: "blocks/fortune/cobalt_crate2",
        fortune1: "blocks/fortune/cobalt_crate1",
        default: "blocks/cobalt_crate"
      },
      "iron"
    );
  }
};

export const event_jungle_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [

      ],
      {
        fortune3: "blocks/fortune/jungle_crate3",
        fortune2: "blocks/fortune/jungle_crate2",
        fortune1: "blocks/fortune/jungle_crate1",
        default: "blocks/jungle_crate"
      },
      "coal"
    );
  }
};

export const event_diamond_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/diamond_crate3",
        fortune2: "blocks/fortune/diamond_crate2",
        fortune1: "blocks/fortune/diamond_crate1",
        default: "blocks/diamond_crate"
      },
      "diamond"
    );
  }
};

export const event_titanium_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/titanium_crate3",
        fortune2: "blocks/fortune/titanium_crate2",
        fortune1: "blocks/fortune/titanium_crate1",
        default: "blocks/titanium_crate"
      },
      "titanium"
    );
  }
};

export const event_viritum_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'dungeon:silvirum_pickaxe'
      ],
      {
        fortune3: "blocks/fortune/viritum_crate3",
        fortune2: "blocks/fortune/viritum_crate2",
        fortune1: "blocks/fortune/viritum_crate1",
        default: "blocks/viritum_crate"
      },
      "viritum"
    );
  }
};

export const event_glimmerite_crate = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'dungeon:silvirum_pickaxe'
      ],
      {
        fortune3: "blocks/fortune/glimmerite_crate3",
        fortune2: "blocks/fortune/glimmerite_crate2",
        fortune1: "blocks/fortune/glimmerite_crate1",
        default: "blocks/glimmerite_crate"
      },
      "glimmerite"
    );
  }
};

export const event_redstone = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/redstone_ore3",
        fortune2: "blocks/fortune/redstone_ore2",
        fortune1: "blocks/fortune/redstone_ore1",
        default: "blocks/redstone_ore"
      },
      "redstone"
    );
  }
};

export const event_glimmerite = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_hammer',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe'
      ],
      {
        fortune3: "blocks/fortune/glimmerite_ore3",
        fortune2: "blocks/fortune/glimmerite_ore2",
        fortune1: "blocks/fortune/glimmerite_ore1",
        default: "blocks/glimmerite_ore"
      },
      "glimmerite"
    );
  }
};

export const event_viritum = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'dungeon:viritum_pickaxe','dungeon:silvirum_pickaxe'
      ],
      {
        fortune3: "blocks/fortune/viritum_ore3",
        fortune2: "blocks/fortune/viritum_ore2",
        fortune1: "blocks/fortune/viritum_ore1",
        default: "blocks/viritum_ore"
      },
      "viritum"
    );
  }
};

export const event_iron = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/iron_ore3",
        fortune2: "blocks/fortune/iron_ore2",
        fortune1: "blocks/fortune/iron_ore1",
        default: "blocks/iron_ore"
      },
      "iron"
    );
  }
};

export const event_luminarite = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/luminarite_ore3",
        fortune2: "blocks/fortune/luminarite_ore2",
        fortune1: "blocks/fortune/luminarite_ore1",
        default: "blocks/luminarite_ore"
      },
      "luminarite"
    );
  }
};

export const event_coal = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:wooden_pickaxe',
        'minecraft:gold_pickaxe',
        'minecraft:iron_pickaxe',
        'dungeon:bone_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/coal_ore3",
        fortune2: "blocks/fortune/coal_ore2",
        fortune1: "blocks/fortune/coal_ore1",
        default: "blocks/coal_ore"
      },
      "coal"
    );
  }
};

export const event_gold = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/gold_ore3",
        fortune2: "blocks/fortune/gold_ore2",
        fortune1: "blocks/fortune/gold_ore1",
        default: "blocks/gold_ore"
      },
      "gold"
    );
  }
};

export const event_copper = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/copper_ore3",
        fortune2: "blocks/fortune/copper_ore2",
        fortune1: "blocks/fortune/copper_ore1",
        default: "blocks/copper_ore"
      },
      "copper"
    );
  }
};

export const event_vitalife = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/vitalife_ore3",
        fortune2: "blocks/fortune/vitalife_ore2",
        fortune1: "blocks/fortune/vitalife_ore1",
        default: "blocks/vitalife_ore"
      },
      "vitalife"
    );
  }
};

export const event_diamond = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/diamond_ore3",
        fortune2: "blocks/fortune/diamond_ore2",
        fortune1: "blocks/fortune/diamond_ore1",
        default: "blocks/diamond_ore"
      },
      "diamond"
    );
  }
};

export const event_lapis = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:bone_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/c",
        fortune2: "blocks/fortune/lapis_ore2",
        fortune1: "blocks/fortune/lapis_ore1",
        default: "blocks/lapis_ore"
      },
      "lapis"
    );
  }
};

export const event_emerald = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/emerald3",
        fortune2: "blocks/fortune/emerald2",
        fortune1: "blocks/fortune/emerald1",
        default: "blocks/emerald"
      },
      "emerald"
    );
  }
};

export const event_jade = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:netherite_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/jade3",
        fortune2: "blocks/fortune/jade2",
        fortune1: "blocks/fortune/jade1",
        default: "blocks/jade"
      },
      "jade"
    );
  }
};

export const event_tungsten = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/tungsten3",
        fortune2: "blocks/fortune/tungsten2",
        fortune1: "blocks/fortune/tungsten1",
        default: "blocks/tungsten_ore"
      },
      "tungsten"
    );
  }
};

export const event_titanium = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'dungeon:silvirum_pickaxe'
      ],
      {
        fortune3: "blocks/fortune/titanium3",
        fortune2: "blocks/fortune/titanium2",
        fortune1: "blocks/fortune/titanium1",
        default: "blocks/titanium_ore"
      },
      "titanium"
    );
  }
};

export const event_silver = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'dungeon:wooden_pickaxe',
        'minecraft:gold_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/silver_ore3",
        fortune2: "blocks/fortune/silver_ore2",
        fortune1: "blocks/fortune/silver_ore1",
        default: "blocks/silver_ore"
      },
      "silver"
    );
  }
};

export const event_cobalt = {
  onPlayerBreak: e => {
    handleOreDrop(e,
      [
        'minecraft:stone_pickaxe',
        'minecraft:copper_pickaxe',
        'minecraft:gold_pickaxe',
        'minecraft:iron_pickaxe',
        'minecraft:diamond_pickaxe',
        'dungeon:cobalt_hammer',
        'dungeon:bone_pickaxe',
        'minecraft:netherite_pickaxe',
        'dungeon:silvirum_pickaxe',
        'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe',
        'dungeon:glimmerite_hammer'
      ],
      {
        fortune3: "blocks/fortune/cobal_ore3",
        fortune2: "blocks/fortune/cobal_ore2",
        fortune1: "blocks/fortune/cobal_ore1",
        default: "blocks/cobalt_ore"
      },
      "cobalt"
    );
  }
};


const VANILLA_ORE_CONFIG = {
  // COAL
  "minecraft:coal_ore": {
    tools: [
      'minecraft:wooden_pickaxe', 'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:gold_pickaxe',
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:wooden_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/coal_ore"
    },
    xp: "coal"
  },
  "minecraft:deepslate_coal_ore": {
    tools: [
      'minecraft:wooden_pickaxe', 'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:gold_pickaxe',
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:wooden_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/coal_ore"
    },
    xp: "coal"
  },

  // COPPER
  "minecraft:copper_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:wooden_pickaxe', 'dungeon:cobalt_hammer',
      'dungeon:bone_pickaxe', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/copper_ore"
    },
    xp: "copper"
  },
  "minecraft:deepslate_copper_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:wooden_pickaxe', 'dungeon:cobalt_hammer',
      'dungeon:bone_pickaxe', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/copper_ore"
    },
    xp: "copper"
  },

  // IRON
  "minecraft:iron_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/iron_ore"
    },
    xp: "iron"
  },
  "minecraft:deepslate_iron_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/iron_ore"
    },
    xp: "iron"
  },

  // GOLD
  "minecraft:gold_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/gold_ore"
    },
    xp: "gold"
  },
  "minecraft:deepslate_gold_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/gold_ore"
    },
    xp: "gold"
  },

  // REDSTONE
  "minecraft:redstone_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/redstone_ore"
    },
    xp: "redstone"
  },
  "minecraft:deepslate_redstone_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/redstone_ore"
    },
    xp: "redstone"
  },

  // LAPIS
  "minecraft:lapis_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/lapis_ore"
    },
    xp: "lapis"
  },
  "minecraft:deepslate_lapis_ore": {
    tools: [
      'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe',
      'minecraft:netherite_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/lapis_ore"
    },
    xp: "lapis"
  },

  // DIAMOND
  "minecraft:diamond_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/diamond_ore"
    },
    xp: "diamond"
  },
  "minecraft:deepslate_diamond_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/diamond_ore"
    },
    xp: "diamond"
  },

  // EMERALD
  "minecraft:emerald_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/emerald"
    },
    xp: "emerald"
  },
  "minecraft:deepslate_emerald_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/deepslate_emerald_ore"
    },
    xp: "emerald"
  },

  // NETHER QUARTZ
  "minecraft:nether_quartz_ore": {
    tools: [
      'minecraft:wooden_pickaxe', 'minecraft:stone_pickaxe',
      'minecraft:copper_pickaxe', 'minecraft:gold_pickaxe',
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:wooden_pickaxe', 'dungeon:cobalt_hammer', 'dungeon:bone_pickaxe',
      'dungeon:silvirum_pickaxe', 'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/nether_quartz_ore"
    },
    xp: "coal" // usa la misma XP que coal
  },

  // NETHER GOLD
  "minecraft:nether_gold_ore": {
    tools: [
      'minecraft:iron_pickaxe', 'minecraft:diamond_pickaxe', 'minecraft:netherite_pickaxe',
      'dungeon:cobalt_hammer', 'dungeon:silvirum_pickaxe',
      'dungeon:glimmerite_pickaxe','dungeon:viritum_pickaxe', 'dungeon:glimmerite_hammer'
    ],
    loot: {
      default: "blocks/nether_gold_ore"
    },
    xp: "gold"
  },

  "minecraft:wheat": {
    tools: [
      "minecraft:wooden_hoe", "minecraft:stone_hoe","minecraft:copper_hoe", "minecraft:iron_hoe",
      "minecraft:diamond_hoe", "minecraft:netherite_hoe", "dungeon:silver_hoe", "dungeon:cobalt_hoe", "dungeon:titanium_hoe", "dungeon:tungsten_hoe"
    ],
    loot: {
      fortune3: "blocks/fortune/wheat3",
      fortune2: "blocks/fortune/wheat2",
      fortune1: "blocks/fortune/wheat1",
      default: "blocks/wheat"
    },
    xp: "farming"
  },

  "minecraft:carrots": {
    tools: [
      "minecraft:wooden_hoe", "minecraft:stone_hoe","minecraft:copper_hoe", "minecraft:iron_hoe",
      "minecraft:diamond_hoe", "minecraft:netherite_hoe", "dungeon:silver_hoe", "dungeon:cobalt_hoe", "dungeon:titanium_hoe", "dungeon:tungsten_hoe"
    ],
    loot: {
      fortune3: "blocks/fortune/carrots3",
      fortune2: "blocks/fortune/carrots2",
      fortune1: "blocks/fortune/carrots1",
      default: "blocks/carrots"
    },
    xp: "farming"
  },

  "minecraft:potatoes": {
    tools: [
      "minecraft:wooden_hoe", "minecraft:stone_hoe","minecraft:copper_hoe", "minecraft:iron_hoe",
      "minecraft:diamond_hoe", "minecraft:netherite_hoe", "dungeon:silver_hoe", "dungeon:cobalt_hoe", "dungeon:titanium_hoe", "dungeon:tungsten_hoe"
    ],
    loot: {
      fortune3: "blocks/fortune/potatoes3",
      fortune2: "blocks/fortune/potatoes2",
      fortune1: "blocks/fortune/potatoes1",
      default: "blocks/potatoes"
    },
    xp: "farming"
  },

  "minecraft:beetroot": {
    tools: [
      "minecraft:wooden_hoe", "minecraft:stone_hoe","minecraft:copper_hoe", "minecraft:iron_hoe",
      "minecraft:diamond_hoe", "minecraft:netherite_hoe", "dungeon:silver_hoe", "dungeon:cobalt_hoe", "dungeon:titanium_hoe", "dungeon:tungsten_hoe"
    ],
    loot: {
      fortune3: "blocks/fortune/beetroots3",
      fortune2: "blocks/fortune/beetroots2",
      fortune1: "blocks/fortune/beetroots1",
      default: "blocks/beetroots"
    },
    xp: "farming"
  },

  "minecraft:nether_wart": {
    tools: [
      "minecraft:wooden_hoe", "minecraft:stone_hoe","minecraft:copper_hoe", "minecraft:iron_hoe",
      "minecraft:diamond_hoe", "minecraft:netherite_hoe", "dungeon:silver_hoe", "dungeon:cobalt_hoe", "dungeon:titanium_hoe", "dungeon:tungsten_hoe"
    ],
    loot: {
      fortune3: "blocks/fortune/nether_wart3",
      fortune2: "blocks/fortune/nether_wart2",
      fortune1: "blocks/fortune/nether_wart1",
      default: "blocks/nether_wart"
    },
    xp: "farming"
  }

};
