Flight API
Flight API modification provides a universal flight management system for Minecraft, designed to eliminate conflicts between different mods that interact with player flight mechanics.
What This Library Solves
The problem occurs when multiple mods simultaneously try to control the player's flight state by directly accessing player.getAbilities().flying and player.getAbilities().allowFlying settings. This leads to unstable behavior - the player may suddenly fall to the ground or completely lose the ability to fly due to constant parameter toggling by different mods.
Flight API implements a flight management system based on request queuing, which ensures predictable flight operation even when using multiple modifications.
Main Features
- Queue-based flight management system: Developed for proper control distribution between mods, intercepting changes to
allowFlyingandflyingstates. - Simple problem diagnostics: Includes logging that helps players identify conflicts between mods and automatically resolve compatibility issues. Particularly useful when debugging large modpacks where it's difficult to identify the specific source of flight problems.
Player Instructions
Simply place the .jar file in the mods folder - the library is immediately ready to use. If you encounter flight issues, the debug.log file from the logs folder will help developers identify the cause of the malfunction, as Flight API records information about problematic mods.
Developer Guide
Working Principle
In standard Minecraft and most mods, flight logic looks something like this:
player.getAbilities().flying = true;
player.getAbilities().allowFlying = true;
When multiple mods use this approach simultaneously, the player's flight state starts changing chaotically.
Flight API prevents this through the following mechanisms:
- Exclusive control: Only one mod can control the player's flight at any given moment. All other requests are placed in a queue.
- Change interception: Direct attempts to change
flyingorallowFlyingstates are blocked if not authorized. - Recommended API: Developers should use
FlightAPI.requestFlight()andFlightAPI.releaseFlight()methods instead of directly accessing flight parameters.
Dependency Setup (Fabric/NeoForge)
In the build.gradle file, add the repository and dependency:
repositories {
maven {
name = 'BehindTheScenery Team Maven'
url = 'https://maven.behindthescenery.online/repository/maven-public/'
}
}
dependencies {
modImplementation "dev.denismasterherobrine:flightapi-${project.mod_loader}:${project.flightapi_version}"
}
The ${project.mod_loader} parameter determines the mod loader used (for example, "fabric" or "neoforge"), and ${project.flightapi_version} - the Flight API version.
You can also embed the API directly into your mod to simplify installation.
API Usage
Requesting Flight Control
When your mod needs to activate flight (for example, when turning on a jetpack or casting a levitation spell), call:
boolean gotControl = FlightAPI.requestFlight(modId, player);
if (gotControl) {
// You have gained flight control
// FlightAPI automatically sets allowFlying/flying = true
} else {
// Another mod is already controlling flight
// Your request has been added to the queue
}
Releasing Flight Control
When your mod finishes flight control:
FlightAPI.releaseFlight("MyAwesomeMod", player);
If there are other mods in the queue, the next one immediately receives control.
Checking Current Owner
Optional<String> currentOwner = FlightAPI.getCurrentOwner(player);
if (currentOwner.isPresent()) {
System.out.println("Flight is controlled by: " + currentOwner.get());
} else {
System.out.println("Flight is currently inactive");
}
Application Examples
Collaboration between "Jetpack" and "Levitation Spell" Mods
Without Flight API, both mods would constantly toggle the flight state, causing the player to jerk in the air. Using the API, the "Jetpack" mod gets control first, and the "Levitation Spell" mod wait in the queue. When the jetpack runs out, control is automatically transferred to the spell.
Detecting Problematic Mods
If some mod continuously tries to disable flight without authorization, Flight API blocks these attempts and logs them, helping to identify the problem source.
Priority Logic
By default, the FIFO principle (first in, first out) is used.
License
Flight API is distributed under the CC0-1.0 license.