(function () {
    let ClientboundSetEntityMotionPacket = Java.loadClass('net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket');

    StartupEvents.registry('palladium:abilities', (event) => {
        event.create('heroes:spatial_armaments_cycle')
            .icon(palladium.createItemIcon('palladium:vibranium_circuit'))
			.addProperty("cycle_type", "string", "Next", "Next / Prev")
            .tick((entity, entry, holder, enabled) => {
                if (enabled) {
					const cycle_type = entry.getPropertyByName('cycle_type');
					let spatial_slot = palladium.getProperty(entity, "heroes:spatial_armaments_slot")
                    let username = entity.getGameProfile().getName();
					let username_true = username.toLowerCase();
					let spatial_max = 2
					if (abilityUtil.isEnabled(entity, 'heroes:spatial_armaments', 'Armament_Slots_1')) {
						spatial_max += 1
					}
					if (abilityUtil.isEnabled(entity, 'heroes:spatial_armaments', 'Armament_Slots_2')) {
						spatial_max += 1
					}
					if (abilityUtil.isEnabled(entity, 'heroes:spatial_armaments', 'Armament_Slots_3')) {
						spatial_max += 1
					}
					if (cycle_type == "Next") {
						spatial_slot += 1
						if (spatial_slot > spatial_max) {
							spatial_slot = 1
						}
					}
					if (cycle_type == "Prev") {
						spatial_slot -= 1
						if (spatial_slot <= 0) {
							spatial_slot = spatial_max
						}
					}
					entity.server.runCommandSilent("execute as " + username + " at @s run title @s actionbar \"-<Slot " + spatial_slot + " Selected>-\"");
					palladium.setProperty(entity, "heroes:spatial_armaments_slot", spatial_slot);
					
					}
            });
    });
})();