// priority: 1

// by blueversal

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

StartupEvents.registry('item', (event) => {
	event
        .create('immortal_summoner')
		.useAnimation('bow')
		.rarity('epic')
		.maxStackSize(1)
        .use((level, player, hand) => true)
        .useDuration((itemstack) => 1)
        .finishUsing((itemstack, level, entity) => {
            if (entity.player) {
                let item = entity.getHeldItem('main_hand');
                let offHandItem = entity.getHeldItem('off_hand');
                if (item.id == 'kubejs:immortal_summoner') {
                    item.count--;
                } else if (offHandItem.id == 'kubejs:immortal_summoner') {
                    offHandItem.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} run summon eeeabsmobs:immortal ${player.getX()} ${player.getY()} ${player.getZ()}`);
    level.server.runCommandSilent(`/eta sendcustom ${player.username} {
  "anchor":"CENTER_CENTER",
  "background":true,
  "size":2.0
} 150 <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>`);
    level.server.runCommandSilent(`/effect give ${player.username} minecraft:darkness 5 0 true`);
    level.server.runCommandSilent(`/effect give ${player.username} minecraft:blindness 5 0 true`);
};