Nico Alcantara

The name of the mod is "Crack's Flight HUD".

Make a Hud Mod that makes it so that when you are gliding with an elytra a custom Fighter Jet like HUD shows on screen.

Main Features: Flight path vector, Pitch Ladder, Mach, Heading, Bank Angle, Horizon Line.

Additional Features:

Make it so that the keybind to toggle it can be changed in the controls Default Hud Toggle is "[". Make it so that the user can input their own sounds and warnings.

Warn the player when they are on course to crash into a wall "Pull up" if there are no blocks beyond 10 blocks above the obstacle according to the Flight Path Vector, "Roll Left", if there are no blocks beyond 30 blocks to the left of the obstacle according to the Flight Path Vector, "Roll Right" if there are no blocks beyond 30 blocks to the right of the obstacle according to the Flight Path Vector. and play the corresponding audio warning "Pull up", "Roll Left", and "Roll Right"

Warn the player is low to the ground and are 50 blocks above terrain, Flash the warning "PULL UP" in a box and play the audio warning "Altitude" and "Pull up". Make these audio warnings changeable by importing any audio files in a separate folder named "Crack's Flight HUD" where it the mod will find the name of audio file corresponding to the warning and play it

Use This as a Basis of the HUD http://www.simscape.fr/F16HUD_Doc.html

Kodari AI
KodariOct 31 at 6:58 am 2
CracksFlightHUD
A Fabric mod that displays a fighter jet-style HUD while gliding with an elytra. The HUD includes a flight path vector, pitch ladder, Mach number, heading indicator, bank angle, and horizon line. Players can toggle the HUD with a configurable keybind (default "["). The mod provides collision warnings: "Pull up" when terrain is within 10 blocks above the flight path, "Roll Left" when terrain is within 30 blocks to the left, and "Roll Right" when within 30 blocks to the right. It also warns when the player is 50 blocks above the ground with a flashing "PULL UP" box. All audio warnings are customizable by placing audio files in a folder named "Crack's Flight HUD" where the mod matches filenames to warning types.
  1. Create the client-only Fabric 26.3 mod scaffold and HUD/keybind.

  2. Add flight instruments and predictive terrain/obstacle warnings.

  3. Add replaceable warning audio files from the named folder and document their filenames.

Created Crack’s Flight HUD, a client-only Fabric 26.3 mod with a fighter-jet-inspired HUD while gliding: flight path vector, pitch ladder, horizon, Mach, heading, and estimated bank angle.

  • The HUD is on by default; [ toggles it. Rebind it in Options → Controls.

  • Glide warnings check for forward obstacles and clear pull-up or roll routes. At 50 blocks or less above terrain, the HUD flashes PULL UP.

  • Drop custom audio into the game directory’s Crack's Flight HUD folder, named Pull up, Roll Left, Roll Right, or Altitude (spaces, underscores, and hyphens are interchangeable). Low-altitude alerts play both Altitude and Pull up. Audio playback depends on the format being supported by Java Sound; without matching audio files, the visual warnings still appear.

Nico Alcantara

Make the mod fully configurable and customizable via the Mod Menu mod. same as the FlightAssistant Mod, use this as a basis for the customizability https://github.com/Octol1ttle/FlightAssistant/wiki/HUD

Use the FlightAssistant mod's HUD as a basis of this mod. https://modrinth.com/mod/flightassistant?loader=fabric&version=1.21.11

Additionally, Make the horizon line relative to the ground and not to the player (gyroscopic). Also add elytra health and a stall warning when you are flying at below 20 blocks per second or just use the flightassistant github as a basis for all the stats. Additionally make the folder for the warning audio files be accessable through the mod menu settings

Kodari AI
KodariOct 31 at 8:48 am 5
  1. Add a Mod Menu-accessible configuration screen for HUD customization, using FlightAssistant’s HUD options as a reference.

  2. Update the HUD horizon and add elytra durability and stall indication.

  3. Make warning-audio folder access part of the settings, with configurable warning audio.

  1. Mod Menu configuration: Added a YACL settings screen for HUD scale and colors, individual instrument visibility, warning toggles, and the stall-speed threshold. Settings persist between launches; the HUD toggle remains rebindable in Controls.

  2. Flight displays: The horizon and pitch ladder now account for nearby terrain slope. Added ground and vertical speed, altitude, coordinates, elytra durability, and a configurable stall alert (default: below 20 blocks/second).

  3. Warning audio: Added an Open warning audio folder button in settings. Put files named Pull up, Roll Left, Roll Right, Altitude, or STALL in Crack's Flight HUD; filenames ignore case, spaces, underscores, and hyphens. Playback supports formats available to Java Sound.

Kodari can make mistakes. Review important code before using.
Files
src
build.gradle
gradle.properties
settings.gradle
Code
6 430
src/client/java/com/cracksflighthud/client/CracksFlightHudClient.java
package com.cracksflighthud.client;

import com.mojang.blaze3d.platform.InputConstants;
import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.fabricmc.fabric.api.client.keymapping.v1.KeyMappingHelper;
import net.fabricmc.fabric.api.client.rendering.v1.hud.HudElementRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.Identifier;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.world.phys.Vec3;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineEvent;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Stream;

public final class CracksFlightHudClient implements ClientModInitializer {
	private static final String MOD_ID = "cracksflighthud";
	private static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
	private static final int HUD_COLOR = 0xFF72FFB0;
	private static final int ALERT_COLOR = 0xFFFF554F;
	private static final long WARNING_COOLDOWN_NANOS = 2_500_000_000L;
	private static final Map<String, Long> WARNING_COOLDOWNS = new HashMap<>();
	private static final ExecutorService AUDIO_EXECUTOR = Executors.newSingleThreadExecutor(task -> {
		Thread thread = new Thread(task, "Crack's Flight HUD audio");
		thread.setDaemon(true);
		return thread;
	});
	private static final KeyMapping.Category KEY_CATEGORY = KeyMapping.Category.register(
			Identifier.fromNamespaceAndPath(MOD_ID, "main")
	);
	private static final Identifier HUD_ID = Identifier.fromNamespaceAndPath(MOD_ID, "flight_hud");

	private static KeyMapping toggleKey;
	private static Path audioDirectory;
	private static boolean hudEnabled = true;
	private static FlightData flightData;
	private static String currentWarning = "";
	private static long currentWarningUntil;
	private static double previousHeading = Double.NaN;

	@Override
	public void onInitializeClient() {
		toggleKey = KeyMappingHelper.registerKeyMapping(new KeyMapping(
				"key.cracksflighthud.toggle",
				InputConstants.Type.KEYBOARD,
				InputConstants.KEY_LBRACKET,
				KEY_CATEGORY
		));
		audioDirectory = FabricLoader.getInstance().getGameDir().resolve("Crack's Flight HUD");
		prepareAudioDirectory();
		ClientTickEvents.END_CLIENT_TICK.register(CracksFlightHudClient::tick);
		HudElementRegistry.addLast(HUD_ID, (graphics, deltaTracker) -> renderHud(graphics));
	}

	private static void prepareAudioDirectory() {
		try {
			Files.createDirectories(audioDirectory);
			Path instructions = audioDirectory.resolve("README.txt");
			if (!Files.exists(instructions)) {
				Files.writeString(instructions,
						"Drop warning audio files in this folder. Name each file Pull up, Roll Left, Roll Right, or Altitude (spaces, underscores, and hyphens are interchangeable). The mod uses audio formats supported by Java Sound on this system. Low-altitude warnings play both Altitude and Pull up.\n",
						StandardCharsets.UTF_8);
			}
			LOGGER.info("Crack's Flight HUD warning audio folder: {}", audioDirectory);
		} catch (IOException exception) {
			LOGGER.warn("Could not create the Crack's Flight HUD audio folder at {}", audioDirectory, exception);
		}
	}

	private static void tick(Minecraft client) {
		while (toggleKey.consumeClick()) {
			hudEnabled = !hudEnabled;
		}

		LocalPlayer player = client.player;
		Level level = client.level;
		if (!hudEnabled || player == null || level == null || !player.isFallFlying()) {
			flightData = null;
			previousHeading = Double.NaN;
			return;
		}

		Vec3 velocity = player.getDeltaMovement();
		double speed = Math.sqrt(velocity.x * velocity.x + velocity.y * velocity.y + velocity.z * velocity.z);
		double heading = normalizeDegrees(180.0 + player.getYRot());
		double bankAngle = 0.0;
		if (!Double.isNaN(previousHeading)) {
			bankAngle = clamp(signedDegrees(heading - previousHeading) * 4.0, -60.0, 60.0);
		}
		previousHeading = heading;

		double bodyPitch = -player.getXRot();
		double trackHeading = heading;
		double flightPitch = bodyPitch;
		if (speed > 0.0001) {
			trackHeading = normalizeDegrees(Math.toDegrees(Math.atan2(velocity.x, -velocity.z)));
			flightPitch = Math.toDegrees(Math.asin(clamp(velocity.y / speed, -1.0, 1.0)));
		}

		BlockPos playerBlock = BlockPos.containing(player.getX(), player.getY(), player.getZ());
		int groundY = level.getHeight(Heightmap.Types.MOTION_BLOCKING, playerBlock.getX(), playerBlock.getZ());
		double radioAltitude = Math.max(0.0, player.getY() - groundY);
		if (radioAltitude <= 50.0) {
			warn("PULL_UP", "PULL UP", "ALTITUDE", "PULL UP");
		}

		if (speed > 0.0001) {
			String collisionWarning = predictEscapeWarning(level, player, velocity, speed);
			if (collisionWarning != null) {
				if (collisionWarning.equals("ROLL LEFT")) {
					warn("ROLL_LEFT", collisionWarning, "ROLL LEFT");
				} else if (collisionWarning.equals("ROLL RIGHT")) {
					warn("ROLL_RIGHT", collisionWarning, "ROLL RIGHT");
				} else {
					warn("PULL_UP", "PULL UP", "PULL UP");
				}
			}
		}

		double mach = speed * 20.0 / 343.0;
		flightData = new FlightData(
				heading,
				bankAngle,
				mach,
				radioAltitude,
				signedDegrees(trackHeading - heading),
				flightPitch - bodyPitch,
				bodyPitch
		);
	}

	private static String predictEscapeWarning(Level level, LocalPlayer player, Vec3 velocity, double speed) {
		double forwardX = velocity.x / speed;
		double forwardY = velocity.y / speed;
		double forwardZ = velocity.z / speed;
		Vec3 start = new Vec3(player.getX(), player.getY() + 0.9, player.getZ());
		Vec3 forwardEnd = new Vec3(
				start.x + forwardX * 60.0,
				start.y + forwardY * 60.0,
				start.z + forwardZ * 60.0
		);
		BlockHitResult obstacle = level.clip(new ClipContext(
				start, forwardEnd, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player
		));
		if (obstacle.getType() == HitResult.Type.MISS) {
			return null;
		}

		Vec3 point = obstacle.getLocation();
		double dx = point.x - start.x;
		double dy = point.y - start.y;
		double dz = point.z - start.z;
		if (Math.sqrt(dx * dx + dy * dy + dz * dz) > 55.0) {
			return null;
		}

		double horizontalLength = Math.sqrt(forwardX * forwardX + forwardZ * forwardZ);
		if (horizontalLength < 0.05) {
			return "PULL UP";
		}

		double leftX = forwardZ / horizontalLength;
		double leftZ = -forwardX / horizontalLength;
		if (clearRoute(level, player, start,
				point.x + forwardX * 8.0, point.y + 10.0, point.z + forwardZ * 8.0)) {
			return "PULL UP";
		}
		if (clearRoute(level, player, start,
				point.x + forwardX * 8.0 + leftX * 30.0, point.y, point.z + forwardZ * 8.0 + leftZ * 30.0)) {
			return "ROLL LEFT";
		}
		if (clearRoute(level, player, start,
				point.x + forwardX * 8.0 - leftX * 30.0, point.y, point.z + forwardZ * 8.0 - leftZ * 30.0)) {
			return "ROLL RIGHT";
		}
		return "PULL UP";
	}