import { world,  ItemStack, Entity,  ItemTypes, EntityInventoryComponent, Block,  } from "@minecraft/server"
import { system, Vector } from "@minecraft/server";
import { ActionFormData, MessageFormData, ModalFormData } from "@minecraft/server-ui"

world.afterEvents.itemReleaseUse.subscribe(data => {
    if(data.itemStack.typeId == 'better_on_bedrock:nether_amulet_3_stone_yellow_red_green' && data.useDuration <= 24 && data.source.isSneaking == false) {
        
        console.warn(data.useDuration)
        
    }
    if(data.itemStack.typeId == 'better_on_bedrock:nether_amulet_3_stone_yellow_red_green' && data.useDuration >= 24 && data.source.isSneaking == false){
         
    }
})
world.afterEvents.itemStartUse.subscribe(data => {
    if(data.useDuration >= 25 && data.source.isSneaking == true){
        
        const zombie =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombies =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiess =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiesss =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))

        const zombiew =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiesw =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiessw =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiesssw =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))

        const zombiews =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiesws =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiessws =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))
        const zombiesssws  =  world.getDimension('overworld').spawnEntity('minecraft:snowball', new Vector(data.source.location.x, data.source.location.y + 10, data.source.location.z))

  zombie.clearVelocity();
  zombies.clearVelocity();
  zombiess.clearVelocity();
  zombiesss.clearVelocity();

  zombiew.clearVelocity();
  zombiesw.clearVelocity();
  zombiessw.clearVelocity();
  zombiesssw.clearVelocity();

  zombiews.clearVelocity();
  zombiesws.clearVelocity();
  zombiessws.clearVelocity();
  zombiesssws.clearVelocity();

  // throw the zombie up in the air
  //zombie.applyImpulse({ x: data.source.getViewDirection().x, y: data.source.getViewDirection().y, z: data.source.getViewDirection().z });
  zombie.applyImpulse({ x: 1, y: 0, z: 0 });
  zombies.applyImpulse({ x: 0, y: 0, z: 1 });
  zombiess.applyImpulse({ x: -1, y: 0, z: 0 });
  zombiesss.applyImpulse({ x: 0, y: 0, z: -1 });

  zombiew.applyImpulse({ x: 1, y: 0, z: -1 });
  zombiesw.applyImpulse({ x: -1, y: 0, z: 1 });
  zombiessw.applyImpulse({ x: -1, y: 0, z: 1 });
  zombiesssw.applyImpulse({ x: 1, y: 0, z: -1 });

  zombiews.applyImpulse({ x: 1, y: 0, z: 1 });
  zombiesws.applyImpulse({ x: -1, y: 0, z: -1 });
  zombiessws.applyImpulse({ x:-1, y: 0, z: -1 });
  zombiesssws.applyImpulse({ x: 1, y: 0, z: 1 });
    }
})