import { world } from "@minecraft/server";
world.afterEvents.itemUse.subscribe(event => {
    const item = event.itemStack
    const player = event.source
    const entities = player.getEntitiesFromViewDirection({ maxDistance: 7 }).forEach(event => {
        const entity = event.entity
        if (item.typeId === "minecraft:music_disc_11" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:eleven"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_13" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:thirteen"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_5" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:five"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_blocks" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:blocks"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_cat" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:cat"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_chirp" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:chirp"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "omni_science:music_disc_chaos" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:chaos"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_far" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:far"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_mall" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:mall"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_mellohi" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:mellohi"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_otherside" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:otherside"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_pigstep" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:pigstep"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_precipice" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:precipice"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_relic" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:relic"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_stal" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:stal"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_strad" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:strad"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_wait" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:wait"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_ward" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:ward"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_creator" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:creator"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
        if (item.typeId === "minecraft:music_disc_creator_music_box" && entity.typeId === "minecraft:creeper") {
            entity.runCommandAsync(`/summon omni_science:creeper_dj ~ ~ ~ ~ ~ "omni_science:creator_box"`)
            entity.runCommandAsync(`/teleport @e[type=creeper, r=0.1] ~ -66 ~`)
            player.runCommandAsync(`replaceitem entity @s slot.weapon.mainhand 0 air`)
        }
    })
})

//if creeper dj dies
world.afterEvents.entityDie.subscribe(event => {
    const entity = event.deadEntity
    if (entity?.typeId === 'omni_science:creeper_dj') {
        entity.runCommand('stopsound @a[r=20])')
    }
})