Skip to content

Commit 49c57cb

Browse files
authored
Build: Port to 1.21.11 Fabric
GitHub: #118
1 parent 1ebcb0f commit 49c57cb

File tree

9 files changed

+183
-88
lines changed

9 files changed

+183
-88
lines changed

api/UniversalCraft.api

Lines changed: 86 additions & 76 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 fabric12111 = createNode("1.21.11-fabric", 12111, "srg")
1516
val fabric12109 = createNode("1.21.9-fabric", 12109, "srg")
1617
val neoForge12107 = createNode("1.21.7-neoforge", 12107, "srg")
1718
val forge12107 = createNode("1.21.7-forge", 12107, "srg")
@@ -57,6 +58,7 @@ preprocess {
5758
val forge11202 = createNode("1.12.2-forge", 11202, "srg")
5859
val forge10809 = createNode("1.8.9-forge", 10809, "srg")
5960

61+
fabric12111.link(fabric12109)
6062
fabric12109.link(fabric12107)
6163
neoForge12107.link(fabric12107)
6264
forge12107.link(fabric12107)

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ listOf(
6565
"1.21.7-forge",
6666
"1.21.7-neoforge",
6767
"1.21.9-fabric",
68+
"1.21.11-fabric",
6869
).forEach { version ->
6970
include(":$version")
7071
project(":$version").apply {

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

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
import static org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE;
4747
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
4848

49+
//#if MC>=12111
50+
//$$ import com.mojang.blaze3d.textures.FilterMode;
51+
//#endif
52+
4953
//#if MC>=12109
5054
//$$ import net.minecraft.client.font.TextDrawable;
5155
//$$ import net.minecraft.text.StyleSpriteSource;
@@ -519,9 +523,12 @@ public static void bindTexture(ResourceLocation resourceLocation) {
519523
}
520524
//#endif
521525

526+
@Deprecated // see UGraphics.Globals
522527
public static void bindTexture(int index, int glTextureId) {
523528
//#if STANDALONE
524529
//$$ configureTextureUnit(index, () -> glBindTexture(GL_TEXTURE_2D, glTextureId));
530+
//#elseif MC>=12111
531+
//$$ throw new UnsupportedOperationException("No longer supported on 1.21.11+, use `UBufferBuilder`/`URenderPipeline` instead.");
525532
//#elseif MC>=12106
526533
//$$ RenderSystem.setShaderTexture(index, RenderSystem.getDevice().createTextureView(new UnownedGlTexture(glTextureId)));
527534
//#elseif MC>=12105
@@ -534,6 +541,7 @@ public static void bindTexture(int index, int glTextureId) {
534541
}
535542

536543
//#if !STANDALONE
544+
@Deprecated // see UGraphics.Globals
537545
public static void bindTexture(int index, ResourceLocation resourceLocation) {
538546
bindTexture(index, getOrLoadTextureId(resourceLocation));
539547
}
@@ -687,8 +695,13 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
687695
//$$ try (URenderPass renderPass = new URenderPass()) {
688696
//$$ renderPass.draw(UBuiltBuffer.wrap(builtBuffer), URenderPipeline.wrap(pipeline), builder -> {
689697
//$$ RenderPass mcRenderPass = ((URenderPass.DrawCallBuilderImpl) builder).getMc();
690-
//$$ mcRenderPass.bindSampler("Sampler0", texture);
691-
//$$ mcRenderPass.bindSampler("Sampler2", lightTexture);
698+
//#if MC>=12111
699+
//$$ mcRenderPass.bindTexture("Sampler0", texture, RenderSystem.getSamplerCache().get(FilterMode.NEAREST));
700+
//$$ mcRenderPass.bindTexture("Sampler2", lightTexture, RenderSystem.getSamplerCache().get(FilterMode.LINEAR));
701+
//#else
702+
//$$ mcRenderPass.bindSampler("Sampler0", texture);
703+
//$$ mcRenderPass.bindSampler("Sampler2", lightTexture);
704+
//#endif
692705
//$$ return kotlin.Unit.INSTANCE;
693706
//$$ });
694707
//$$ }
@@ -705,7 +718,11 @@ public static void drawString(UMatrixStack stack, String text, float x, float y,
705718
//$$ }
706719
//$$ drawable.render(matrix, bufferBuilder, LIGHT, false);
707720
//$$ }
721+
//#if MC>=12111
722+
//$$ @Override public void drawGlyph(TextDrawable.DrawnGlyphRect glyph) { draw(glyph); }
723+
//#else
708724
//$$ @Override public void drawGlyph(TextDrawable drawable) { draw(drawable); }
725+
//#endif
709726
//$$ @Override public void drawRectangle(TextDrawable drawable) { draw(drawable); }
710727
//#else
711728
//$$ private void setupBuffer(BakedGlyph bakedGlyph) {
@@ -1028,6 +1045,10 @@ public static void disableScissor() {
10281045

10291046
public enum DrawMode {
10301047
LINES(GL11.GL_LINES),
1048+
/**
1049+
* @deprecated No longer properly supported as of 1.21.11, use {@link #LINES} instead
1050+
*/
1051+
@Deprecated
10311052
LINE_STRIP(GL11.GL_LINE_STRIP),
10321053
TRIANGLES(GL11.GL_TRIANGLES),
10331054
TRIANGLE_STRIP(GL11.GL_TRIANGLE_STRIP),
@@ -1059,7 +1080,11 @@ public enum DrawMode {
10591080
//$$ private static VertexFormat.DrawMode glToMcDrawMode(int glMode) {
10601081
//$$ switch (glMode) {
10611082
//$$ case GL11.GL_LINES: return VertexFormat.DrawMode.LINES;
1062-
//$$ case GL11.GL_LINE_STRIP: return VertexFormat.DrawMode.LINE_STRIP;
1083+
//#if MC>=12111
1084+
//$$ case GL11.GL_LINE_STRIP: return VertexFormat.DrawMode.DEBUG_LINE_STRIP;
1085+
//#else
1086+
//$$ case GL11.GL_LINE_STRIP: return VertexFormat.DrawMode.LINE_STRIP;
1087+
//#endif
10631088
//$$ case GL11.GL_TRIANGLES: return VertexFormat.DrawMode.TRIANGLES;
10641089
//$$ case GL11.GL_TRIANGLE_STRIP: return VertexFormat.DrawMode.TRIANGLE_STRIP;
10651090
//$$ case GL11.GL_TRIANGLE_FAN: return VertexFormat.DrawMode.TRIANGLE_FAN;
@@ -1071,7 +1096,11 @@ public enum DrawMode {
10711096
//$$ private static DrawMode fromMc(VertexFormat.DrawMode mcMode) {
10721097
//$$ switch (mcMode) {
10731098
//$$ case LINES: return DrawMode.LINES;
1074-
//$$ case LINE_STRIP: return DrawMode.LINE_STRIP;
1099+
//#if MC>=12111
1100+
//$$ case DEBUG_LINE_STRIP: return DrawMode.LINE_STRIP;
1101+
//#else
1102+
//$$ case LINE_STRIP: return DrawMode.LINE_STRIP;
1103+
//#endif
10751104
//$$ case TRIANGLES: return DrawMode.TRIANGLES;
10761105
//$$ case TRIANGLE_STRIP: return DrawMode.TRIANGLE_STRIP;
10771106
//$$ case TRIANGLE_FAN: return DrawMode.TRIANGLE_FAN;
@@ -1543,7 +1572,7 @@ public UGraphics light(int u, int v) {
15431572
return this;
15441573
}
15451574

1546-
//#if MC>=12105 && !STANDALONE
1575+
//#if MC>=12105 && MC<12111
15471576
//$$ private static class UnownedGlTexture extends GlTexture {
15481577
//$$ public UnownedGlTexture(int glId) {
15491578
//#if MC>=12106
@@ -1606,6 +1635,8 @@ public static void scale(double x, double y, double z) {
16061635
* {@code RenderSystem.setShaderTexture}, but just like the vanilla {@code RenderPipeline},
16071636
* {@code URenderPipeline} also requires textures to be set explicitly, despite {@code UGraphics.bindTexture} not
16081637
* yet being deprecated (because it's still used for {@code RenderLayer}).
1638+
* <br>
1639+
* Update: As of 1.21.11, {@code UGraphics.bindTexture} is now deprecated too.
16091640
* <p>
16101641
* If you need to still use the old global state on versions prior to 1.21.5, you may use the methods declared in
16111642
* this class. They are functionally identical to the ones in UGraphics but are not deprecated with the
@@ -1691,5 +1722,17 @@ public UGraphics beginWithDefaultShader(DrawMode mode, VertexFormat format) {
16911722
}
16921723
//#endif
16931724
//#endif
1725+
1726+
//#if MC<12111 || STANDALONE
1727+
public static void bindTexture(int index, int glTextureId) {
1728+
UGraphics.bindTexture(index, glTextureId);
1729+
}
1730+
1731+
//#if !STANDALONE
1732+
public static void bindTexture(int index, ResourceLocation resourceLocation) {
1733+
UGraphics.bindTexture(index, resourceLocation);
1734+
}
1735+
//#endif
1736+
//#endif
16941737
}
16951738
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import gg.essential.universal.vertex.UBuiltBufferInternal
55

66
//#if STANDALONE
77
//#else
8+
//#if MC>=12111
9+
//$$ import net.minecraft.client.render.RenderLayers
10+
//#endif
11+
812
//#if MC>=12106
913
//$$ import com.mojang.blaze3d.buffers.GpuBuffer
1014
//$$ import org.lwjgl.system.MemoryStack
@@ -64,8 +68,12 @@ internal class URenderPass : AutoCloseable {
6468
//#else
6569
//$$ RenderSystem.getModelOffset(),
6670
//#endif
71+
//#if MC>=12111
72+
//$$ org.joml.Matrix4f(),
73+
//#else
6774
//$$ RenderSystem.getTextureMatrix(),
6875
//$$ RenderSystem.getShaderLineWidth(),
76+
//#endif
6977
//$$ )
7078
//#endif
7179
//$$ val builtBuffer = builtBuffer.mc
@@ -158,11 +166,15 @@ internal class URenderPass : AutoCloseable {
158166
//#else
159167
//$$ val texture = object : GlTexture("", TextureFormat.RGBA8, 0, 0, 0, textureGlId) {
160168
//#endif
169+
//#if MC<12111
161170
//$$ init {
162171
//$$ needsReinit = false
163172
//$$ }
173+
//#endif
164174
//$$ }
165-
//#if MC>=12106
175+
//#if MC>=12111
176+
//$$ mc.bindTexture(name, RenderSystem.getDevice().createTextureView(texture), RenderLayers.BLOCK_SAMPLER.get())
177+
//#elseif MC>=12106
166178
//$$ mc.bindSampler(name, RenderSystem.getDevice().createTextureView(texture))
167179
//#else
168180
//$$ mc.bindSampler(name, texture)

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import net.minecraft.util.ResourceLocation
3030
//$$ import net.minecraft.client.gl.UniformType
3131
//$$ import net.minecraft.client.render.BuiltBuffer
3232
//$$ import org.apache.commons.codec.digest.DigestUtils
33-
//$$ import java.util.function.BiFunction
3433
//#else
3534
import gg.essential.universal.shader.UShader
3635
import gg.essential.universal.vertex.UBuiltBufferInternal
@@ -66,14 +65,22 @@ import net.minecraft.client.renderer.vertex.VertexFormatElement
6665

6766
//#endif
6867

68+
//#if MC>=12105 && !STANDALONE
69+
//#if MC>=12111
70+
//$$ typealias ShaderSourceGetter = net.minecraft.client.gl.ShaderSourceGetter
71+
//#else
72+
//$$ typealias ShaderSourceGetter = java.util.function.BiFunction<Identifier, ShaderType, String?>
73+
//#endif
74+
//#endif
75+
6976
class URenderPipeline private constructor(
7077
private val id: ResourceLocation,
7178
internal val format: VertexFormat,
7279
//#if STANDALONE
7380
//$$ private val drawMode: DrawMode,
7481
//#endif
7582
//#if MC>=12105 && !STANDALONE
76-
//$$ private var shaderSourceGetter: BiFunction<Identifier, ShaderType, String?>?,
83+
//$$ private var shaderSourceGetter: ShaderSourceGetter?,
7784
//$$ internal val mcRenderPipeline: RenderPipeline,
7885
//#else
7986
private val shader: ShaderSupplier?,
@@ -230,7 +237,7 @@ class URenderPipeline private constructor(
230237
//$$ return
231238
//$$ }
232239
//#endif
233-
null -> UGraphics.bindTexture(index, glId)
240+
null -> UGraphics.Globals.bindTexture(index, glId)
234241
}
235242
}
236243
//#endif
@@ -365,7 +372,7 @@ class URenderPipeline private constructor(
365372
) : Builder, BuilderProps by BuilderPropsImpl() {
366373
override fun build(): URenderPipeline {
367374
//#if MC>=12105 && !STANDALONE
368-
//$$ var shaderSourceGetter: BiFunction<Identifier, ShaderType, String?>? = null
375+
//$$ var shaderSourceGetter: ShaderSourceGetter? = null
369376
//$$ var mcRenderPipeline = RenderPipeline.builder().apply {
370377
//$$ withLocation(id)
371378
//$$ withVertexFormat(format, drawMode.mcMode)
@@ -379,7 +386,7 @@ class URenderPipeline private constructor(
379386
//$$ val vertId = Identifier.of("universalcraft", "shader/generated/" + DigestUtils.sha1Hex(transformedVertSource).lowercase())
380387
//$$ val fragId = Identifier.of("universalcraft", "shader/generated/" + DigestUtils.sha1Hex(transformedFragSource).lowercase())
381388
//$$
382-
//$$ shaderSourceGetter = BiFunction { id: Identifier, type: ShaderType ->
389+
//$$ shaderSourceGetter = ShaderSourceGetter { id: Identifier, type: ShaderType ->
383390
//$$ when (id) {
384391
//$$ vertId -> transformedVertSource
385392
//$$ fragId -> transformedFragSource

src/main/kotlin/gg/essential/universal/utils/ReleasedDynamicTexture.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import gg.essential.universal.UGraphics
77
//$$ import org.lwjgl.opengl.GL20C
88
//$$ import java.nio.Buffer
99
//#else
10+
//#if MC>=12111
11+
//$$ import com.mojang.blaze3d.textures.AddressMode
12+
//#endif
13+
1014
//#if MC>=12106
1115
//$$ import com.mojang.blaze3d.textures.GpuTextureView
1216
//#endif
@@ -126,6 +130,9 @@ class ReleasedDynamicTexture private constructor(
126130
//#else
127131
//$$ val texture = device.createTexture(null as String?, TextureFormat.RGBA8, width, height, 1)
128132
//#endif
133+
//#if MC>=12111
134+
//$$ sampler = RenderSystem.getSamplerCache().get(AddressMode.REPEAT, AddressMode.REPEAT, FilterMode.LINEAR, FilterMode.NEAREST, true);
135+
//#else
129136
//$$ texture.setTextureFilter(FilterMode.NEAREST, true)
130137
//$$ UGraphics.configureTexture((texture as GlTexture).glId) {
131138
//#if MC>=12106
@@ -134,6 +141,7 @@ class ReleasedDynamicTexture private constructor(
134141
//$$ texture.checkDirty()
135142
//#endif
136143
//$$ }
144+
//#endif
137145
//$$ device.createCommandEncoder().writeToTexture(texture, textureData!!)
138146
//$$ textureData = null
139147
//$$ uploaded = true
@@ -200,12 +208,15 @@ class ReleasedDynamicTexture private constructor(
200208
//$$ return super.getGlTextureView()
201209
//$$ }
202210
//$$
211+
//#if MC<12111
203212
//$$ override fun setUseMipmaps(mipmaps: Boolean) {
204213
//$$ uploadTexture()
205214
//$$ super.setUseMipmaps(mipmaps)
206215
//$$ }
207216
//#endif
217+
//#endif
208218
//$$
219+
//#if MC<12111
209220
//$$ override fun setClamp(clamp: Boolean) {
210221
//$$ uploadTexture()
211222
//$$ super.setClamp(clamp)
@@ -215,6 +226,7 @@ class ReleasedDynamicTexture private constructor(
215226
//$$ uploadTexture()
216227
//$$ super.setFilter(bilinear, mipmap)
217228
//$$ }
229+
//#endif
218230
//$$
219231
//$$ override fun getGlTexture(): GpuTexture {
220232
//$$ uploadTexture()
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
essential.defaults.loom.minecraft=com.mojang:minecraft:1.21.11-pre5
2+
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.11-pre5+build.1:v2
3+
# Required because our Loom doesn't yet support the unpick version included in the above yarn version
4+
essential.loom.disableUnpick=true

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,11 @@ internal class TemporaryTextureAllocator(
7575
height,
7676
1,
7777
1
78-
).apply { setTextureFilter(FilterMode.NEAREST, false) }
78+
).apply {
79+
//#if MC<12111
80+
setTextureFilter(FilterMode.NEAREST, false)
81+
//#endif
82+
}
7983
var depthTexture = gpuDevice.createTexture(
8084
{ "Pre-rendered depth texture" },
8185
GpuTexture.USAGE_RENDER_ATTACHMENT,

0 commit comments

Comments
 (0)