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

world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent("fm:block_tick", {
    onTick(eventData) {
      const player = eventData.player;
      const block = eventData.block;
      const dimension = eventData.dimension
//Normal collector
      if (block.typeId === 'fm:mana_c_2') {
        system.run(() => {
          block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~ fm:mana_c_3`);
        });
      }
      if (block.typeId === 'fm:mana_c_3') {
        system.run(() => {
        block.setType("fm:mana_c_4");
        });
      }
      if (block.typeId === 'fm:mana_c_4') {
        system.run(() => {
        block.setType("fm:mana_c_5");
        });
      }
//Cold collector
      if (block.typeId === 'fm:mana_c_cold2') {
        system.run(() => {
          block.setType("fm:mana_c_cold3");
        });
      }
      if (block.typeId === 'fm:mana_c_cold3') {
        system.run(() => {
        block.setType("fm:mana_c_cold4");
        });
      }
      if (block.typeId === 'fm:mana_c_cold4') {
        system.run(() => {
        block.setType("fm:mana_c_cold5");
        });
      }
      if (block.typeId === 'fm:mana_c_cold5') {
        system.run(() => {
        block.setType("fm:mana_c_cold");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_cold_aura ~ ~ ~`);
        });
      }
//Dark collector
      if (block.typeId === 'fm:mana_c_dark2') {
        system.run(() => {
          block.setType("fm:mana_c_dark3");
        });
      }
      if (block.typeId === 'fm:mana_c_dark3') {
        system.run(() => {
        block.setType("fm:mana_c_dark4");
        });
      }
      if (block.typeId === 'fm:mana_c_dark4') {
        system.run(() => {
        block.setType("fm:mana_c_dark5");
        });
      }
      if (block.typeId === 'fm:mana_c_dark5') {
        system.run(() => {
        block.setType("fm:mana_c_dark");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_dark_aura ~ ~ ~`);
        });
      }
//Empty collector
      if (block.typeId === 'fm:mana_c_empty2') {
        system.run(() => {
          block.setType("fm:mana_c_empty3");
        });
      }
      if (block.typeId === 'fm:mana_c_empty3') {
        system.run(() => {
        block.setType("fm:mana_c_empty4");
        });
      }
      if (block.typeId === 'fm:mana_c_empty4') {
        system.run(() => {
        block.setType("fm:mana_c_empty5");
        });
      }
      if (block.typeId === 'fm:mana_c_empty5') {
        system.run(() => {
        block.setType("fm:mana_c_empty");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_empty_aura ~ ~ ~`);
        });
      }
//Fire collector
      if (block.typeId === 'fm:mana_c_fire2') {
        system.run(() => {
          block.setType("fm:mana_c_fire3");
        });
      }
      if (block.typeId === 'fm:mana_c_fire3') {
        system.run(() => {
        block.setType("fm:mana_c_fire4");
        });
      }
      if (block.typeId === 'fm:mana_c_fire4') {
        system.run(() => {
        block.setType("fm:mana_c_fire5");
        });
      }
      if (block.typeId === 'fm:mana_c_fire5') {
        system.run(() => {
        block.setType("fm:mana_c_fire");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_fire_aura ~~~`);
        });
      }
//Light collector
      if (block.typeId === 'fm:mana_c_light2') {
        system.run(() => {
          block.setType("fm:mana_c_light3");
        });
      }
      if (block.typeId === 'fm:mana_c_light3') {
        system.run(() => {
        block.setType("fm:mana_c_light4");
        });
      }
      if (block.typeId === 'fm:mana_c_light4') {
        system.run(() => {
        block.setType("fm:mana_c_light5");
        });
      }
      if (block.typeId === 'fm:mana_c_light5') {
        system.run(() => {
        block.setType("fm:mana_c_light");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_light_aura ~ ~ ~`);
        });
      }
//Nature collector
      if (block.typeId === 'fm:mana_c_nature2') {
        system.run(() => {
          block.setType("fm:mana_c_nature3");
        });
      }
      if (block.typeId === 'fm:mana_c_nature3') {
        system.run(() => {
        block.setType("fm:mana_c_nature4");
        });
      }
      if (block.typeId === 'fm:mana_c_nature4') {
        system.run(() => {
        block.setType("fm:mana_c_nature5");
        });
      }
      if (block.typeId === 'fm:mana_c_nature5') {
        system.run(() => {
        block.setType("fm:mana_c_nature");
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run summon fm:item_nature_aura ~ ~ ~`);
        });
      }
      
//Crucible      
      
      if (block.typeId === 'fm:cauldron_water') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function crucible_on`);
        });
      }
      if (block.typeId === 'fm:cauldron_on') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_blue ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_blue ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_blue ~~0.5~`);
        });
      }
            if (block.typeId === 'fm:cauldron_f_dusty') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_purple ~~0.5~`);
        });
      }
            if (block.typeId === 'fm:cauldron_mystic_flower') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
            if (block.typeId === 'fm:cauldron_pestle1') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_broom_search') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_dark_blood_rune2') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_dark_blood_rune1') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_white ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_white ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_white ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_gold1') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_chromerite') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_purple ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_pestle_2') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_void') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_pestle_3') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_thaulum') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_white ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_white ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_white ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_f_stone') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_purple ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_purple ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:cauldron_void_2') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ fire run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ lava run particle mob:bubble_orange ~~0.5~`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~-1~ campfire run particle mob:bubble_orange ~~0.5~`);
        });
      }
      if (block.typeId === 'fm:duplicator_block') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run execute if block ~~1~ mob:thaulum_block if block ~~-1~ mob:thaulum_block run function duplicator`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function duplicator_block_on`);
        });
      }
      if (block.typeId === 'fm:void_extractor_on') {
        system.run(() => {
        block.dimension.spawnParticle("mob:extractor_on", block.center());
        block.dimension.spawnParticle("mob:extractor_core", block.center());
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~1~~ air`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~-1~~ air`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~1 air`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~-1 air`);       
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~1~ air`);
        });
      }
      if (block.typeId === 'mob:demon_salt') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function mothgor`);
        
//Atractor
//isso Ta grande dms ;-;
       });
      }
      if (block.typeId === 'fm:atractor') {
        system.run(() => {
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function atractor`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function atractor_2`);
        block.dimension.runCommandAsync(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function atractor_3`);
        
        });
      }  
    }  
  });
});
