function addKeyBind(hero, boostName, boostKey) {
    hero.addKeyBindFunc("func_BOOST", (player, manager) => {
        manager.setData(player, "fiskheroes:dyn/flight_super_boost", 1);
        return true;
    }, boostName, boostKey);
}

function tick(entity, manager) {
    if (entity.getData("fiskheroes:dyn/flight_super_boost") == 1) {
        manager.setData(entity, "fiskheroes:dyn/flight_super_boost", 2);
        manager.setData(entity, "fiskheroes:flying", true);
        manager.setData(entity, "fiskheroes:flight_timer", entity.getData("fiskheroes:prev_flight_timer"));
        manager.setData(entity, "fiskheroes:flight_boost_timer", entity.getData("fiskheroes:prev_flight_boost_timer"));
    }
    else if (!(entity.isSprinting() && entity.getData("fiskheroes:flying")) && entity.getData("fiskheroes:dyn/flight_super_boost") > 0) {
        manager.setData(entity, "fiskheroes:dyn/flight_super_boost", 0);
    }

    var x = entity.posX();
    var y = entity.posY();
    var z = entity.posZ();
    var dim = entity.world().getDimension();
    if (y > 1024 && entity.getData("fiskheroes:dyn/flight_super_boost") > 0) {
        manager.setData(entity, "fiskheroes:teleport_dest", manager.newCoords(x, y, z, dim + 1));
        manager.setData(entity, "fiskheroes:teleport_delay", 1);
    }
}

function isModifierEnabled(entity, modifier) {
    if (modifier.name() == "fiskheroes:controlled_flight") {
        var boost = entity.getData("fiskheroes:dyn/flight_super_boost");
        var telekinesis = entity.getData("fiskheroes:telekinesis");
        if (modifier.id() == "telekinesis") {
            return telekinesis;
        }
        return boost != 1 && !telekinesis && (modifier.id() == "boosted") == (boost > 0 && !telekinesis);
    }
    return true;
}

function isKeyBindEnabled(entity, keyBind) {
    if (keyBind == "func_BOOST") {
        return entity.isSprinting() && entity.getData("fiskheroes:flying") && entity.getData("fiskheroes:dyn/flight_super_boost") == 0;
    }
    return true;
}
