import { system, world, BlockVolume, BlockPermutation, Block, EquipmentSlot, ItemStack, EntityComponentTypes, ItemComponent, ItemComponentTypes } from '@minecraft/server'
import { CommandPermissionLevel, CustomCommandParamType, CustomCommandStatus } from "@minecraft/server";
import { ActionFormData, ModalFormData } from '@minecraft/server-ui'

system.beforeEvents.startup.subscribe(start => {
    start.blockComponentRegistry.registerCustomComponent('darkw_onyxdlc1:pylon', {
        onPlayerInteract: e => {
            const block = e.block
            const player = e.player
            const timeofDay = world.scoreboard.getObjective('darkw_onyxdlc1:time').getScore('darkw_onyxdlc1:timekeeper')
            const cells = block.permutation.getState('darkw_onyxdlc1:powercells')

            if (block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length != 0) player.runCommand('/tellraw @s {"rawtext":[{"text":"§cA raid is ongoing nearby."}]}')
            if (block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length != 0) block.dimension.playSound('mob.darkw_onyxdlc1.pylon.no', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                if (block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length != 0) return
            
            // * If player has all four cores inserted, Prompt the player.
            if (cells === 4) {
                if ((timeofDay > 0 && timeofDay < 12000)) {
                    block.dimension.playSound('mob.darkw_onyxdlc1.pylon.no', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    player.runCommand('/tellraw @s {"rawtext":[{"text":"§cRaids must be started at night."}]}')
                    return
                }
                
                block.dimension.playSound('mob.darkw_onyxdlc1.pylon.ui1', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                let settings = new ModalFormData()
                settings.title('Rotten Harvest | Setup')
                settings.label(`Welcome! With your pylon fully powered, you are ready to start a §dRotten Harvest§r! Below you will find a couple settings to select before you start. You will be prompted to select from two raid types and a difficulty.`)
                settings.divider()
                settings.label('§eRaid Types§f:\n\nNormal Mode:\n A normal raid, fight five waves of enemies, fight the boss and you win!\n\nEndless Mode:\n In this mode, you will fight endless waves until it becomes daytime! The raid repeats after every boss and the mobs get stronger.')
                settings.divider()
                settings.label('§eDifficulty§f:\n There are four difficulties to choose from before you start. Higher difficulty, more loot.\n\n§cYou must select a Raid Type and a Difficulty to start a raid.')
                settings.divider()
                settings.dropdown('Select a Raid Type:', ['- SELECT RAID TYPE -', 'Normal Mode', 'Endless Mode'])
                settings.dropdown('Select a Raid Difficulty:', ['- SELECT DIFFICULTY -', 'Standard   | (Easy)', 'Moderate   | (Medium)', 'Brutal       | (Hard)', 'Nightmare  | (Nightmare)'])
                settings.divider()
                settings.submitButton('Start')
                settings.show(player).then(r => {
                    if (r.canceled) return
                    let type = ['fail', 'Normal', 'Endless', 'Developer']
                    let difficulty = ['fail', 'Standard', 'Moderate', 'Brutal', 'Nightmare']
                    let typeSelect = type[r.formValues[6]]
                    let diffSelect = difficulty[r.formValues[7]]
                    if (typeSelect === 'fail') {
                        player.runCommand('/tellraw @s {"rawtext":[{"text":"§cYou did not select a Raid Type."}]}')
                        block.dimension.playSound('mob.darkw_onyxdlc1.pylon.no', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                        return
                    }
                    if (diffSelect === 'fail') {
                        player.runCommand('/tellraw @s {"rawtext":[{"text":"§cYou did not select a Difficulty."}]}')
                        block.dimension.playSound('mob.darkw_onyxdlc1.pylon.no', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                        return
                    }
                    
                    let raidendPromt = ""
                    if (typeSelect === "Normal") raidendPromt = "The raid will end when the boss is defeated."
                    if (typeSelect === "Endless") raidendPromt = "The raid will end at the end of the night."
                    
                    let confirm = new ActionFormData()
                    confirm.title('Rotten Harvest | Confirmation')
                    block.dimension.playSound('mob.darkw_onyxdlc1.pylon.ui1', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    let colorize1 = JSON.stringify(`§e${typeSelect}§f`).slice(1, -1)
                    let colorize2 = JSON.stringify(`§e${diffSelect}§f`).slice(1, -1)
                    confirm.divider()
                    confirm.label(`You are about to start a raid.\n\nRaid Type: ${colorize1}\nDifficulty: ${colorize2}\n\n${raidendPromt}`)
                    confirm.divider()
                    confirm.button('Start')
                    confirm.button('Cancel')
                    confirm.show(player).then(r => {
                        if (r.canceled) return
                        if (r.selection === 0) {
                            block.dimension.spawnParticle('darkw_onyxdlc1:pylon_charge_blow', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                            block.dimension.setBlockPermutation(block.location, BlockPermutation.resolve('darkw_onyxdlc1:pylon', { 'darkw_onyxdlc1:powercells': 0 }))
                            block.dimension.playSound('mob.darkw_onyxdlc1.pylon.ui2', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                            player.runCommand(`/tellraw @a[r=25] {"rawtext":[{"selector":"@p"},{"text":" started a ${typeSelect} Raid at ${diffSelect} difficulty!"}]}`)
                            if (typeSelect === "Normal") {
                                let waveSpawner = player.dimension.spawnEntity('darkw_onyxdlc1:wave_spawner', { x: block.location.x + 0.5, y: block.location.y + 1.5, z: block.location.z + 0.7 })
                                waveSpawner.setProperty('darkw_onyxdlc1:difficulty', diffSelect)
                                waveSpawner.setProperty('darkw_onyxdlc1:type', typeSelect)

                            }
                            if (typeSelect === "Endless") {
                                let waveSpawner = player.dimension.spawnEntity('darkw_onyxdlc1:wave_spawner_endless', { x: block.location.x + 0.5, y: block.location.y + 1.5, z: block.location.z + 0.7 })
                                waveSpawner.setProperty('darkw_onyxdlc1:difficulty', diffSelect)
                                waveSpawner.setProperty('darkw_onyxdlc1:type', typeSelect)
                            }
                        }
                    })
                })
            }

            // * Pylon not powered yet.
            let hasCore = player.runCommand('/testfor @s[hasitem={item=darkw_onyxdlc1:ettercore, location=slot.weapon.mainhand}]').successCount
            if (cells === 4) return
            if (!hasCore) { 
                let coresRemaining1 = 4 - cells
                let coresRemaining2 = cells === 1 ? '3TT3R-C0RE' : '3TT3R-C0REs'
                player.runCommand(`/tellraw @s {"rawtext":[{"text":"§cThis pylon needs ${coresRemaining1} more ${coresRemaining2} to start a raid."}]}`)
                block.dimension.playSound('mob.darkw_onyxdlc1.pylon.no', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                return
            }

            const item = player.getComponent('equippable').getEquipment('Mainhand')

            // * Has core in hand, update accordingly
            block.dimension.setBlockPermutation(block.location, BlockPermutation.resolve('darkw_onyxdlc1:pylon', { 'darkw_onyxdlc1:powercells': block.permutation.getState('darkw_onyxdlc1:powercells') + 1 }))
            switch (cells) {
                case 0: {
                    block.dimension.playSound('respawn_anchor.charge', block.location)
                    if (player.getGameMode() != 'Creative') replaceOnUseOrWhatever(player, item.amount, item.typeId)
                    break
                }
                case 1: {
                    block.dimension.playSound('respawn_anchor.charge', block.location)
                if (player.getGameMode() != 'Creative') replaceOnUseOrWhatever(player, item.amount, item.typeId)
                    break
                }
                case 2: {
                    block.dimension.playSound('respawn_anchor.charge', block.location)
                if (player.getGameMode() != 'Creative') replaceOnUseOrWhatever(player, item.amount, item.typeId)
                    break
                }
                case 3: {
                    block.dimension.playSound('respawn_anchor.set_spawn', block.location)
                    block.dimension.spawnParticle('darkw_onyxdlc1:pylon_powerup', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    if (player.getGameMode() != 'Creative') replaceOnUseOrWhatever(player, item.amount, item.typeId)
                    break
                }
            }
        },
        onTick: e => {
            const block = e.block
            const cells = block.permutation.getState('darkw_onyxdlc1:powercells')
            const timeofDay = world.scoreboard.getObjective('darkw_onyxdlc1:time').getScore('darkw_onyxdlc1:timekeeper')

            if (cells === 4 && (timeofDay > 12000 && timeofDay < 24000) && block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length > 0) block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power5_raid', { x: block.location.x + 0.5, y: block.location.y + 1, z: block.location.z + 0.5 })
            if (block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length != 0) return
            if (cells === 4 && (timeofDay > 12000 && timeofDay < 24000) && block.dimension.getEntities({ maxDistance: 15, families: ['roxcrow_waver'], location: block.location }).length === 0) block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power5', { x: block.location.x + 0.5, y: block.location.y + 1, z: block.location.z + 0.5 })

            block.dimension.getPlayers({ location: block.location, maxDistance: 5 }).forEach(player => {
                if (cells === 4 && (timeofDay > 12000 && timeofDay < 24000)) player.runCommand('/titleraw @s actionbar {"rawtext":[{"translate":"tile.darkw_onyxdlc1.allcoresin","with":{"rawtext":[{"text":""}]}}]}')
                if (cells === 4 && (timeofDay > 0 && timeofDay < 12000)) player.runCommand('/titleraw @s actionbar {"rawtext":[{"translate":"tile.darkw_onyxdlc1.allcoresin_daytime","with":{"rawtext":[{"text":""}]}}]}')
                if (cells < 4) player.runCommand(`/titleraw @s actionbar {"rawtext":[{"translate":"tile.darkw_onyxdlc1.entercores1","with":{"rawtext":[{"text":""}]}},{"text":"${4 - cells} "},{"translate":"tile.darkw_onyxdlc1.entercores2","with":{"rawtext":[{"text":""}]}}]}`)
            })

            switch (cells) {
                case 1: {
                    block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power1', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    break
                }
                case 2: {
                    block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power2', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    break
                }
                case 3: {
                    block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power3', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    break
                }
                case 4: {
                    block.dimension.spawnParticle('darkw_onyxdlc1:pylon_power4', { x: block.location.x + 0.5, y: block.location.y, z: block.location.z + 0.5 })
                    break
                }
            }

            return
            if ((timeofDay > 12000 && timeofDay < 24000) && block.permutation.getState('darkw_onyxdlc1:can_start_raid') === false && cells === 4) {
                block.dimension.setBlockPermutation(block.location, BlockPermutation.resolve('darkw_onyxdlc1:pylon', { 'darkw_onyxdlc1:can_start_raid': true }))
                block.
                    console.warn('ready')
            }
            if ((timeofDay < 12000 && timeofDay > 0) && block.permutation.getState('darkw_onyxdlc1:can_start_raid') === true && cells === 4) {
                block.dimension.setBlockPermutation(block.location, BlockPermutation.resolve('darkw_onyxdlc1:pylon', { 'darkw_onyxdlc1:can_start_raid': false }))
                console.warn('booo')
            }
        }
    })
    // * Bat Staff
    start.itemComponentRegistry.registerCustomComponent("darkw_onyxdlc1:bat_staff", {
        onUse: e => {
            const item = e.itemStack
            const player = e.source
            const dura = e.itemStack.getComponent('durability')

            // Stop if no durability
            if (dura.damage === dura.maxDurability) {
                return
            }

            // Do stuff if durabibility is good
            if (dura.damage != dura.maxDurability) {
                let damAmount = 125
                let afterDam = dura.damage + damAmount
                
                let spawnBatsInt = Math.floor((dura.maxDurability - dura.damage) / 40)
                for (let i = 0; i != spawnBatsInt; i++) {
                    player.dimension.spawnEntity('darkw_onyxdlc1:bat', player.location).triggerEvent('darkw_onyxdlc1:spawned_by_player_event')
                }
                
                if (afterDam >= dura.maxDurability) {
                    dura.damage = dura.maxDurability
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
                if (afterDam <= dura.maxDurability) {
                    dura.damage += damAmount
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
            }
        }
    })
    start.itemComponentRegistry.registerCustomComponent("darkw_onyxdlc1:firelantern", {
        onUse: e => {
            const item = e.itemStack
            const player = e.source
            const dura = e.itemStack.getComponent('durability')

            // Stop if no durability
            if (dura.damage === dura.maxDurability) {
                return
            }

            // Do stuff if durabibility is good
            if (dura.damage != dura.maxDurability) {
                let damAmount = 125
                let afterDam = dura.damage + damAmount




                player.runCommand('/playsound mob.darkw_onyxdlc1.roxcrow.pew @s ~ ~ ~')
                let spawnBatsInt = Math.floor((dura.maxDurability - dura.damage) / 40)
                for (let i = 0; i != spawnBatsInt; i++) {






                    const velRan = Math.random() * 1
                    const playerViewDirection = player.getViewDirection();
                    const velocityMultiplier = Math.random() * 2

                    const projectile = player.dimension.spawnEntity("darkw_onyxdlc1:firespray", {
                        x: player.location.x + playerViewDirection.x,
                        y: player.location.y + 1 + playerViewDirection.y,
                        z: player.location.z + playerViewDirection.z,
                    });

                    const projectileComponent = projectile.getComponent(EntityComponentTypes.Projectile);
                    const { x: vx, y: vy, z: vz } = player.getViewDirection();

                    projectileComponent.shoot({
                        x: vx * velocityMultiplier,
                        y: vy * velocityMultiplier,
                        z: vz * velocityMultiplier
                    });
                    projectileComponent.owner = player;



                }

                if (afterDam >= dura.maxDurability) {
                    dura.damage = dura.maxDurability
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
                if (afterDam <= dura.maxDurability) {
                    dura.damage += damAmount
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
            }
        }
    })
    // * Book of The Etterbeast
    start.itemComponentRegistry.registerCustomComponent("darkw_onyxdlc1:tome_etterbeast", {
        onUse: e => {
            const item = e.itemStack
            const player = e.source
            const dura = e.itemStack.getComponent('durability')

            // Stop if no durability
            if (dura.damage === dura.maxDurability) {
                return
            }
            // Do stuff if durabibility is good
            if (dura.damage != dura.maxDurability) {
                let damAmount = 125
                let afterDam = dura.damage + damAmount
                let cordsList = []
                // & Location Magic
                const loc = player.location
                const bv = new BlockVolume(
                    { x: loc.x + 7, y: loc.y + 7, z: loc.z + 7 },
                    { x: loc.x - 7, y: loc.y - 1, z: loc.z - 7 }
                )

                // & Block Testing Magic
                const hits = player.dimension.getBlocks(bv, { excludeTypes: ['minecraft:air'] })
                for (let cords of hits.getBlockLocationIterator()) {
                    const block = player.dimension.getBlock(cords)
                    if (block.above(1).typeId != 'minecraft:air') continue
                    cordsList.push(cords)
                }

                let spawbBeastsInt = Math.floor((dura.maxDurability - dura.damage) / 20)
                for (let i = 0; i != spawbBeastsInt; i++) {

                    let ran = Math.floor(Math.random() * cordsList.length)
                    let ranCord = cordsList[ran]
                    const spawnBlock = player.dimension.getBlock(ranCord)
                    let spawE = spawnBlock.dimension.spawnEntity('darkw_onyxdlc1:roxcrow_z_beast', { x: spawnBlock.location.x, y: spawnBlock.location.y + 0.5, z: spawnBlock.location.z }).getComponent('tameable').tame(player)
                }

                if (afterDam >= dura.maxDurability) {
                    dura.damage = dura.maxDurability
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
                if (afterDam <= dura.maxDurability) {
                    dura.damage += damAmount
                    player.getComponent('equippable').setEquipment(EquipmentSlot.Mainhand, item)
                    return
                }
            }
        }
    })
    // * The Death Blade (heehee)
    start.itemComponentRegistry.registerCustomComponent("darkw_onyxdlc1:death_blade", {
        onHitEntity: e => {
            const item = e.itemStack
            const player = e.attackingEntity
            const cool = e.itemStack.getComponent(ItemComponentTypes.Cooldown)

            // Stop if no durability
            if (cool.getCooldownTicksRemaining(player) != 0) {
                return
            }

            let cordsList = []

            // & Location Magic
            const loc = player.location
            const bv = new BlockVolume(
                { x: loc.x + 7, y: loc.y + 7, z: loc.z + 7 },
                { x: loc.x - 7, y: loc.y - 1, z: loc.z - 7 }
            )

            // & Block Testing Magic
            const hits = player.dimension.getBlocks(bv, { excludeTypes: ['minecraft:air'] })
            for (let cords of hits.getBlockLocationIterator()) {
                const block = player.dimension.getBlock(cords)
                if (block.above(1).typeId != 'minecraft:air') continue
                cordsList.push(cords)
            }
            if ((Math.random() * 6) > 5) return

            let ran = Math.floor(Math.random() * cordsList.length)
            let ranCord = cordsList[ran]

            const spawnBlock = player.dimension.getBlock(ranCord)
            spawnBlock.dimension.spawnEntity('darkw_onyxdlc1:roxcrow_a_ally', { x: spawnBlock.location.x, y: spawnBlock.location.y + 0.5, z: spawnBlock.location.z }).getComponent('tameable').tame(player)

            cool.startCooldown(player)
        }
    })
})

system.runInterval(() => {
    world.scoreboard.getObjective('darkw_onyxdlc1:time').setScore('darkw_onyxdlc1:timekeeper', world.getTimeOfDay())
    world.getAllPlayers().forEach(player => {
        let playerContainer = player.getComponent('inventory').container
        for (let i = 0; i < playerContainer.size; i++) {
            if (!playerContainer.getItem(i)) continue
            // * Regen durability on certain items.
            if (playerContainer.getItem(i).getTags().includes('darkw_onyxdlc1:durabilityregen')) {
                let item = playerContainer.getItem(i)
                let dura = item.getComponent('durability')
                if (dura.damage != 0) {
                    let ran = Math.floor(Math.random() * 50)
                    if (player.hasTag('dev')) ran = ran + 500
                    if (player.getGameMode() === 'Creative') ran = ran + 150
                    if (dura.damage - ran < 0) {
                        dura.damage = 0
                        playerContainer.setItem(i, item)
                    }
                    if (dura.damage - ran > 0) {
                        dura.damage -= ran
                        playerContainer.setItem(i, item)
                    }

                }
            }
            // * Enabled charms
            if (playerContainer.getItem(i).typeId === 'darkw_onyxdlc1:charm_death_yes') {
                let item = playerContainer.getItem(i)
                let dura = item.getComponent('durability')

                if (dura.damage != dura.maxDurability) {
                    let ran = Math.floor(Math.random() * 25)
                    if (player.hasTag('dev')) ran = ran + 500
                    if (dura.damage + ran > dura.maxDurability) {
                        playerContainer.setItem(i, new ItemStack('darkw_onyxdlc1:charm_death_no', 1))
                        return
                    }
                    if (dura.damage + ran > 0) {
                        dura.damage += ran
                        playerContainer.setItem(i, item)
                    }

                }
            }
        }
    })
}, 25)

// ! LORE
// ! =================================================================================
world.afterEvents.playerInventoryItemChange.subscribe(ev => {
    if (!ev.itemStack) return;

    const item = ev.itemStack;
    const player = ev.player;

    if (item.getLore().length > 0) return
    switch (item.typeId) {
        case "darkw_onyxdlc1:wea_bow1": {
            item.setLore([
            "\n§r§7Applies wither to targets hit and all entities around them.",
            "§r§cDo not use tipped arrows with this bow, it will not work."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:wea_batstaff": {
            item.setLore([
            "\n§r§7On Use:",
            "§r§9 Summons a number of bats based on the item's remaining durability.",
            "§r§9 This item loses durability on use but regenerates over time."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:wea_beastbook": {
            item.setLore([
            "\n§r§7On Use:",
            "§r§9 Summons a number of Etterbeasts based on the item's remaining durability.",
            "§r§9 This item loses durability on use but regenerates over time."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:wea_lantern": {
            item.setLore([
            "\n§r§7On Use:",
            "§r§9 Fires a burst of flames based on the item's remaining durability.",
            "§r§9 This item loses durability on use but regenerates over time."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:charm_death_no": {
            item.setLore([
            "\n§r§7On Use:",
            "§r§9 The charm activates, causing all attacks the holder makes to cause wither.",
            "§r§9 Each attack while active will damage the charm, turning \n off when durability reaches zero."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:charm_death_yes": {
            item.setLore([
            "\n§r§7On Use:",
            "§r§9 All attacks the holder of this charm makes causes wither.",
            "§r§9 Each attack while active will damage the charm, turning \n off when durability reaches zero."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:wea_death_blade": {
            item.setLore([
            "\n§r§7On Entity Attack:",
            "§r§9 Randomly summons a friendly roxcrow nearby to attack your target.",
            "§r§9 This item loses durability on use but regenerates over time."
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        // * Vials
        // *
        // *
        // *
        case "darkw_onyxdlc1:via_fire": {
            item.setLore([
            "\n§r§7Info:\n§r§9 Can be smashed on the ground \n (Melee attack a block) for a desired result.",
            "§r§7On Ground Smash:",
            "§r§9 Shoots strands of mini flames out from the block you hit.",
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:via_heal": {
            item.setLore([
            "\n§r§7Info:\n§r§9 Can be smashed on the ground \n (Melee attack a block) for a desired result.",
            "§r§7On Ground Smash:",
            "§r§9 Heals all nearby players around the block you hit.",
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:via_slow": {
            item.setLore([
            "\n§r§7Info:\n§r§9 Can be smashed on the ground \n (Melee attack a block) for a desired result.",
            "§r§7On Ground Smash:",
            "§r§9 Slows down all nearby Roxcrows.",
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
        case "darkw_onyxdlc1:via_kill": {
            item.setLore([
            "\n§r§7Info:\n§r§9 Can be smashed on the ground \n (Melee attack a block) for a desired result.",
            "§r§7On Ground Smash:",
            "§r§9 Kills §eup to three§9 nearby Roxcrows.",
            ]);
            player.getComponent('inventory').container.setItem(ev.slot, item);
            break
        }
    }
})




            function replaceOnUseOrWhatever(entity, amount, typeId){
                if (amount != 1) {
                    entity.runCommand(`/replaceitem entity @s slot.weapon.mainhand 0 ${typeId} ${amount - 1}`)
                    return
                }
                if (amount === 1) {
                    entity.runCommand(`/replaceitem entity @s slot.weapon.mainhand 0 air 1`)
                    return
                }
            }