Skip to content

Commit

Permalink
Build: Port to 1.20.6 Fabric
Browse files Browse the repository at this point in the history
* Build: Port to 1.20.6 Fabric

Sets kotlin language and api version to maintain compatibility with
consumers still using older Kotlin compilers / stdlib.

* UScreen: Fix gui scale handling

As of 1.20.5, the change callback of the guiScale option calls
MinecraftClient#onResolutionChanged, which in turn causes the current
screen to be reinitialized. However, UScreen calls updateGuiScale when
the screen is initialized, causing the gui scale to be set back to
the overridden gui scale. This doesn't recurse forever, since Minecraft
only calls option change callbacks when the value changes.

We fix this by ignoring this call when we are the ones that trigger it.

We also restore the guiScaleToRestore field to -1 when the screen is closed.
This fixes gui scale restoration with screen instances that are reused,
previously the gui scale that was recorded when the gui was opened for
the first time would always be restored.

* Build: remove old code from gradlew

This was from when we used TeamCity, the IS_CI variable not set on
GitHub Actions. Java versions are now managed by the GitHub Actions
workflow.

GitHub: #68
  • Loading branch information
DJtheRedstoner committed May 2, 2024
1 parent 34f682c commit d0ab622
Show file tree
Hide file tree
Showing 12 changed files with 136 additions and 71 deletions.
1 change: 1 addition & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
8
16
17
21
# Can't use setup-java for this because https://github.com/actions/setup-java/issues/366
- uses: actions/cache@v3
Expand Down
106 changes: 53 additions & 53 deletions api/UniversalCraft.api

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import gg.essential.gradle.util.*
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
Expand All @@ -17,6 +18,13 @@ dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.21")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
languageVersion = "1.6"
apiVersion = "1.6"
}
}

tasks.jar {
manifest {
attributes(mapOf("FMLModType" to "LIBRARY"))
Expand Down
5 changes: 0 additions & 5 deletions gradlew
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
#!/usr/bin/env sh

# Need Java 17, and this seems to be the easiest way to do that per-branch for TeamCity
if [ -n "$IS_CI" ]; then
JAVA_HOME=/usr/lib/jvm/jdk-17.0.2
fi

#
# Copyright 2015 the original author or authors.
#
Expand Down
4 changes: 3 additions & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import gg.essential.gradle.util.*

plugins {
kotlin("jvm") version "1.6.10" apply false
kotlin("jvm") version "1.9.23" apply false
id("gg.essential.multi-version.root")
id("gg.essential.multi-version.api-validation")
}

version = versionFromBuildIdAndBranch()

preprocess {
val fabric12006 = createNode("1.20.6-fabric", 12006, "srg")
val forge12004 = createNode("1.20.4-forge", 12004, "srg")
val fabric12004 = createNode("1.20.4-fabric", 12004, "yarn")
val forge12002 = createNode("1.20.2-forge", 12002, "srg")
Expand All @@ -33,6 +34,7 @@ preprocess {
val forge11202 = createNode("1.12.2-forge", 11202, "srg")
val forge10809 = createNode("1.8.9-forge", 10809, "srg")

fabric12006.link(fabric12004)
forge12004.link(fabric12004)
fabric12004.link(fabric12002, file("versions/1.20.4-1.20.2.txt"))
forge12002.link(fabric12002)
Expand Down
5 changes: 3 additions & 2 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pluginManagement {
maven("https://repo.essential.gg/repository/maven-public")
}
plugins {
val egtVersion = "0.4.0"
val egtVersion = "0.5.0"
id("gg.essential.multi-version.root") version egtVersion
id("gg.essential.multi-version.api-validation") version egtVersion
}
Expand Down Expand Up @@ -40,7 +40,8 @@ listOf(
"1.20.2-fabric",
"1.20.2-forge",
"1.20.4-fabric",
"1.20.4-forge"
"1.20.4-forge",
"1.20.6-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
23 changes: 22 additions & 1 deletion src/main/java/gg/essential/universal/UGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
import static org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;

//#if MC>=12005
//$$ import org.joml.Vector3f;
//#endif

//#if MC>=11904
//$$ import net.minecraft.client.font.TextRenderer;
//#endif
Expand Down Expand Up @@ -744,8 +748,18 @@ public enum CommonVertexFormats {
POSITION_TEXTURE(DefaultVertexFormats.POSITION_TEX),
POSITION_TEXTURE_COLOR(DefaultVertexFormats.POSITION_TEX_COLOR),
POSITION_COLOR_TEXTURE_LIGHT(DefaultVertexFormats.BLOCK),
/**
* @deprecated Minecraft removed the built-in shader for this vertex format in 1.20.5, so it is no
* longer universal across all versions.
*/
@Deprecated
POSITION_TEXTURE_LIGHT_COLOR(DefaultVertexFormats.POSITION_TEX_LMAP_COLOR),
POSITION_TEXTURE_COLOR_LIGHT(DefaultVertexFormats.PARTICLE_POSITION_TEX_COLOR_LMAP),
/**
* @deprecated Minecraft removed the built-in shader for this vertex format in 1.20.5, so it is no
* longer universal across all versions.
*/
@Deprecated
POSITION_TEXTURE_COLOR_NORMAL(DefaultVertexFormats.POSITION_TEX_COLOR_NORMAL),
;

Expand Down Expand Up @@ -780,8 +794,12 @@ public UGraphics beginWithActiveShader(DrawMode mode, VertexFormat format) {
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_TEXTURE, GameRenderer::getPositionColorTexShader);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR, GameRenderer::getPositionTexColorShader);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT, GameRenderer::getPositionColorTexLightmapShader);
//#if MC>=12005
//$$ // Shaders for these formats are no longer provided.
//#else
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_LIGHT_COLOR, GameRenderer::getPositionTexLightmapColorShader);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR_NORMAL, GameRenderer::getPositionTexColorNormalShader);
//#endif
//$$ }
//#endif

Expand Down Expand Up @@ -950,7 +968,10 @@ public UGraphics norm(UMatrixStack stack, float x, float y, float z) {
if (stack == UNIT_STACK) {
instance.normal(x, y, z);
} else {
//#if MC>=11602
//#if MC>=12005
//$$ Vector3f normal = stack.peek().getNormal().transform(x, y, z, new Vector3f());
//$$ instance.normal(normal.x(), normal.y(), normal.z());
//#elseif MC>=11602
//$$ instance.normal(stack.peek().getNormal(), x, y, z);
//#else
Vector3f vec = new Vector3f(x, y, z);
Expand Down
16 changes: 14 additions & 2 deletions src/main/kotlin/gg/essential/universal/UMatrixStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ class UMatrixStack private constructor(

fun applyToGlobalState() {
//#if MC>=11700
//#if MC>=11800
//#if MC>=12005
//$$ RenderSystem.getModelViewStack().mul(stack.last.model)
//#elseif MC>=11800
//$$ // FIXME preprocessor bug: should remap the intermediary name to yarn no problem
//$$ RenderSystem.getModelViewStack().multiplyPositionMatrix(stack.last.model)
//#else
Expand All @@ -204,7 +206,9 @@ class UMatrixStack private constructor(
}

fun replaceGlobalState() {
//#if MC>=11700
//#if MC>=12005
//$$ RenderSystem.getModelViewStack().identity()
//#elseif MC>=11700
//$$ RenderSystem.getModelViewStack().loadIdentity()
//#else
GL11.glLoadIdentity()
Expand All @@ -229,13 +233,21 @@ class UMatrixStack private constructor(
private inline fun <R> withGlobalStackPushed(block: () -> R) : R {
//#if MC>=11700
//$$ val stack = RenderSystem.getModelViewStack()
//#if MC>=12005
//$$ stack.pushMatrix()
//#else
//$$ stack.push()
//#endif
//#else
UGraphics.GL.pushMatrix()
//#endif
return block().also {
//#if MC>=11700
//#if MC>=12005
//$$ stack.popMatrix()
//#else
//$$ stack.pop()
//#endif
//$$ RenderSystem.applyModelViewMatrix()
//#else
UGraphics.GL.popMatrix()
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/gg/essential/universal/UMinecraft.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object UMinecraft {
get() = guiScaleValue
set(value) {
guiScaleValue = value
//#if MC>=11502
//#if MC>=11502 && MC<12005
//$$ val mc = getMinecraft()
//$$ val window = mc.mainWindow
//$$ val scaleFactor = window.calcGuiScale(value, mc.forceUnicodeFont)
Expand Down
22 changes: 17 additions & 5 deletions src/main/kotlin/gg/essential/universal/UScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ abstract class UScreen(
) : this(restoreCurrentGuiOnClose, newGuiScale, null)

private var guiScaleToRestore = -1
private var restoringGuiScale = false
private val screenToRestore: GuiScreen? = if (restoreCurrentGuiOnClose) currentScreen else null

//#if MC>=12000
Expand Down Expand Up @@ -141,8 +142,7 @@ abstract class UScreen(
//$$
//$$ final override fun onClose() {
//$$ onScreenClose()
//$$ if (guiScaleToRestore != -1)
//$$ UMinecraft.guiScale = guiScaleToRestore
//$$ restoreGuiScale()
//$$ }
//$$
//#if MC>=12000
Expand Down Expand Up @@ -213,8 +213,7 @@ abstract class UScreen(

final override fun onGuiClosed() {
onScreenClose()
if (guiScaleToRestore != -1)
UMinecraft.guiScale = guiScaleToRestore
restoreGuiScale()
}

final override fun drawWorldBackground(tint: Int) {
Expand All @@ -232,7 +231,7 @@ abstract class UScreen(
}

open fun updateGuiScale() {
if (newGuiScale != -1) {
if (newGuiScale != -1 && !restoringGuiScale) {
if (guiScaleToRestore == -1)
guiScaleToRestore = UMinecraft.guiScale
UMinecraft.guiScale = newGuiScale
Expand All @@ -241,6 +240,19 @@ abstract class UScreen(
}
}

private fun restoreGuiScale() {
if (guiScaleToRestore != -1) {
// This flag is necessary since on 1.20.5 setting the gui scale causes the screen's resize
// method to be called due to an option change callback. This resize causes the screen to reinitialize,
// which calls updateGuiScale. To prevent that method for changing the gui scale back,
// we suppress its behavior with a flag.
restoringGuiScale = true
UMinecraft.guiScale = guiScaleToRestore
restoringGuiScale = false
guiScaleToRestore = -1
}
}

open fun initScreen(width: Int, height: Int) {
//#if MC>=11502
//$$ super.init()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ package gg.essential.universal.vertex
import gg.essential.universal.UMatrixStack
import net.minecraft.client.renderer.WorldRenderer

//#if MC>=12005
//$$ import org.joml.Vector3f
//#endif

//#if MC>=11602
//$$ import com.mojang.blaze3d.vertex.IVertexBuilder
//#else
Expand Down Expand Up @@ -67,7 +71,10 @@ internal class VanillaVertexConsumer(
inner.normal(x, y, z)
return@apply
}
//#if MC>=11602
//#if MC>=12005
//$$ val normal = stack.peek().normal.transform(x, y, z, Vector3f())
//$$ inner.normal(normal.x, normal.y, normal.z)
//#elseif MC>=11602
//$$ inner.normal(stack.peek().normal, x, y, z);
//#else
val vec = Vector3f(x, y, z)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ internal object DummyPack : ResourcePack {
override fun <T : Any?> parseMetadata(metaReader: ResourceMetadataReader<T>?): T? {
throw UnsupportedOperationException()
}

//#if MC>=12005
//$$ override fun getInfo(): net.minecraft.resource.ResourcePackInfo {
//$$ throw UnsupportedOperationException()
//$$ }
//#endif
}

0 comments on commit d0ab622

Please sign in to comment.