StartupEvents.registry('palladium:abilities', (event) => {
    event.create('arrzenhanced:speedburst_shield_toggle')
    .icon(palladium.createItemIcon('minecraft:compass'))
    .tick((entity, entry, holder, enabled) => global.speedburstShield(entity, entry, holder, enabled));
});

global.speedburstShield = (entity, entry, holder, enabled) => {
    if (enabled) {
        if (
            entity.mainHandItem.is('minecraft:air') && // hand
            entity.tags.contains('arrz.speedburst.shield')
        ) {
            if (!entity.persistentData['speedburstShield']) {
                entity.setMainHandItem(Item.of('arrzenhanced:speedburst_shield', 1, {}))
            } else {
                entity.setMainHandItem(Item.of('arrzenhanced:speedburst_shield', 1, JSON.parse(entity.persistentData['speedburstShield'])))
            }
            entity.tags.remove('arrz.speedburst.shield')
        } else if (
            entity.mainHandItem.is('arrzenhanced:speedburst_shield') && // hand
            !entity.tags.contains('arrz.speedburst.shield')
        ) {
            entity.persistentData['speedburstShield'] = JSON.stringify(entity.mainHandItem.nbt)

            entity.setMainHandItem(Item.of('minecraft:air'))
            entity.tags.add('arrz.speedburst.shield')
        } else {
            //
        }
    };
}