import * as SERVER from '@minecraft/server';

//lab_amb//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:alcantarilla_amb', {
    onTick: e => alcantarilla_ambX(e.block)
});

});
function alcantarilla_ambX(block) {  

  block.dimension.getEntities({ location: block.location, maxDistance: 20 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {    
            player.runCommand(`playsound block.alcantarilla.ambient @a[r=20] ${block.location.x} ${block.location.y} ${block.location.z}`);
               
          });
            
      } 
  });  
      
   }
//deco city//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:deco_city1', {
      onTick: e => deco_city1X(e.block),
  });
});

function deco_city1X(block) {
  const genstructuresB = [
    
    'structure load sacrificio1 ~-2~~-2',
    'structure load sacrificio2 ~-2~~-2',
    'structure load sacrificio3 ~-2~~-2',
    'structure load sacrificio4 ~-2~~-2',
    'structure load sacrificio5 ~-2~~-2',
    'structure load sacrificio6 ~-2~~-2',
    'structure load sacrificio7 ~-2~~-2',,
    'structure load sacrificio8 ~-2~~-2',
    'structure load deco_city_ambient1 ~-3 ~ ~-3',
    'structure load deco_city_cordy3 ~-3 ~ ~-3',
    'structure load deco_city_cordy2 ~-3 ~ ~-3',
    'structure load deco_city_cordy1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_ambient1 ~-3 ~ ~-3',
    'structure load deco_city_cordy3 ~-3 ~ ~-3',
    'structure load deco_city_cordy2 ~-3 ~ ~-3',
    'structure load deco_city_cordy1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_ambient1 ~-3 ~ ~-3',
    'structure load deco_city_cordy3 ~-3 ~ ~-3',
    'structure load deco_city_cordy2 ~-3 ~ ~-3',
    'structure load deco_city_cordy1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_ambient1 ~-3 ~ ~-3',
    'structure load deco_city_cordy3 ~-3 ~ ~-3',
    'structure load deco_city_cordy2 ~-3 ~ ~-3',
    'structure load deco_city_cordy1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3',
    'structure load deco_city_x7 ~-3 ~ ~-3',
    'structure load deco_city_x6 ~-3 ~ ~-3',
    'structure load deco_city_x5 ~-3 ~ ~-3',
    'structure load deco_city_x4 ~-3 ~ ~-3',
    'structure load deco_city_x3 ~-3 ~ ~-3',
    'structure load deco_city_x2 ~-3 ~ ~-3',
    'structure load deco_city_x1 ~-3 ~ ~-3'
  ];
  const bases2Load = genstructuresB[Math.floor(Math.random() * genstructuresB.length)];
  block.dimension.getEntities({ location: block.location, maxDistance: 10 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {
            player.runCommand(Math.random() < 0.2 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${bases2Load}`:
          `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~ moss_block`);
          block.setType('minecraft:moss_block');
        });
            
      } 
  });
}

//ALCANTARILLA//
//alc_horizontalX//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:alc_horizontalX', {
    onTick: e => alc_horizontalX(e.block)
});

});
  function alc_horizontalX(block) {  
    block.dimension.getEntities({ location: block.location, maxDistance: 32 })
    .forEach(entity => {
        if (entity.typeId == 'minecraft:player') {
            block.dimension.getPlayers().forEach(player => {    
              player.runCommand(Math.random() < 0.5 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run structure load az2_o ~~~1` : `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run structure load azc ~~~1`);   
  block.setType('minecraft:air');
            });
              
        } 
    });  
        
     }
//alc_verticalX//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:alc_verticalX', {
    onTick: e => alc_verticalX(e.block)
});

});
function alc_verticalX(block) {  
  const genstructuresB2 = [
    'structure load az1 ~1~-1~-5',
    'structure load az2 ~1~-1~-9',
    'structure load az2 ~1~-1~-9',
    'structure load alc_center_v ~1~-3~-12',
    'structure load az1 ~1~-1~-5'
  ];
  const genstructuresB3 = [
    'structure load az3 ~1~-12~-5',
    'structure load az3 ~1~-12~-5',
    'structure load az3 ~1~-12~-5',
    'structure load alc_center_v ~1~-3~-12',
    'structure load alc_rat_king ~1~1~-4'
  ];
  const summon = genstructuresB2[Math.floor(Math.random() * genstructuresB2.length)];    
  const summon2 = genstructuresB3[Math.floor(Math.random() * genstructuresB3.length)]; 
  block.dimension.getEntities({ location: block.location, maxDistance: 32 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {   
          player.runCommand(Math.random() < 0.5 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon}` : `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon2}`);   
      block.setType('minecraft:air'); 
          });
            
      } 
  });  
      
   }
//base_casaX//bases//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:base_casaX', {
    onTick: e => base_casaX(e.block)
});

});
function base_casaX(block) {  
  const genstructuresB2 = [
    
    'structure load sacrificio1 ~-2~~-2',
    'structure load sacrificio2 ~-2~~-2',
    'structure load sacrificio3 ~-2~~-2',
    'structure load sacrificio4 ~-2~~-2',
    'structure load sacrificio5 ~-2~~-2',
    'structure load sacrificio6 ~-2~~-2',
    'structure load sacrificio7 ~-2~~-2',
    'structure load sacrificio8 ~-2~~-2',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'structure load cordy1_deco ~-3~~-3',
    'structure load cordy2_deco ~-3~~-3',
    'structure load cordy3_deco ~-3~~-3',
    'structure load cordy4_deco ~-3~~-3',
    'structure load cordy5_deco ~-3~~-3',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico',
    'setblock ~~~ xaierg:plastico'
  ];
  const summon = genstructuresB2[Math.floor(Math.random() * genstructuresB2.length)];    
  const genstructuresB3 = [
    'structure load alc1_deco ~-2~~-2',
    'structure load alc2_deco ~-2~~-2',
    'structure load alc3_deco ~-2~~-2',
    'structure load alc4_deco ~-2~~-2',
    'structure load alc5_deco ~-2~~-2',
    'structure load alc1_deco ~-2~~-2',
    'structure load alc2_deco ~-2~~-2',
    'structure load alc3_deco ~-2~~-2',
    'structure load alc4_deco ~-2~~-2',
    'structure load alc5_deco ~-2~~-2',
    'structure load alc6_deco ~-3~~-3',
    'structure load alc7_deco ~-3~~-3',
    'structure load alc8_deco ~-3~~-3',
    'structure load alc9_deco ~-3~~-3',
    'structure load alc10_deco ~-3~~-3',
    'structure load alc11_deco ~-3~~-3',
    'structure load alc12_deco ~-3~~-3',
    'structure load embrion_child ~-3~~-3'
  ];
  const summon2 = genstructuresB3[Math.floor(Math.random() * genstructuresB3.length)]; 
  block.dimension.getEntities({ location: block.location, maxDistance: 16 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {   
            player.runCommand(Math.random() < 0.25 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon}` : `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon2}`);   
            block.setType('minecraft:dirt'); 
          });
            
      } 
  });  
      
   }
   //alcantarillax//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:alcantarillaX', {
    onTick: e => alcantarillaX(e.block)
});

});
function alcantarillaX(block) {   
  block.dimension.getEntities({ location: block.location, maxDistance: 16 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {   
            player.runCommand(`execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run function structure_alcantarilla`);   
            block.setType('minecraft:dirt'); 
          });
            
      } 
  });  
      
   }
//m_alc_horizontalX//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:m_alc_horizontalX', {
    onTick: e => m_alc_horizontalX(e.block)
});

});
function m_alc_horizontalX(block) {  
  const genstructuresB2 = [
    'structure load azcc2 ~-28~-2~',
    'structure load azcc2 ~~-2~'
  ];
  const summon = genstructuresB2[Math.floor(Math.random() * genstructuresB2.length)];    
  block.dimension.getEntities({ location: block.location, maxDistance: 16 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => { 
            player.runCommand(Math.random() < 0.15 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon}` : `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~ dirt`);   
   block.setType('minecraft:dirt'); 
          });
            
      } 
  });  
      
   }
//m_alc_verticalX//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('xaierg:m_alc_verticalX', {
    onTick: e => m_alc_verticalX(e.block)
});

});
function m_alc_verticalX(block) { 
  const genstructuresB2 = [
    'structure load azcc1 ~~-2~',
    'structure load azcc1 ~~-2~-28'
  ];
  const summon = genstructuresB2[Math.floor(Math.random() * genstructuresB2.length)];    
  block.dimension.getEntities({ location: block.location, maxDistance: 16 })
  .forEach(entity => {
      if (entity.typeId == 'minecraft:player') {
          block.dimension.getPlayers().forEach(player => {   
            player.runCommand(Math.random() < 0.15 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${summon}` : `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run setblock ~~~ dirt`);   
block.setType('minecraft:dirt'); 
          });
            
      } 
  });  
      
   }

   //decoraciones overworld adaptar//
   
//abandonadoX//
SERVER.world.beforeEvents.worldInitialize.subscribe(initEvent => {
    initEvent.blockComponentRegistry.registerCustomComponent('xaierg:abandonadX', {
        onTick: e => abandonadoX(e.block),
    });
  });
  
  function abandonadoX(block) {
    const genstructuresB = [
      'structure load aban2 ~-3~-2~-3',
      'structure load aban3 ~-3~-2~-3',
      'structure load aban4 ~-3~-2~-3',
      'structure load aban5 ~-3~-2~-3',
      'structure load aban6 ~-3~-2~-3',
      'structure load aban7 ~-3~-2~-3',
      'structure load aban8 ~-3~-2~-3',
      'structure load aban9 ~-3~-2~-3',
      'structure load aban10 ~-3~-2~-3',
      'structure load aban11 ~-3~-2~-3',
      'structure load aban12 ~-3~-2~-3',
      'structure load aban13 ~-3~-2~-3',
      'structure load aban14 ~-3~-2~-3',
      'structure load aban15 ~-3~-2~-3',
      'structure load aban16 ~-3~-2~-3',
      'structure load aban17 ~-3~-2~-3',
      'structure load aban18 ~-3~-2~-3',
      'structure load aban19 ~-3~-2~-3',
      'structure load aban20 ~-3~-2~-3',
      'structure load aban21 ~-3~-2~-3',
      'structure load aban22 ~-3~-2~-3',
      'structure load aban23 ~-3~-2~-3',
      'structure load aban24 ~-3~-2~-3',
      'structure load aban25 ~-3~-2~-3',
      'structure load aban26 ~-3~-2~-3',
      'structure load aban27 ~-3~-2~-3',
      'structure load aban28 ~-3~-2~-3',
      'structure load aban29 ~-3~-2~-3',
      'structure load aban30 ~-3~-2~-3',
      'structure load aban31 ~-3~-2~-3',
      'structure load aban32 ~-3~-2~-3',
      'structure load aban33 ~-3~-2~-3',
      'structure load aban34 ~-3~-2~-3',
      'structure load aban35 ~-3~-2~-3',
      'structure load aban36 ~-3~-2~-3',
      'structure load aban37 ~-3~-2~-3',
      'structure load aban38 ~-3~-2~-3',
      'structure load aban39 ~-4~-2~-4',
      'structure load aban40 ~-4~-2~-4',
      'structure load aban41 ~-4~-2~-4',
      'setblock ~~~1 xaierg:bases2',
    ];
    const bases2Load = genstructuresB[Math.floor(Math.random() * genstructuresB.length)];
    const genstructuresB2 = [
      'structure load zona_oscura ~-1~-9~-1',
      'structure load sacrificio1 ~-2~~-2',
      'structure load sacrificio2 ~-2~~-2',
      'structure load sacrificio3 ~-2~~-2',
      'structure load sacrificio4 ~-2~~-2',
      'structure load sacrificio5 ~-2~~-2',
      'setblock ~~~1 xaierg:bases2',
      'structure load aban1 ~-5~-2~-5'
    ];
    const bases2LoadF = genstructuresB2[Math.floor(Math.random() * genstructuresB2.length)];
    
    block.dimension.getEntities({ location: block.location, maxDistance: 128 })
    .forEach(entity => {
        if (entity.typeId == 'minecraft:player') {
            block.dimension.getPlayers().forEach(player => {
              player.runCommand(Math.random() < 0.5 ? `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${bases2Load}`:
            `execute positioned ${block.location.x} ${block.location.y} ${block.location.z} run ${bases2LoadF}`);
            block.setType('minecraft:moss_block');
          });
              
        } 
    });
  }
  

