import { world } from 'mojang-minecraft'

world.events.tick.subscribe((ev) => {
 for (let player of world.getPlayers()) {
  const inv = player.getComponent("inventory").container;
  const item = inv.getItem(player.selectedSlot);
  
    if (!item){
      return;
    }
  
  if (item.id === 'pixel:iron_greatsword'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (item.id === 'pixel:stone_greatsword'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 1")
    }
  if (item.id === 'pixel:netherite_greatsword'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (item.id === 'pixel:iron_odachi'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (item.id === 'pixel:iron_odachi_vltsb'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (item.id === 'pixel:iron_odachi_rndtsb'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (item.id === 'pixel:iron_odachi_rdsmtsb'){
    player.runCommand("execute @s ~ ~ ~ effect @s slowness 1 2")
    }
  if (!item){
    break;
    }
  }
})
