Skip to content

Commit a8a1f2b

Browse files
authored
Build: Port to 1.21.2 Fabric
GitHub: #85
1 parent afb891d commit a8a1f2b

File tree

10 files changed

+140
-60
lines changed

10 files changed

+140
-60
lines changed

api/UniversalCraft.api

+52-52
Large diffs are not rendered by default.

root.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ version = versionFromBuildIdAndBranch()
1111
preprocess {
1212
strictExtraMappings.set(true)
1313

14+
val fabric12102 = createNode("1.21.2-fabric", 12102, "srg")
1415
val fabric12100 = createNode("1.21-fabric", 12100, "srg")
1516
val fabric12006 = createNode("1.20.6-fabric", 12006, "srg")
1617
val forge12004 = createNode("1.20.4-forge", 12004, "srg")
@@ -37,6 +38,7 @@ preprocess {
3738
val forge11202 = createNode("1.12.2-forge", 11202, "srg")
3839
val forge10809 = createNode("1.8.9-forge", 10809, "srg")
3940

41+
fabric12102.link(fabric12100)
4042
fabric12100.link(fabric12006)
4143
fabric12006.link(fabric12004)
4244
forge12004.link(fabric12004)

settings.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ listOf(
4646
"1.20.4-forge",
4747
"1.20.6-fabric",
4848
"1.21-fabric",
49+
"1.21.2-fabric",
4950
).forEach { version ->
5051
include(":$version")
5152
project(":$version").apply {

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

+37-5
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@
4444
import static org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE;
4545
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;
4646

47+
//#if MC>=12102
48+
//$$ import net.minecraft.client.gl.ShaderProgramKey;
49+
//$$ import net.minecraft.client.gl.ShaderProgramKeys;
50+
//$$ import java.util.HashMap;
51+
//#endif
52+
4753
//#if MC>=12100
4854
//$$ import net.minecraft.client.render.BufferRenderer;
4955
//$$ import net.minecraft.client.render.BuiltBuffer;
@@ -837,7 +843,11 @@ public static void disableDepth() {
837843

838844
//#if MC>=11700 && !STANDALONE
839845
//$$ public static void setShader(Supplier<Shader> shader) {
840-
//$$ RenderSystem.setShader(shader);
846+
//#if MC>=12102
847+
//$$ RenderSystem.setShader(shader.get());
848+
//#else
849+
//$$ RenderSystem.setShader(shader);
850+
//#endif
841851
//$$ }
842852
//#endif
843853

@@ -971,7 +981,20 @@ public UGraphics beginWithActiveShader(DrawMode mode, VertexFormat format) {
971981
}
972982
//#endif
973983

974-
//#if MC>=11700 && !STANDALONE
984+
//#if STANDALONE
985+
//#elseif MC>=12102
986+
//$$ private static final Map<VertexFormat, ShaderProgramKey> DEFAULT_SHADERS = new HashMap<>();
987+
//$$ static {
988+
//$$ DEFAULT_SHADERS.put(VertexFormats.LINES, ShaderProgramKeys.RENDERTYPE_LINES);
989+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR_LIGHT, ShaderProgramKeys.PARTICLE);
990+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION, ShaderProgramKeys.POSITION);
991+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR, ShaderProgramKeys.POSITION_COLOR);
992+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_LIGHT, ShaderProgramKeys.POSITION_COLOR_LIGHTMAP);
993+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE, ShaderProgramKeys.POSITION_TEX);
994+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR, ShaderProgramKeys.POSITION_TEX_COLOR);
995+
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT, ShaderProgramKeys.POSITION_COLOR_TEX_LIGHTMAP);
996+
//$$ }
997+
//#elseif MC>=11700
975998
//$$ // Note: Needs to be an Identity hash map because VertexFormat's equals method is broken (compares via its
976999
//$$ // component Map but order very much matters for VertexFormat) as of 1.17
9771000
//$$ private static final Map<VertexFormat, Supplier<Shader>> DEFAULT_SHADERS = new IdentityHashMap<>();
@@ -1011,11 +1034,16 @@ public UGraphics beginWithDefaultShader(DrawMode mode, CommonVertexFormats forma
10111034
//#if !STANDALONE
10121035
public UGraphics beginWithDefaultShader(DrawMode mode, VertexFormat format) {
10131036
//#if MC>=11700
1014-
//$$ Supplier<Shader> supplier = DEFAULT_SHADERS.get(format);
1015-
//$$ if (supplier == null) {
1037+
//#if MC>=12102
1038+
//$$ ShaderProgramKey shader = DEFAULT_SHADERS.get(format);
1039+
//#else
1040+
//$$ Supplier<Shader> shader = DEFAULT_SHADERS.get(format);
1041+
//#endif
1042+
//$$ if (shader == null) {
10161043
//$$ throw new IllegalArgumentException("No default shader for " + format + ". Bind your own and use beginWithActiveShader instead.");
10171044
//$$ }
1018-
//$$ setShader(supplier);
1045+
//$$
1046+
//$$ RenderSystem.setShader(shader);
10191047
//#endif
10201048
return beginWithActiveShader(mode, format);
10211049
}
@@ -1079,8 +1107,12 @@ public void drawSorted(int cameraX, int cameraY, int cameraZ) {
10791107
//#else
10801108
//#if MC>=12100
10811109
//$$ BuiltBuffer builtBuffer = instance.end();
1110+
//#if MC>=12102
1111+
//$$ builtBuffer.sortQuads(SORTED_QUADS_ALLOCATOR, RenderSystem.getProjectionType().getVertexSorter());
1112+
//#else
10821113
//$$ builtBuffer.sortQuads(SORTED_QUADS_ALLOCATOR, RenderSystem.getVertexSorting());
10831114
//#endif
1115+
//#endif
10841116
//#if MC>=11600
10851117
//$$ if (renderLayer != null) {
10861118
//#if MC>=12100

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

+8
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,34 @@ class UImage(val nativeImage: BufferedImage) {
3131

3232
fun getPixelRGBA(x: Int, y: Int): Int {
3333
//#if MC>=11600 && !STANDALONE
34+
//#if MC>=12102
35+
//$$ return Integer.rotateLeft(nativeImage.getColorArgb(x, y), 8) // Convert ARGB to RGBA
36+
//#else
3437
//$$ // Convert ABGR to RGBA
3538
//$$ val abgr = nativeImage.getPixelRGBA(x, y) // mappings are incorrect, this returns ABGR
3639
//$$ val a = abgr shr 24 and 0xFF
3740
//$$ val b = abgr shr 16 and 0xFF
3841
//$$ val g = abgr shr 8 and 0xFF
3942
//$$ val r = abgr and 0xFF
4043
//$$ return (r shl 24) or (g shl 16) or (b shl 8) or a
44+
//#endif
4145
//#else
4246
return Integer.rotateLeft(nativeImage.getRGB(x, y), 8) // Convert ARGB to RGBA
4347
//#endif
4448
}
4549

4650
fun setPixelRGBA(x: Int, y: Int, color: Int) {
4751
//#if MC>=11600 && !STANDALONE
52+
//#if MC>=12102
53+
//$$ nativeImage.setColorArgb(x, y, Integer.rotateRight(color, 8)) // Convert RGBA to ARGB
54+
//#else
4855
//$$ // Convert RGBA to ABGR
4956
//$$ val r = color shr 24 and 0xFF
5057
//$$ val g = color shr 16 and 0xFF
5158
//$$ val b = color shr 8 and 0xFF
5259
//$$ val a = color and 0xFF
5360
//$$ nativeImage.setPixelRGBA(x, y, (a shl 24) or (b shl 16) or (g shl 8) or r) // mappings are incorrect, this takes ABGR
61+
//#endif
5462
//#else
5563
nativeImage.setRGB(x, y, Integer.rotateRight(color, 8)) // Convert RGBA to ARGB
5664
//#endif

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

+4
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,9 @@ class UMatrixStack private constructor(
191191
//#else
192192
//$$ RenderSystem.getModelViewStack().method_34425(stack.last.model)
193193
//#endif
194+
//#if MC<12102
194195
//$$ RenderSystem.applyModelViewMatrix()
196+
//#endif
195197
//#else
196198
stack.last.model.store(MATRIX_BUFFER)
197199
// Explicit cast to Buffer required so we do not use the JDK9+ override in FloatBuffer
@@ -247,7 +249,9 @@ class UMatrixStack private constructor(
247249
//#else
248250
//$$ stack.pop()
249251
//#endif
252+
//#if MC<12102
250253
//$$ RenderSystem.applyModelViewMatrix()
254+
//#endif
251255
//#else
252256
UGraphics.GL.popMatrix()
253257
//#endif

src/main/kotlin/gg/essential/universal/shader/BlendState.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import gg.essential.universal.UGraphics
44
import org.lwjgl.opengl.GL11
55
import org.lwjgl.opengl.GL14
66

7-
//#if MC>=11700 && !STANDALONE
7+
//#if MC>=11700 && MC<12102
88
//$$ import net.minecraft.client.gl.GlBlendState
99
//#endif
1010

@@ -22,7 +22,7 @@ data class BlendState(
2222
) {
2323
val separate = srcRgb != srcAlpha || dstRgb != dstAlpha
2424

25-
//#if MC>=11700 && !STANDALONE
25+
//#if MC>=11700 && MC<12102
2626
//$$ private inner class McBlendState : GlBlendState {
2727
//$$ constructor() : super()
2828
//$$ constructor(srcRgb: Int, dstRgb: Int, func: Int) : super(srcRgb, dstRgb, func)

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ object UPlayer {
1616

1717
@JvmStatic
1818
fun sendClientSideMessage(message: UTextComponent) {
19-
//#if MC>=11900
19+
//#if MC>=12102
20+
//$$ getPlayer()!!.sendMessage(message, false)
21+
//#elseif MC>=11900
2022
//$$ getPlayer()!!.sendMessage(message)
2123
//#elseif MC>=11602
2224
//#if FORGE

versions/1.17.1-fabric/src/main/kotlin/gg/essential/universal/shader/MCShader.kt

+29
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import org.apache.commons.codec.digest.DigestUtils
1414
import java.io.FileNotFoundException
1515
import kotlin.NoSuchElementException
1616

17+
//#if MC>=12102
18+
//$$ import net.minecraft.client.gl.CompiledShader
19+
//$$ import net.minecraft.client.gl.ShaderProgramDefinition
20+
//#endif
21+
1722
//#if MC>=11903
1823
//$$ import gg.essential.universal.DummyPack
1924
//#endif
@@ -93,6 +98,7 @@ internal class MCShader(
9398
println(json)
9499
}
95100

101+
//#if MC<12102
96102
val factory = { id: Identifier ->
97103
val content = when {
98104
id.path.endsWith(".json") -> json
@@ -108,6 +114,7 @@ internal class MCShader(
108114
ResourceImpl("__generated__", id, content.byteInputStream(), null)
109115
//#endif
110116
}
117+
//#endif
111118

112119
fun buildVertexFormat(elements: Map<String, VertexFormatElement>): VertexFormat {
113120
//#if MC>=12100
@@ -136,11 +143,29 @@ internal class MCShader(
136143
}
137144

138145

146+
//#if MC>=12102
147+
//$$ val shaderProgram = ShaderProgram.create(
148+
//$$ CompiledShader.compile(
149+
//$$ Identifier.of("universalcraft", DigestUtils.sha1Hex(transformedVertSource).lowercase()),
150+
//$$ CompiledShader.Type.VERTEX, transformedVertSource
151+
//$$ ),
152+
//$$ CompiledShader.compile(
153+
//$$ Identifier.of("universalcraft", DigestUtils.sha1Hex(transformedFragSource).lowercase()),
154+
//$$ CompiledShader.Type.FRAGMENT, transformedFragSource
155+
//$$ ),
156+
//$$ shaderVertexFormat,
157+
//$$ )
158+
//$$ shaderProgram.set(transformer.uniforms.map { (name, type) ->
159+
//$$ ShaderProgramDefinition.Uniform(name, type.typeName, type.default.size, type.default.map { it.toFloat() })
160+
//$$ }, transformer.samplers.map { name -> ShaderProgramDefinition.Sampler(name) })
161+
//$$ return MCShader(shaderProgram, blendState)
162+
//#else
139163
val name = DigestUtils.sha1Hex(json).lowercase()
140164
//#if FORGE
141165
//$$ @Suppress("DEPRECATION") // Forge wants us to use its overload, but we don't care
142166
//#endif
143167
return MCShader(Shader(factory, name, shaderVertexFormat), blendState)
168+
//#endif
144169
}
145170
}
146171
}
@@ -166,6 +191,10 @@ internal class MCSamplerUniform(val mc: Shader, val name: String) : SamplerUnifo
166191
override val location: Int = 0
167192

168193
override fun setValue(textureId: Int) {
194+
//#if MC>=12102
195+
//$$ mc.addSamplerTexture(name, textureId)
196+
//#else
169197
mc.addSampler(name, textureId)
198+
//#endif
170199
}
171200
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
essential.defaults.loom.minecraft=com.mojang:minecraft:1.21.2-rc1
2+
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.2-rc1+build.1:v2

0 commit comments

Comments
 (0)