Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ Please use [Discord](https://discord.gg/5kcBCvnbTp) or [GitHub](https://github.c

**A wiki is now available: https://github.com/Octol1ttle/FlightAssistant/wiki**

## 3.1.0

- Added support for Minecraft 26.1
- Added a keybind to toggle Auto Thrust on its own, independent of the rest of the autopilot
- Added a keybind to toggle Flight Directors, Auto Thrust, and Autopilot together with one press
- Added a holding pattern autopilot mode: enter it with a keybind to hold at the waypoint you're currently flying to (or at your present position if there isn't one), or configure a fix and inbound course manually in the Autoflight setup screen
- Fixed the attitude display's pitch-limit indicators sometimes appearing far more than intended, especially at low speed

## Changes from Beta 1

- Added Chinese localization
Expand Down
10 changes: 6 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
plugins {
kotlin("jvm")
kotlin("plugin.serialization")
id("dev.isxander.modstitch.base") version "0.7.0-unstable"
id("fabric-loom") version "1.14.6" apply false
id("dev.isxander.modstitch.base") version "0.8.5"
id("fabric-loom") version "1.17.20" apply false
id("me.modmuss50.mod-publish-plugin")
id("me.fallenbreath.yamlang") version "1.5.0"
}
Expand Down Expand Up @@ -47,15 +47,17 @@ tasks.withType<Jar> {
modstitch {
minecraftVersion = minecraft

val j25: Boolean = stonecutter.eval(minecraft, ">=26.1")
val j21: Boolean = stonecutter.eval(minecraft, ">=1.20.6")
javaVersion = if (j21) 21 else 17
val javaVersionNumber: Int = if (j25) 25 else if (j21) 21 else 17
javaVersion = javaVersionNumber

java {
withSourcesJar()
}

kotlin {
jvmToolchain(if (j21) 21 else 17)
jvmToolchain(javaVersionNumber)
}

// If parchment doesnt exist for a version yet you can safely
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ org.gradle.configuration-cache=false
mod.id=flightassistant
mod.name=FlightAssistant
mod.group=ru.octol1ttle
mod.version=3.0.0
mod.version=3.1.0

# Global Dependencies
deps.mixin_extras=0.4.1
deps.fabric_loader=0.16.10
deps.fabric_loader=0.19.5
deps.flk=1.13.0

publish.modrinth=CWqLEOPt
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-9.2.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-9.5.1-bin.zip
networkTimeout=10000
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ stonecutter {
mc("1.21.6", "fabric")
mc("1.21.9", "fabric")
mc("1.21.11", "fabric")
mc("26.1.2", "fabric")
mc("26.2", "fabric")
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@

@Mixin(Gui.class)
abstract class GuiMixinNew {
//? if fabric && >=1.21.6 {
//? if fabric && >=26.1 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "extractRenderState", at = @org.spongepowered.asm.mixin.injection.At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;extractHotbarAndDecorations(Lnet/minecraft/client/gui/GuiGraphicsExtractor;Lnet/minecraft/client/DeltaTracker;)V"))
private void beforeRenderHotbarAndDecorations(net.minecraft.client.gui.GuiGraphicsExtractor guiGraphics, net.minecraft.client.DeltaTracker deltaTracker, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
ru.octol1ttle.flightassistant.api.util.event.FixedGuiRenderCallback.EVENT.invoker().onRenderGui(guiGraphics, deltaTracker.getGameTimeDeltaPartialTick(true));
guiGraphics.nextStratum();
}
*///?} else if fabric && >=1.21.6 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "render", at = @org.spongepowered.asm.mixin.injection.At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Gui;renderHotbarAndDecorations(Lnet/minecraft/client/gui/GuiGraphics;Lnet/minecraft/client/DeltaTracker;)V"))
private void beforeRenderHotbarAndDecorations(net.minecraft.client.gui.GuiGraphics guiGraphics, net.minecraft.client.DeltaTracker deltaTracker, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
ru.octol1ttle.flightassistant.api.util.event.FixedGuiRenderCallback.EVENT.invoker().onRenderGui(guiGraphics, deltaTracker.getGameTimeDeltaPartialTick(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@

@Mixin(LevelRenderer.class)
abstract class LevelRendererMixinNewestest {
//? if >=1.21.9 {
//? if >=26.1 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "renderLevel", at = @org.spongepowered.asm.mixin.injection.At("HEAD"))
private void onStartRender(com.mojang.blaze3d.resource.GraphicsResourceAllocator graphicsResourceAllocator, net.minecraft.client.DeltaTracker deltaTracker, boolean renderBlockOutline, net.minecraft.client.renderer.state.level.CameraRenderState cameraRenderState, org.joml.Matrix4fc frustumMatrix, com.mojang.blaze3d.buffers.GpuBufferSlice fogBuffer, org.joml.Vector4f fogColor, boolean renderSky, net.minecraft.client.renderer.chunk.ChunkSectionsToRender chunkSectionsToRender, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
ru.octol1ttle.flightassistant.api.util.event.LevelRenderCallback.EVENT.invoker().onStartRenderLevel(deltaTracker.getGameTimeDeltaPartialTick(true), cameraRenderState.xRot, cameraRenderState.yRot, cameraRenderState.projectionMatrix, frustumMatrix.get3x3(new org.joml.Matrix3f()));
}
*///?} else if >=1.21.9 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "renderLevel", at = @org.spongepowered.asm.mixin.injection.At("HEAD"))
private void onStartRender(com.mojang.blaze3d.resource.GraphicsResourceAllocator graphicsResourceAllocator, net.minecraft.client.DeltaTracker deltaTracker, boolean renderBlockOutline, net.minecraft.client.Camera camera, org.joml.Matrix4f frustumMatrix, org.joml.Matrix4f projectionMatrix, org.joml.Matrix4f cullingProjectionMatrix, com.mojang.blaze3d.buffers.GpuBufferSlice fogBuffer, org.joml.Vector4f fogColor, boolean renderSky, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
ru.octol1ttle.flightassistant.api.util.event.LevelRenderCallback.EVENT.invoker().onStartRenderLevel(deltaTracker.getGameTimeDeltaPartialTick(true), camera, projectionMatrix, frustumMatrix.get3x3(new org.joml.Matrix3f()));
ru.octol1ttle.flightassistant.api.util.event.LevelRenderCallback.EVENT.invoker().onStartRenderLevel(deltaTracker.getGameTimeDeltaPartialTick(true), camera.xRot, camera.yRot, projectionMatrix, frustumMatrix.get3x3(new org.joml.Matrix3f()));
}
*///?}
}
4 changes: 4 additions & 0 deletions src/main/kotlin/net/minecraft/client/gui/GuiGraphics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package net.minecraft.client.gui

//? if >=26.1
/*typealias GuiGraphics = GuiGraphicsExtractor*/
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.minecraft.client.gui.components

//? if >=26.1 {
/*fun Renderable.render(guiGraphics: net.minecraft.client.gui.GuiGraphics, mouseX: Int, mouseY: Int, partialTick: Float) {
this.extractRenderState(guiGraphics, mouseX, mouseY, partialTick)
}
*///?}
41 changes: 40 additions & 1 deletion src/main/kotlin/ru/octol1ttle/flightassistant/FAKeyMappings.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package ru.octol1ttle.flightassistant

import com.mojang.blaze3d.platform.InputConstants
import kotlin.math.roundToInt
import net.minecraft.client.KeyMapping
import org.lwjgl.glfw.GLFW
import ru.octol1ttle.flightassistant.FlightAssistant.mc
import ru.octol1ttle.flightassistant.api.computer.ComputerBus
import ru.octol1ttle.flightassistant.api.util.pointsToDirection
import ru.octol1ttle.flightassistant.config.FAConfig
import ru.octol1ttle.flightassistant.impl.computer.autoflight.modes.HoldingPatternLateralMode
import ru.octol1ttle.flightassistant.impl.computer.autoflight.modes.SelectedAltitudeVerticalMode
import ru.octol1ttle.flightassistant.screen.FlightAssistantSetupScreen

object FAKeyMappings {
Expand All @@ -24,6 +28,9 @@ object FAKeyMappings {
lateinit var openFlightAssistantSetup: KeyMapping

lateinit var autopilotDisconnect: KeyMapping
lateinit var toggleAutoThrust: KeyMapping
lateinit var toggleAllAutopilot: KeyMapping
lateinit var toggleHoldingPattern: KeyMapping
lateinit var globalAutomationOverride: KeyMapping

lateinit var hideCurrentAlert: KeyMapping
Expand All @@ -38,7 +45,10 @@ object FAKeyMappings {
toggleEnabled = addKeyMapping("toggle_enabled", -1)
openFlightAssistantSetup = addKeyMapping("open_flightassistant_setup", GLFW.GLFW_KEY_KP_ENTER)

autopilotDisconnect = addKeyMapping("autopilot_disconnect", GLFW.GLFW_KEY_CAPS_LOCK) // TODO: replace with "Toggle FD", "Toggle A/T", "Toggle AP"
autopilotDisconnect = addKeyMapping("autopilot_disconnect", GLFW.GLFW_KEY_CAPS_LOCK)
toggleAutoThrust = addKeyMapping("toggle_auto_thrust", -1)
toggleAllAutopilot = addKeyMapping("toggle_all_autopilot", -1)
toggleHoldingPattern = addKeyMapping("toggle_holding_pattern", -1)
globalAutomationOverride = addKeyMapping("global_automation_override", GLFW.GLFW_KEY_LEFT_ALT)

hideCurrentAlert = addKeyMapping("hide_current_alert", GLFW.GLFW_KEY_KP_0)
Expand Down Expand Up @@ -78,6 +88,35 @@ object FAKeyMappings {
}
computers.autoflight.setAutoPilot(false, alert = false)
}
while (toggleAutoThrust.consumeClick()) {
computers.autoflight.setAutoThrust(!computers.autoflight.autoThrust, alert = false)
}
while (toggleAllAutopilot.consumeClick()) {
val enable: Boolean = !computers.autoflight.autopilot
computers.autoflight.setFlightDirectors(enable)
computers.autoflight.setAutoThrust(enable, alert = false)
computers.autoflight.setAutoPilot(enable, alert = false)
}
while (toggleHoldingPattern.consumeClick()) {
if (computers.autoflight.selectedLateralMode is HoldingPatternLateralMode) {
computers.autoflight.selectedLateralMode = null
computers.autoflight.selectedVerticalMode = null
} else {
// Hold at the waypoint currently being flown to, if there is one; otherwise hold at present position.
val target = computers.plan.getEnrouteTarget()
val fixX: Int = target?.coordinatesX ?: computers.data.x.roundToInt()
val fixZ: Int = target?.coordinatesZ ?: computers.data.z.roundToInt()
val fixAltitude: Int = target?.altitude ?: computers.data.altitude.roundToInt()
val inboundCourse: Float = if (target != null) {
pointsToDirection(fixX.toDouble(), fixZ.toDouble(), computers.data.x, computers.data.z).toFloat() + 180.0f
} else {
computers.data.heading
}

computers.autoflight.selectedLateralMode = HoldingPatternLateralMode(fixX, fixZ, inboundCourse)
computers.autoflight.selectedVerticalMode = SelectedAltitudeVerticalMode(fixAltitude)
}
}

while (hideCurrentAlert.consumeClick()) {
computers.alert.hideCurrentAlert()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ object FlightAssistant {
ComputerHost.sendRegistrationEvent()
initComplete = true
}
LevelRenderCallback.EVENT.register { partialTick, camera, projectionMatrix, frustumMatrix ->
LevelRenderCallback.EVENT.register { partialTick, cameraXRot, cameraYRot, projectionMatrix, frustumMatrix ->
FAKeyMappings.checkPressed(ComputerHost)

ComputerHost.tick(partialTick)

RenderMatrices.projectionMatrix.set(projectionMatrix)
RenderMatrices.worldSpaceMatrix.set(frustumMatrix)
//? if >=26.1 {
/*RenderMatrices.modelViewMatrix.identity()
*///?} else
RenderMatrices.modelViewMatrix.set(RenderSystem.getModelViewMatrix())

RenderMatrices.worldSpaceNoRollMatrix.set(Matrix4f().apply {
rotate(Axis.XP.rotationDegrees(camera.xRot))
rotate(Axis.YP.rotationDegrees(camera.yRot + 180.0f))
rotate(Axis.XP.rotationDegrees(cameraXRot))
rotate(Axis.YP.rotationDegrees(cameraYRot + 180.0f))
})

RenderMatrices.ready = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@ import org.jetbrains.annotations.Contract
import org.joml.Matrix4f
import org.joml.Vector3f
import org.joml.Vector4f
import org.lwjgl.opengl.GL11
import ru.octol1ttle.flightassistant.FlightAssistant.mc

object ScreenSpace {
private var viewport: IntArray = IntArray(4)

internal fun updateViewport() {
GL11.glGetIntegerv(GL11.GL_VIEWPORT, viewport)
// The HUD is now extracted during the CPU render-state phase (26.x), where the
// GL viewport is stale. Project against the actual framebuffer size instead.
viewport[0] = 0
viewport[1] = 0
viewport[2] = mc.window.width
viewport[3] = mc.window.height
}

/**
Expand Down Expand Up @@ -52,10 +56,24 @@ object ScreenSpace {
val matrixModel = Matrix4f(RenderMatrices.modelViewMatrix)

matrixProj.mul(matrixModel)
.project(
transformedCoordinates.x(), transformedCoordinates.y(), transformedCoordinates.z(), viewport,
target
)

// On 26.x the projection matrix uses a reversed-Z depth range. Points that are at
// or behind the camera plane (clip.w <= 0) get mirrored back into the visible depth
// window, so the generic z-range check below can no longer reject them. Reject them
// here explicitly, otherwise e.g. both pitch-limit arrows end up drawn at once.
val clipW: Float =
matrixProj.m03() * transformedCoordinates.x +
matrixProj.m13() * transformedCoordinates.y +
matrixProj.m23() * transformedCoordinates.z +
matrixProj.m33() * transformedCoordinates.w
if (clipW <= 0.0f) {
return Vector3f(-1.0f, -1.0f, 2.0f)
}

matrixProj.project(
transformedCoordinates.x(), transformedCoordinates.y(), transformedCoordinates.z(), viewport,
target
)

return Vector3f(
target.x / mc.window.guiScale.toFloat(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ package ru.octol1ttle.flightassistant.api.util.event

import dev.architectury.event.Event
import dev.architectury.event.EventFactory
import net.minecraft.client.Camera
import org.joml.Matrix3f
import org.joml.Matrix4f
import org.joml.Matrix4fc

fun interface LevelRenderCallback {
/**
* Called when the LevelRenderer starts rendering the level
*/
fun onStartRenderLevel(partialTick: Float, camera: Camera, projectionMatrix: Matrix4f, frustumMatrix: Matrix3f)
fun onStartRenderLevel(partialTick: Float, cameraXRot: Float, cameraYRot: Float, projectionMatrix: Matrix4fc, frustumMatrix: Matrix3f)

companion object {
@JvmField
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,36 @@ import ru.octol1ttle.flightassistant.config.FAConfig

internal val font: Font = mc.font

//? if >=26.1 {
/*fun GuiGraphics.hLine(x1: Int, x2: Int, y: Int, color: Int) {
val minX: Int = minOf(x1, x2)
val maxX: Int = maxOf(x1, x2)
fill(minX, y, maxX + 1, y + 1, color)
}

fun GuiGraphics.vLine(x: Int, y1: Int, y2: Int, color: Int) {
val minY: Int = minOf(y1, y2)
val maxY: Int = maxOf(y1, y2)
fill(x, minY, x + 1, maxY + 1, color)
}

fun GuiGraphics.drawString(font: Font, text: String, x: Int, y: Int, color: Int) {
this.text(font, text, x, y, color)
}

fun GuiGraphics.drawString(font: Font, text: String, x: Int, y: Int, color: Int, shadow: Boolean) {
this.text(font, text, x, y, color, shadow)
}

fun GuiGraphics.drawString(font: Font, text: Component, x: Int, y: Int, color: Int) {
this.text(font, text, x, y, color)
}

fun GuiGraphics.drawString(font: Font, text: Component, x: Int, y: Int, color: Int, shadow: Boolean) {
this.text(font, text, x, y, color, shadow)
}
*///?}

val lineHeight: Int
get() = font.lineHeight

Expand Down Expand Up @@ -156,13 +186,19 @@ fun org.joml.Matrix3x2fStack.pop() {
popMatrix()
}

//? if >=1.21.9 {
//? if >=26.1 {
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
outline(x, y, width, height, color)
}
*///?}
//? if >=1.21.11 && <26.1 {
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
renderOutline(x, y, width, height, color)
}
*///?}
//? if >=1.21.9 && <1.21.11 {
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
//? if >=1.21.11 {
/^renderOutline(
^///?} else
submitOutline(
x, y, width, height, color)
submitOutline(x, y, width, height, color)
renderDeferredElements()
}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class FlightPlanComputer(computers: ComputerBus) : Computer(computers) {
return enrouteData.singleOrNull { it.active == EnrouteWaypoint.Active.ORIGIN }
}

private fun getEnrouteTarget(): EnrouteWaypoint? {
fun getEnrouteTarget(): EnrouteWaypoint? {
return enrouteData.singleOrNull { it.active == EnrouteWaypoint.Active.TARGET }
}

Expand Down
Loading