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
37 changes: 31 additions & 6 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.15.5" apply false
id("me.modmuss50.mod-publish-plugin")
id("me.fallenbreath.yamlang") version "1.5.0"
}
Expand All @@ -29,6 +29,13 @@ val minecraftVersionRange = prop("mod.mc_version_range")

// See https://stonecutter.kikugie.dev/stonecutter/guide/comments#condition-constants
val loader: String = name.split("-")[1]

// Minecraft 26.x (unobfuscated) requires Java 25, 1.20.6+ requires Java 21, older requires Java 17
val javaVersionTarget: Int = when {
stonecutter.eval(minecraft, ">=26") -> 25
stonecutter.eval(minecraft, ">=1.20.6") -> 21
else -> 17
}
stonecutter {
constants {
match(loader, "fabric", "neoforge", "forge")
Expand All @@ -47,15 +54,14 @@ tasks.withType<Jar> {
modstitch {
minecraftVersion = minecraft

val j21: Boolean = stonecutter.eval(minecraft, ">=1.20.6")
javaVersion = if (j21) 21 else 17
javaVersion = javaVersionTarget

java {
withSourcesJar()
}

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

// If parchment doesnt exist for a version yet you can safely
Expand All @@ -81,6 +87,8 @@ modstitch {
put("fml", if (loader == "neoforge") "1" else "45")
put("mnd", if (loader == "neoforge") "type = \"required\"" else "mandatory = true")
put("refmap", if (loader == "forge") refmapString else "")
put("flmin", if (loader == "fabric") ">=${prop("deps.fabric_loader")}" else "")
put("javamin", ">=$javaVersionTarget")
}

overwriteProjectVersionAndGroup = false
Expand Down Expand Up @@ -145,7 +153,7 @@ dependencies {

modstitch.loom {
modstitchModImplementation("net.fabricmc.fabric-api:fabric-api:${property("deps.fapi")}")
modstitchModImplementation("net.fabricmc:fabric-language-kotlin:${property("deps.flk")}+kotlin.2.1.0")
modstitchModImplementation("net.fabricmc:fabric-language-kotlin:${property("deps.flk")}+${property("deps.flk_kotlin")}")
modstitchModImplementation("com.terraformersmc:modmenu:${property("deps.modmenu")}")
}

Expand Down Expand Up @@ -173,6 +181,23 @@ yamlang {
inputDir.set("assets/${mod.id}/lang")
}

// Modstitch's source configuration overrides stonecutter's automatic wiring of
// the preprocessed (chiseled) sources into the compile source set, so we wire
// them up explicitly here. The generated (preprocessed) sources fully replace
// the shared raw sources under src/main.
sourceSets["main"].apply {
// Kotlin srcDirs must also include the generated Java dir so Kotlin/Java
// joint compilation sees the Java classes (e.g. mixin invokers, interfaces).
kotlin.setSrcDirs(listOf(
layout.buildDirectory.dir("generated/stonecutter/main/kotlin"),
layout.buildDirectory.dir("generated/stonecutter/main/java"),
))
java.setSrcDirs(listOf(layout.buildDirectory.dir("generated/stonecutter/main/java")))
}
tasks.matching { it.name == "compileKotlin" || it.name == "compileJava" || it.name == "sourcesJar" || it.name == "processResources" }.configureEach {
dependsOn(tasks.named("stonecutterGenerate"))
}

// Publishing
publishMods {
val modrinthToken = findProperty("modrinthToken")
Expand Down
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod.version=3.1.0
deps.mixin_extras=0.4.1
deps.fabric_loader=0.16.10
deps.flk=1.13.0
deps.flk_kotlin=kotlin.2.1.0

publish.modrinth=CWqLEOPt
publish.curseforge=972881
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ stonecutter {
mc("1.21.6", "fabric")
mc("1.21.9", "fabric")
mc("1.21.11", "fabric")
mc("26.2", "fabric")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package ru.octol1ttle.flightassistant.mixin.gui;

import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Pseudo;

// The HUD class was renamed Gui -> Hud in 26.x, so this mixin targets a class that
// only exists on 26+. @Pseudo makes the mixin a no-op (skipped with a warning) on
// older versions where the target is absent, so it can stay registered in the config.
@Pseudo
@Mixin(targets = "net.minecraft.client.gui.Hud")
abstract class GuiMixinHud26 {
//? if >=26 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "extractRenderState", at = @org.spongepowered.asm.mixin.injection.At(value = "INVOKE", target = "Lnet/minecraft/client/gui/Hud;extractHotbarAndDecorations(Lnet/minecraft/client/gui/GuiGraphicsExtractor;Lnet/minecraft/client/DeltaTracker;)V"))
private void beforeExtractHotbarAndDecorations(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();
}
*///?}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@Mixin(Gui.class)
abstract class GuiMixinNew {
//? if fabric && >=1.21.6 {
//? if fabric && >=1.21.6 && <26 {
/*@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,19 @@

@Mixin(LevelRenderer.class)
abstract class LevelRendererMixinNewestest {
//? if >=1.21.9 {
//? if >=1.21.9 && <26 {
/*@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()));
}
*///?}
//? if >=26 {
/*@org.spongepowered.asm.mixin.injection.Inject(method = "render", 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, org.spongepowered.asm.mixin.injection.callback.CallbackInfo ci) {
net.minecraft.client.Camera camera = net.minecraft.client.Minecraft.getInstance().gameRenderer.mainCamera();
if (camera != null) {
ru.octol1ttle.flightassistant.api.util.event.LevelRenderCallback.EVENT.invoker().onStartRenderLevel(deltaTracker.getGameTimeDeltaPartialTick(true), camera, cameraRenderState.projectionMatrix, frustumMatrix.get3x3(new org.joml.Matrix3f()));
}
}
*///?}
}
5 changes: 5 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,5 @@
package net.minecraft.client.gui

//? if >=26 {
/*typealias GuiGraphics = GuiGraphicsExtractor
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import net.minecraft.client.KeyMapping
import org.lwjgl.glfw.GLFW
import ru.octol1ttle.flightassistant.FlightAssistant.mc
import ru.octol1ttle.flightassistant.api.computer.ComputerBus
//? if >=26 {
/*import ru.octol1ttle.flightassistant.api.util.extensions.setScreen
*///?}
import ru.octol1ttle.flightassistant.config.FAConfig
import ru.octol1ttle.flightassistant.screen.FlightAssistantSetupScreen

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ object FlightAssistant {

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

RenderMatrices.worldSpaceNoRollMatrix.set(Matrix4f().apply {
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
@@ -0,0 +1,92 @@
package ru.octol1ttle.flightassistant.api.util.extensions

// Compatibility shims for Minecraft 26.x, where `GuiGraphics` was replaced by the
// `GuiGraphicsExtractor` render-state model. These only apply on 26+, on older
// versions `GuiGraphics` is still a real class with these members.
//? if >=26 {
/*import net.minecraft.client.gui.Font
import net.minecraft.client.gui.GuiGraphicsExtractor
import net.minecraft.network.chat.Component
import org.joml.Matrix3x2fStack
import org.joml.Quaternionfc
import kotlin.math.atan2

fun GuiGraphicsExtractor.drawString(font: Font, text: String, x: Int, y: Int, color: Int, shadow: Boolean = false): Int {
text(font, text, x, y, color, shadow)
return 1
}

fun GuiGraphicsExtractor.drawString(font: Font, text: Component, x: Int, y: Int, color: Int, shadow: Boolean = false): Int {
text(font, text, x, y, color, shadow)
return 1
}

fun GuiGraphicsExtractor.drawCenteredString(font: Font, text: Component, x: Int, y: Int, color: Int): Int {
centeredText(font, text, x, y, color)
return 1
}

fun GuiGraphicsExtractor.hLine(x1: Int, x2: Int, y: Int, color: Int) {
horizontalLine(x1, x2, y, color)
}

fun GuiGraphicsExtractor.vLine(x: Int, y1: Int, y2: Int, color: Int) {
verticalLine(x, y1, y2, color)
}

fun Matrix3x2fStack.translate(x: Float, y: Float, z: Float): Matrix3x2fStack {
translate(x, y)
return this
}

fun Matrix3x2fStack.mulPose(q: Quaternionfc): Matrix3x2fStack {
rotate(2f * atan2(q.z(), q.w()))
return this
}

fun Matrix3x2fStack.rotateAround(q: Quaternionfc, x: Float, y: Float, z: Float): Matrix3x2fStack {
translate(x, y)
rotate(2f * atan2(q.z(), q.w()))
translate(-x, -y)
return this
}

// ChatFormatting lost its `color` field in 26.x; provide it as an extension.
val net.minecraft.ChatFormatting.color: Int?
get() = when (this) {
net.minecraft.ChatFormatting.BLACK -> 0x000000
net.minecraft.ChatFormatting.DARK_BLUE -> 0x0000AA
net.minecraft.ChatFormatting.DARK_GREEN -> 0x00AA00
net.minecraft.ChatFormatting.DARK_AQUA -> 0x00AAAA
net.minecraft.ChatFormatting.DARK_RED -> 0xAA0000
net.minecraft.ChatFormatting.DARK_PURPLE -> 0xAA00AA
net.minecraft.ChatFormatting.GOLD -> 0xFFAA00
net.minecraft.ChatFormatting.GRAY -> 0xAAAAAA
net.minecraft.ChatFormatting.DARK_GRAY -> 0x555555
net.minecraft.ChatFormatting.BLUE -> 0x5555FF
net.minecraft.ChatFormatting.GREEN -> 0x55FF55
net.minecraft.ChatFormatting.AQUA -> 0x55FFFF
net.minecraft.ChatFormatting.RED -> 0xFF5555
net.minecraft.ChatFormatting.LIGHT_PURPLE -> 0xFF55FF
net.minecraft.ChatFormatting.YELLOW -> 0xFFFF55
net.minecraft.ChatFormatting.WHITE -> 0xFFFFFF
else -> null
}

// Minecraft.setScreen was renamed to setScreenAndShow in 26.x, and the current
// screen/overlay moved to Minecraft.gui.
fun net.minecraft.client.Minecraft.setScreen(screen: net.minecraft.client.gui.screens.Screen?) {
gui.setScreen(screen)
}

val net.minecraft.client.Minecraft.screen: net.minecraft.client.gui.screens.Screen?
get() = gui.screen()

val net.minecraft.client.Minecraft.overlay: net.minecraft.client.gui.screens.Overlay?
get() = gui.overlay()

// Renderable no longer has `render`, it now uses `extractRenderState`.
fun net.minecraft.client.gui.components.Renderable.render(guiGraphics: GuiGraphicsExtractor, mouseX: Int, mouseY: Int, partialTick: Float) {
extractRenderState(guiGraphics, mouseX, mouseY, partialTick)
}
*///?}
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,23 @@ fun org.joml.Matrix3x2fStack.pop() {
popMatrix()
}

//? if >=1.21.9 {
//? if >=26 {
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
outline(x, y, width, height, color)
}
*///?} else {
//? if >=1.21.11 {
/^renderOutline(
^///?} else
submitOutline(
x, y, width, height, color)
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
renderOutline(x, y, width, height, color)
}
*///?} else {
//? if >=1.21.9 {
/*fun GuiGraphics.renderOutline(x: Int, y: Int, width: Int, height: Int, color: Int) {
submitOutline(x, y, width, height, color)
renderDeferredElements()
}
*///?}
*///?} else {
// (<1.21.9) vanilla GuiGraphics.renderOutline exists; no extension needed.
//?}
//?}
//?}
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,15 @@ class FireworkComputer(computers: ComputerBus, private val mc: Minecraft) : Comp
val explosive = FAConfig.safety.fireworkLockExplosive && !isEmptyOrSafe(player, hand)
val anyTerrainAhead = FAConfig.safety.fireworkLockObstacles && anyTerrainAhead()
if (computers.data.automationsAllowed() && (explosive || anyTerrainAhead)) {
//? if >=26 {
/*return@RightClickItem dev.architectury.event.EventResult.interruptFalse()
*///?} else {
//? if >=1.21.2 {
/*return@RightClickItem net.minecraft.world.InteractionResult.FAIL
*///?} else
*///?} else {
return@RightClickItem dev.architectury.event.CompoundEventResult.interruptFalse(stack)
//?}
//?}
}

if (!waitingForResponse) {
Expand All @@ -53,10 +58,15 @@ class FireworkComputer(computers: ComputerBus, private val mc: Minecraft) : Comp
}
}

//? if >=26 {
/*return@RightClickItem dev.architectury.event.EventResult.pass()
*///?} else {
//? if >=1.21.2 {
/*return@RightClickItem net.minecraft.world.InteractionResult.PASS
*///?} else
*///?} else {
return@RightClickItem dev.architectury.event.CompoundEventResult.pass()
//?}
//?}
})
FireworkBoostCallback.EVENT.register(FireworkBoostCallback { _, _ ->
if (waitingForResponse) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,13 @@ import ru.octol1ttle.flightassistant.api.computer.ComputerBus
import ru.octol1ttle.flightassistant.api.util.degrees
import ru.octol1ttle.flightassistant.api.util.extensions.bottomY
import ru.octol1ttle.flightassistant.api.util.extensions.getLerpedDeltaMovement
//? if >=26 {
/*import ru.octol1ttle.flightassistant.api.util.extensions.overlay
*///?}
import ru.octol1ttle.flightassistant.api.util.extensions.perSecond
//? if >=26 {
/*import ru.octol1ttle.flightassistant.api.util.extensions.screen
*///?}
import ru.octol1ttle.flightassistant.api.util.throwIfNotInRange
import ru.octol1ttle.flightassistant.config.FAConfig

Expand Down
Loading