// priority: 1

// by blueversal

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

StartupEvents.registry('item', (event) => {
    event
        .create('infinity_golem_summoner')
        .useAnimation('bow')
        .rarity('rare')
        .maxStackSize(1)
        .use((level, player, hand) => {
            let dim = `${level.dimension}`;
            if (dim != 'minecraft:overworld' && dim != 'minecraft:the_nether') {
                if (!level.isClientSide()) {
                    player.tell('§cYou can only use this in the Overworld or the Nether!');
                }
                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:infinity_golem_summoner') {
                main.count--;
            } else if (off.id == 'kubejs:infinity_golem_summoner') {
                off.count--;
            }

            global.summon_infinity_golem(level, entity);
            return itemstack;
        })
        .displayName('??? Summoner')
        .tooltip('Summons the Infinity Golem');
});

global.summon_infinity_golem = (level, player) => {
    level.server.runCommandSilent(
        `/execute as ${player.username} in ${level.dimension} at ${player.username} run summon infinitygolem:infinity_golem ~ ~5 ~`
    );

    level.server.runCommandSilent(
        `/eta queue ${player.username} infinityGolemIntro "<dur:80>[anchor value=MIDDLE][scale value=2.0][fade in=8 out=8][slam height=20 bounces=2 dur=0.6]<glitch frequency=4 chromatic=2.5><pulse frequency=2 phase=0.4><color value=#FF6A00>INFINITY GOLEM SUMMONED</color></pulse></glitch></scale>"`
    );

    level.server.runCommandSilent(
        `/effect give ${player.username} minecraft:darkness 3 0 true`
    );
};