Skip to content

Commit 0030971

Browse files
authored
Build: Port to 26.1 Fabric
GitHub: #126
1 parent bb5390a commit 0030971

File tree

10 files changed

+217
-88
lines changed

10 files changed

+217
-88
lines changed

api/UniversalCraft.api

Lines changed: 97 additions & 63 deletions
Large diffs are not rendered by default.

root.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ version = versionFromBuildIdAndBranch()
1212
preprocess {
1313
strictExtraMappings.set(true)
1414

15+
val fabric26_01_00 = createNode("26.1-fabric", 26_01_00, "srg")
1516
val fabric12111 = createNode("1.21.11-fabric", 12111, "srg")
1617
val fabric12109 = createNode("1.21.9-fabric", 12109, "srg")
1718
val neoForge12107 = createNode("1.21.7-neoforge", 12107, "srg")
@@ -58,6 +59,7 @@ preprocess {
5859
val forge11202 = createNode("1.12.2-forge", 11202, "srg")
5960
val forge10809 = createNode("1.8.9-forge", 10809, "srg")
6061

62+
fabric26_01_00.link(fabric12111)
6163
fabric12111.link(fabric12109)
6264
fabric12109.link(fabric12107)
6365
neoForge12107.link(fabric12107)

settings.gradle.kts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ pluginManagement {
88
maven("https://repo.essential.gg/repository/maven-public")
99
}
1010
plugins {
11-
val egtVersion = "0.7.0-alpha.2"
11+
val egtVersion = "0.7.0-alpha.4"
1212
id("gg.essential.multi-version.root") version egtVersion
1313
id("gg.essential.multi-version.api-validation") version egtVersion
1414
}
@@ -66,6 +66,7 @@ listOf(
6666
"1.21.7-neoforge",
6767
"1.21.9-fabric",
6868
"1.21.11-fabric",
69+
"26.1-fabric",
6970
).forEach { version ->
7071
include(":$version")
7172
project(":$version").apply {

src/main/java/gg/essential/universal/UGraphics.java

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -668,7 +668,18 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
668668

669669
//#if MC>=12106 && !STANDALONE
670670
//$$ private static class GlyphDrawerImpl implements TextRenderer.GlyphDrawer {
671-
//$$ private static final int LIGHT = 0x00F0_00F0; // see GlyphGuiElementRenderState.setupVertices
671+
//#if MC >= 26.1
672+
//$$ private final GpuTextureView lightTexture = Minecraft.getInstance().gameRenderer.lightmap();
673+
//$$ // lightmap() may return either the uiLightmap, which is 1x1, or the regular lightmap (like pre-26.1)
674+
//$$ // and the text shader uses texelFetch which ignores the wrapping mode, so we need to pass it 0/0 as the
675+
//$$ // light coord or it will simply return 0 as the color.
676+
//$$ // for the 0, see GlyphRenderState.buildVertices
677+
//$$ // for the 0x00F0_00F0, see e.g. DrawableGizmoPrimitives.Group.renderTexts
678+
//$$ private final int light = lightTexture.getWidth(0) == 1 ? 0 : 0x00F0_00F0;
679+
//#else
680+
//$$ private final GpuTextureView lightTexture = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().getGlTextureView();
681+
//$$ private final int light = 0x00F0_00F0; // see GlyphGuiElementRenderState.setupVertices
682+
//#endif
672683
//$$ private org.joml.Matrix4f matrix;
673684
//$$ private RenderPipeline pipeline;
674685
//$$ private GpuTextureView texture;
@@ -691,7 +702,11 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
691702
//$$
692703
//$$ try (BuiltBuffer builtBuffer = bufferBuilder.endNullable()) {
693704
//$$ if (builtBuffer == null) return;
694-
//$$ GpuTextureView lightTexture = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().getGlTextureView();
705+
//#if MC >= 26.1
706+
//$$ GpuTextureView lightTexture = Minecraft.getInstance().gameRenderer.lightmap();
707+
//#else
708+
//$$ GpuTextureView lightTexture = MinecraftClient.getInstance().gameRenderer.getLightmapTextureManager().getGlTextureView();
709+
//#endif
695710
//$$ try (URenderPass renderPass = new URenderPass()) {
696711
//$$ renderPass.draw(UBuiltBuffer.wrap(builtBuffer), URenderPipeline.wrap(pipeline), builder -> {
697712
//$$ RenderPass mcRenderPass = ((URenderPass.DrawCallBuilderImpl) builder).getMc();
@@ -716,7 +731,7 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
716731
//$$ texture = drawable.textureView();
717732
//$$ bufferBuilder = Tessellator.getInstance().begin(pipeline.getVertexFormatMode(), pipeline.getVertexFormat());
718733
//$$ }
719-
//$$ drawable.render(matrix, bufferBuilder, LIGHT, false);
734+
//$$ drawable.render(matrix, bufferBuilder, light, false);
720735
//$$ }
721736
//#if MC>=12111
722737
//$$ @Override public void drawGlyph(TextDrawable.DrawnGlyphRect glyph) { draw(glyph); }
@@ -740,13 +755,13 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
740755
//$$ BakedGlyph bakedGlyph = drawnGlyph.glyph();
741756
//$$ if (bakedGlyph.getTexture() == null) return;
742757
//$$ setupBuffer(bakedGlyph);
743-
//$$ bakedGlyph.draw(drawnGlyph, matrix, bufferBuilder, LIGHT, false);
758+
//$$ bakedGlyph.draw(drawnGlyph, matrix, bufferBuilder, light, false);
744759
//$$ }
745760
//$$
746761
//$$ @Override
747762
//$$ public void drawRectangle(BakedGlyph bakedGlyph, BakedGlyph.Rectangle rectangle) {
748763
//$$ if (bakedGlyph.getTexture() == null) return;
749-
//$$ bakedGlyph.drawRectangle(rectangle, matrix, bufferBuilder, LIGHT, false);
764+
//$$ bakedGlyph.drawRectangle(rectangle, matrix, bufferBuilder, light, false);
750765
//$$ }
751766
//#endif
752767
//$$ }

src/main/kotlin/gg/essential/universal/UScreen.kt

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,16 @@ abstract class UScreen(
147147
//$$
148148
//$$ final override fun charTyped(input: CharInput): Boolean {
149149
//$$ val codepoint = input.codepoint
150+
//#if MC >= 26.1
151+
//$$ val modifiers = 0.toModifiers()
152+
//#else
153+
//$$ val modifiers = input.modifiers.toModifiers()
154+
//#endif
150155
//$$ if (Character.isBmpCodePoint(codepoint)) {
151-
//$$ onKeyPressed(0, input.codepoint.toChar(), input.modifiers.toModifiers())
156+
//$$ onKeyPressed(0, input.codepoint.toChar(), modifiers)
152157
//$$ } else if (Character.isValidCodePoint(codepoint)) {
153-
//$$ onKeyPressed(0, Character.highSurrogate(input.codepoint), input.modifiers.toModifiers())
154-
//$$ onKeyPressed(0, Character.lowSurrogate(input.codepoint), input.modifiers.toModifiers())
158+
//$$ onKeyPressed(0, Character.highSurrogate(input.codepoint), modifiers)
159+
//$$ onKeyPressed(0, Character.lowSurrogate(input.codepoint), modifiers)
155160
//$$ }
156161
//$$ return false
157162
//$$ }
@@ -407,7 +412,9 @@ abstract class UScreen(
407412
//#endif
408413
//$$ }
409414
//$$ if (typedChar != 0.toChar()) {
410-
//#if MC>=12109
415+
//#if MC >= 26.1
416+
//$$ super.charTyped(CharacterEvent(typedChar.code))
417+
//#elseif MC>=12109
411418
//$$ super.charTyped(CharInput(typedChar.code, modifiers.toInt()))
412419
//#else
413420
//$$ super.charTyped(typedChar, modifiers.toInt())

src/main/kotlin/gg/essential/universal/render/URenderPipeline.kt

Lines changed: 56 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,20 @@ import net.minecraft.util.ResourceLocation
2121
//$$ import com.mojang.blaze3d.vertex.VertexFormatElement
2222
//$$ import com.mojang.blaze3d.pipeline.BlendFunction
2323
//$$ import com.mojang.blaze3d.pipeline.RenderPipeline
24+
//#if MC >= 26.1
25+
//$$ import com.mojang.blaze3d.pipeline.ColorTargetState
26+
//$$ import com.mojang.blaze3d.pipeline.DepthStencilState
27+
//$$ import com.mojang.blaze3d.platform.CompareOp
28+
//#else
2429
//$$ import com.mojang.blaze3d.platform.DepthTestFunction
2530
//$$ import com.mojang.blaze3d.platform.LogicOp
31+
//#endif
2632
//$$ import com.mojang.blaze3d.shaders.ShaderType
2733
//$$ import com.mojang.blaze3d.systems.RenderPass
2834
//$$ import gg.essential.universal.shader.ShaderTransformer
35+
//#if MC < 26.1
2936
//$$ import net.minecraft.client.gl.GlResourceManager
37+
//#endif
3038
//$$ import net.minecraft.client.gl.UniformType
3139
//$$ import net.minecraft.client.render.BuiltBuffer
3240
//$$ import org.apache.commons.codec.digest.DigestUtils
@@ -324,6 +332,7 @@ class URenderPipeline private constructor(
324332
interface BuilderProps {
325333
var depthTest: DepthTest
326334
var culling: Boolean
335+
@Deprecated("Unsupported as of Minecraft 26.1")
327336
var colorLogic: ColorLogic
328337
var blendState: BlendState
329338
var colorMask: Pair</*rgb*/Boolean, /*alpha*/Boolean>
@@ -338,6 +347,7 @@ class URenderPipeline private constructor(
338347
private data class BuilderPropsImpl(
339348
override var depthTest: DepthTest,
340349
override var culling: Boolean,
350+
@Deprecated("Unsupported as of Minecraft 26.1")
341351
override var colorLogic: ColorLogic,
342352
override var blendState: BlendState,
343353
override var colorMask: Pair<Boolean, Boolean>,
@@ -425,6 +435,18 @@ class URenderPipeline private constructor(
425435
//$$ shader.uniforms.forEach { withUniform(it.key, it.value) }
426436
//$$ }
427437
//$$ }
438+
//#if MC >= 26.1
439+
//$$ if (depthTest != DepthTest.Disabled) {
440+
//$$ withDepthStencilState(DepthStencilState(when (depthTest) {
441+
//$$ DepthTest.Disabled -> throw AssertionError("unreachable")
442+
//$$ DepthTest.Always -> CompareOp.ALWAYS_PASS
443+
//$$ DepthTest.Equal -> CompareOp.EQUAL
444+
//$$ DepthTest.LessOrEqual -> CompareOp.LESS_THAN_OR_EQUAL
445+
//$$ DepthTest.Less -> CompareOp.LESS_THAN
446+
//$$ DepthTest.Greater -> CompareOp.GREATER_THAN
447+
//$$ }, depthMask, polygonOffset.first, polygonOffset.second))
448+
//$$ }
449+
//#else
428450
//$$ withDepthTestFunction(when (depthTest) {
429451
//$$ DepthTest.Disabled -> DepthTestFunction.NO_DEPTH_TEST
430452
//$$ DepthTest.Always -> DepthTestFunction.NO_DEPTH_TEST // implemented via raw GlStateManager below
@@ -433,7 +455,29 @@ class URenderPipeline private constructor(
433455
//$$ DepthTest.Less -> DepthTestFunction.LESS_DEPTH_TEST
434456
//$$ DepthTest.Greater -> DepthTestFunction.GREATER_DEPTH_TEST
435457
//$$ })
458+
//$$ withDepthWrite(depthMask)
459+
//$$ polygonOffset.let { (factor, units) ->
460+
//$$ withDepthBias(factor, units)
461+
//$$ }
462+
//#endif
436463
//$$ withCull(culling)
464+
//#if MC >= 26.1
465+
//$$ withColorTargetState(ColorTargetState(
466+
//$$ java.util.Optional.ofNullable(if (blendState.enabled) BlendFunction(
467+
//$$ blendState.srcRgb.mcSourceFactor,
468+
//$$ blendState.dstRgb.mcDestFactor,
469+
//$$ blendState.srcAlpha.mcSourceFactor,
470+
//$$ blendState.dstAlpha.mcDestFactor,
471+
//$$ ) else null),
472+
//$$ colorMask.let { (colorMask, alphaMask) ->
473+
//$$ var flags = 0
474+
//$$ if (colorMask) flags += ColorTargetState.WRITE_COLOR
475+
//$$ if (alphaMask) flags += ColorTargetState.WRITE_ALPHA
476+
//$$ flags
477+
//$$ }
478+
//$$ ))
479+
//#else
480+
//$$ @Suppress("DEPRECATION")
437481
//$$ withColorLogic(when (colorLogic) {
438482
//$$ ColorLogic.None -> LogicOp.NONE
439483
//$$ ColorLogic.OrReverse -> LogicOp.OR_REVERSE
@@ -452,12 +496,10 @@ class URenderPipeline private constructor(
452496
//$$ colorMask.let { (colorMask, alphaMask) ->
453497
//$$ withColorWrite(colorMask, alphaMask)
454498
//$$ }
455-
//$$ withDepthWrite(depthMask)
456-
//$$ polygonOffset.let { (factor, units) ->
457-
//$$ withDepthBias(factor, units)
458-
//$$ }
499+
//#endif
459500
//$$ }.build()
460501
//$$
502+
//#if MC < 26.1
461503
//$$ if (depthTest == DepthTest.Always) {
462504
//$$ abstract class CustomRenderPipeline(inner: RenderPipeline) : RenderPipeline(
463505
//$$ inner.location, inner.vertexShader, inner.fragmentShader, inner.shaderDefines, inner.samplers, inner.uniforms, inner.blendFunction, inner.depthTestFunction, inner.polygonMode, inner.isCull, inner.isWriteColor, inner.isWriteAlpha, inner.isWriteDepth, inner.colorLogic, inner.vertexFormat, inner.vertexFormatMode, inner.depthBiasScaleFactor, inner.depthBiasConstant,
@@ -476,6 +518,7 @@ class URenderPipeline private constructor(
476518
//$$ }
477519
//$$ }
478520
//$$ }
521+
//#endif
479522
//$$
480523
//$$ return URenderPipeline(
481524
//$$ id,
@@ -502,8 +545,8 @@ class URenderPipeline private constructor(
502545
DepthTest.Greater -> GL11.GL_GREATER
503546
},
504547
culling = culling,
505-
colorLogicOp = colorLogic != ColorLogic.None,
506-
colorLogicOpMode = when (colorLogic) {
548+
colorLogicOp = @Suppress("DEPRECATION") colorLogic != ColorLogic.None,
549+
colorLogicOpMode = @Suppress("DEPRECATION") when (colorLogic) {
507550
ColorLogic.None -> GL11.GL_COPY
508551
ColorLogic.OrReverse -> GL11.GL_OR_REVERSE
509552
},
@@ -603,7 +646,13 @@ class URenderPipeline private constructor(
603646
//$$ ?: throw IllegalArgumentException("No default shader for $format.")
604647
//#if MC>=12105
605648
//$$ val shaderId = Identifier.ofVanilla(shader)
606-
//$$ val samplers = List(format.mc.elements.count { it.usage == VertexFormatElement.Usage.UV }) { i -> "Sampler$i" }
649+
//$$ val samplers = List(format.mc.elements.count {
650+
//#if MC >= 26.1
651+
//$$ it == VertexFormatElement.UV0 || it == VertexFormatElement.UV1 || it == VertexFormatElement.UV2
652+
//#else
653+
//$$ it.usage == VertexFormatElement.Usage.UV
654+
//#endif
655+
//$$ }) { i -> "Sampler$i" }
607656
//$$ val uniforms = mapOf(
608657
//#if MC>=12106
609658
//$$ "DynamicTransforms" to UniformType.UNIFORM_BUFFER,

src/main/kotlin/gg/essential/universal/wrappers/UPlayer.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ object UPlayer {
2222

2323
@JvmStatic
2424
fun sendClientSideMessage(message: IChatComponent) {
25-
//#if MC>=12102
25+
//#if MC >= 26.1
26+
//$$ UMinecraft.getMinecraft().gui.chat.addClientSystemMessage(message)
27+
//#elseif MC>=12102
2628
//$$ getPlayer()!!.sendMessage(message, false)
2729
//#elseif MC>=11900
2830
//$$ getPlayer()!!.sendMessage(message)

versions/1.21.6-fabric/src/main/kotlin/gg/essential/universal/AdvancedDrawContext.kt

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,16 @@ import gg.essential.universal.utils.TemporaryTextureAllocator
66
import net.minecraft.client.MinecraftClient
77
import net.minecraft.client.gl.RenderPipelines
88
import net.minecraft.client.gui.DrawContext
9-
import net.minecraft.client.render.ProjectionMatrix2
109
import net.minecraft.client.texture.AbstractTexture
1110
import net.minecraft.util.Identifier
1211

12+
//#if MC >= 26.1
13+
//$$ import net.minecraft.client.renderer.Projection
14+
//$$ import net.minecraft.client.renderer.ProjectionMatrixBuffer
15+
//#else
16+
import net.minecraft.client.render.ProjectionMatrix2
17+
//#endif
18+
1319
/**
1420
* Allows rendering of raw OpenGL into [DrawContext] by drawing to a temporary texture which is then submitted as a
1521
* plain textured quad to [DrawContext].
@@ -22,7 +28,12 @@ import net.minecraft.util.Identifier
2228
* simply re-allocate them.
2329
*/
2430
internal class AdvancedDrawContext : AutoCloseable {
31+
//#if MC >= 26.1
32+
//$$ private val projection = Projection()
33+
//$$ private var allocatedProjectionMatrix: ProjectionMatrixBuffer? = null
34+
//#else
2535
private var allocatedProjectionMatrix: ProjectionMatrix2? = null
36+
//#endif
2637

2738
private val textureAllocator = TemporaryTextureAllocator {
2839
allocatedProjectionMatrix?.close()
@@ -38,13 +49,20 @@ internal class AdvancedDrawContext : AutoCloseable {
3849

3950
var projectionMatrix = allocatedProjectionMatrix
4051
if (projectionMatrix == null) {
52+
//#if MC >= 26.1
53+
//$$ projectionMatrix = ProjectionMatrixBuffer("pre-rendered screen")
54+
//#else
4155
projectionMatrix = ProjectionMatrix2("pre-rendered screen", 1000f, 21000f, true)
56+
//#endif
4257
allocatedProjectionMatrix = projectionMatrix
4358
}
44-
RenderSystem.setProjectionMatrix(
45-
projectionMatrix.set(width.toFloat() / scaleFactor, height.toFloat() / scaleFactor),
46-
ProjectionType.ORTHOGRAPHIC,
47-
)
59+
//#if MC >= 26.1
60+
//$$ projection.setupOrtho(1000f, 21000f, width.toFloat() / scaleFactor, height.toFloat() / scaleFactor, true)
61+
//$$ val projectionMatrixBuffer = projectionMatrix.getBuffer(projection)
62+
//#else
63+
val projectionMatrixBuffer = projectionMatrix.set(width.toFloat() / scaleFactor, height.toFloat() / scaleFactor)
64+
//#endif
65+
RenderSystem.setProjectionMatrix(projectionMatrixBuffer, ProjectionType.ORTHOGRAPHIC)
4866

4967
val orgOutputColorTextureOverride = RenderSystem.outputColorTextureOverride
5068
val orgOutputDepthTextureOverride = RenderSystem.outputDepthTextureOverride

versions/1.21.6-fabric/src/main/kotlin/gg/essential/universal/utils/TemporaryTextureAllocator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal class TemporaryTextureAllocator(
6969

7070
var texture = gpuDevice.createTexture(
7171
{ "Pre-rendered texture" },
72-
GpuTexture.USAGE_RENDER_ATTACHMENT or GpuTexture.USAGE_TEXTURE_BINDING,
72+
GpuTexture.USAGE_COPY_DST or GpuTexture.USAGE_COPY_SRC or GpuTexture.USAGE_RENDER_ATTACHMENT or GpuTexture.USAGE_TEXTURE_BINDING,
7373
TextureFormat.RGBA8,
7474
width,
7575
height,
@@ -82,7 +82,7 @@ internal class TemporaryTextureAllocator(
8282
}
8383
var depthTexture = gpuDevice.createTexture(
8484
{ "Pre-rendered depth texture" },
85-
GpuTexture.USAGE_RENDER_ATTACHMENT,
85+
GpuTexture.USAGE_COPY_DST or GpuTexture.USAGE_COPY_SRC or GpuTexture.USAGE_RENDER_ATTACHMENT,
8686
TextureFormat.DEPTH32,
8787
width,
8888
height,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
essential.defaults.loom.minecraft=com.mojang:minecraft:26.1-snapshot-10

0 commit comments

Comments
 (0)