import {
  world,
  system,
} from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('auxillium:exp_low', {
    onPlayerDestroy(e) { //0-2 Orbs (Same as Coal)
      if(e.player.matches({gameMode: 'creative'})) return;
      const block = e.block.center();
      const xpCount = Math.floor(Math.random() * 3);
      for (let i = 0; i < xpCount; i++) {
        const orb = e.dimension.spawnEntity('minecraft:xp_orb', block);
      }
    }
  }),

initEvent.blockComponentRegistry.registerCustomComponent('auxillium:exp_medium', {
    onPlayerDestroy(e) { // 2-5 orbs (Same as Quartz)
      if(e.player.matches({gameMode: 'creative'})) return;
      const block = e.block.center();
      const xpCount = 2+ Math.floor(Math.random() * 4);
      for (let i = 0; i < xpCount; i++) {
        const orb = e.dimension.spawnEntity('minecraft:xp_orb', block);
      }
    }
  }),

initEvent.blockComponentRegistry.registerCustomComponent('auxillium:exp_high', {
    onPlayerDestroy(e) { //3-7 orbs (same as Diamond)
      if(e.player.matches({gameMode: 'creative'})) return;
      const block = e.block.center();
      const xpCount = 3+Math.floor(Math.random() * 5);
      for (let i = 0; i < xpCount; i++) {
        const orb = e.dimension.spawnEntity('minecraft:xp_orb', block);
      }
    }
  })
});