import {
  world,
  system
} from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('dragons:undefined_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:undefined_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:bamboo_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:bamboo_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_bamboo ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:common_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:common_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_common ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:deadly_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:deadly_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_deadly ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:echo_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:echo_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_echo ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:fire_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:fire_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_fire ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:enchanted_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:enchanted_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_enchanted ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:forest_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:forest_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_forest ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:ghost_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:ghost_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_ghost ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:mycelium_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:mycelium_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_mycelium ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:nether_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:nether_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_nether ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:night_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:night_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_night ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:quake_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:quake_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_quake ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:snow_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:snow_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_snow ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:sky_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:sky_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_sky ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:tide_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:tide_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_tide ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  });

  initEvent.blockComponentRegistry.registerCustomComponent('dragons:void_egg', {
    onPlayerInteract(e) {
      const block = e.block;
      const player = e.player;

      block.setType('minecraft:air')

      const egg = block.dimension.spawnEntity('dragons:void_egg', block.bottomCenter());

      e.dimension.runCommandAsync(`particle dragons:egg_activate_void ${block.center().x} ${block.bottomCenter().y} ${block.center().z}`)
    }
  })
});