import {
  world,
  system,
  EntityDamageCause
} from "@minecraft/server";
world.beforeEvents.worldInitialize.subscribe(initEvent => {
  initEvent.blockComponentRegistry.registerCustomComponent('we:sculk_exp', {
    onPlayerDestroy(e) {
      if(e.player.matches({gameMode: 'creative'})) return;
      const block = e.block.center();
      const xpCount = 5;
      for (let i = 0; i < xpCount; i++) {
        const orb = e.dimension.spawnEntity('minecraft:xp_orb', block);
      }
    }
  });

initEvent.blockComponentRegistry.registerCustomComponent('we:sculk_jaws', {
    onStepOn(e) {
  
      const block = e.block;
      const entity = e.entity;
      if (entity.typeId === 'minecraft:warden' || entity.typeId === 'we:bruudlin') return;


      let hp = entity.getComponent('minecraft:health')
      if(!hp) return;
      entity.applyDamage(6, {cause: "fall"});
      entity.addEffect('blindness', 60);
      entity.addEffect('slowness', 120);
      e.dimension.playSound('mob.vex.charge', block.center(), {pitch: 1.4})
      e.dimension.playSound('mob.evocation_fangs.attack', block.center(), {pitch: 0.6})
    }
  });
});