// priority: 1

// by blueversal

Platform.mods.kubejs.name = 'Beyond Depth Insanity';

StartupEvents.registry('item', (event) => {
    event
        .create('immortal_summoner')
        .useAnimation('bow')
        .rarity('rare')
        .maxStackSize(1)
        .use((level, player, hand) => {
            let dim = `${level.dimension}`;
            if (dim == 'minecraft:the_end' || dim == 'voidscape:void') {
                if (!level.isClientSide()) {
                    player.tell('§cYou cannot use this here!');
                }

                return false;
            }
            return true;
        })
        .useDuration((itemstack) => 1)
        .finishUsing((itemstack, level, entity) => {
            if (!entity.player) return itemstack;
            let main = entity.getHeldItem('main_hand');
            let off = entity.getHeldItem('off_hand');

            if (main.id == 'kubejs:immortal_summoner') {
                main.count--;
            } else if (off.id == 'kubejs:immortal_summoner') {
                off.count--;
            }

            global.summon_immortal(level, entity);
            return itemstack;
        })
        .displayName('Immortal Summoner')
        .tooltip('Summons the Immortal');
});

global.summon_immortal = (level, player) => {
    level.server.runCommandSilent(
        `/execute as ${player.username} in ${level.dimension} at ${player.username} run summon eeeabsmobs:immortal ~ ~ ~`
    );
    level.server.runCommandSilent(
        `/eta send ${player.username} 150 <anchor value=MIDDLE><scale value=2.0><bg color=#60000000><color value=#0079b6><glitch intensity=1.0 slices=3 chromatic=true><pulse speed=1.5><neon r=2 intensity=1.5>IMMORTAL SUMMONED</neon></pulse></glitch></color></bg></scale></anchor>`
    );
    level.server.runCommandSilent(`/effect give ${player.username} minecraft:darkness 5 0 true`);
    level.server.runCommandSilent(`/effect give ${player.username} minecraft:blindness 5 0 true`);
};