Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build: Port to 1.21.2 Fabric #85

Merged
merged 1 commit into from
Oct 22, 2024
Merged
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
104 changes: 52 additions & 52 deletions api/UniversalCraft.api

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ version = versionFromBuildIdAndBranch()
preprocess {
strictExtraMappings.set(true)

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

fabric12102.link(fabric12100)
fabric12100.link(fabric12006)
fabric12006.link(fabric12004)
forge12004.link(fabric12004)
Expand Down
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ listOf(
"1.20.4-forge",
"1.20.6-fabric",
"1.21-fabric",
"1.21.2-fabric",
).forEach { version ->
include(":$version")
project(":$version").apply {
Expand Down
42 changes: 37 additions & 5 deletions src/main/java/gg/essential/universal/UGraphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@
import static org.lwjgl.opengl.GL13.GL_ACTIVE_TEXTURE;
import static org.lwjgl.opengl.GL13.GL_TEXTURE0;

//#if MC>=12102
//$$ import net.minecraft.client.gl.ShaderProgramKey;
//$$ import net.minecraft.client.gl.ShaderProgramKeys;
//$$ import java.util.HashMap;
//#endif

//#if MC>=12100
//$$ import net.minecraft.client.render.BufferRenderer;
//$$ import net.minecraft.client.render.BuiltBuffer;
Expand Down Expand Up @@ -837,7 +843,11 @@ public static void disableDepth() {

//#if MC>=11700 && !STANDALONE
//$$ public static void setShader(Supplier<Shader> shader) {
//$$ RenderSystem.setShader(shader);
//#if MC>=12102
//$$ RenderSystem.setShader(shader.get());
//#else
//$$ RenderSystem.setShader(shader);
//#endif
//$$ }
//#endif

Expand Down Expand Up @@ -971,7 +981,20 @@ public UGraphics beginWithActiveShader(DrawMode mode, VertexFormat format) {
}
//#endif

//#if MC>=11700 && !STANDALONE
//#if STANDALONE
//#elseif MC>=12102
//$$ private static final Map<VertexFormat, ShaderProgramKey> DEFAULT_SHADERS = new HashMap<>();
//$$ static {
//$$ DEFAULT_SHADERS.put(VertexFormats.LINES, ShaderProgramKeys.RENDERTYPE_LINES);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR_LIGHT, ShaderProgramKeys.PARTICLE);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION, ShaderProgramKeys.POSITION);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR, ShaderProgramKeys.POSITION_COLOR);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_LIGHT, ShaderProgramKeys.POSITION_COLOR_LIGHTMAP);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE, ShaderProgramKeys.POSITION_TEX);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_TEXTURE_COLOR, ShaderProgramKeys.POSITION_TEX_COLOR);
//$$ DEFAULT_SHADERS.put(VertexFormats.POSITION_COLOR_TEXTURE_LIGHT, ShaderProgramKeys.POSITION_COLOR_TEX_LIGHTMAP);
//$$ }
//#elseif MC>=11700
//$$ // Note: Needs to be an Identity hash map because VertexFormat's equals method is broken (compares via its
//$$ // component Map but order very much matters for VertexFormat) as of 1.17
//$$ private static final Map<VertexFormat, Supplier<Shader>> DEFAULT_SHADERS = new IdentityHashMap<>();
Expand Down Expand Up @@ -1011,11 +1034,16 @@ public UGraphics beginWithDefaultShader(DrawMode mode, CommonVertexFormats forma
//#if !STANDALONE
public UGraphics beginWithDefaultShader(DrawMode mode, VertexFormat format) {
//#if MC>=11700
//$$ Supplier<Shader> supplier = DEFAULT_SHADERS.get(format);
//$$ if (supplier == null) {
//#if MC>=12102
//$$ ShaderProgramKey shader = DEFAULT_SHADERS.get(format);
//#else
//$$ Supplier<Shader> shader = DEFAULT_SHADERS.get(format);
//#endif
//$$ if (shader == null) {
//$$ throw new IllegalArgumentException("No default shader for " + format + ". Bind your own and use beginWithActiveShader instead.");
//$$ }
//$$ setShader(supplier);
//$$
//$$ RenderSystem.setShader(shader);
//#endif
return beginWithActiveShader(mode, format);
}
Expand Down Expand Up @@ -1079,8 +1107,12 @@ public void drawSorted(int cameraX, int cameraY, int cameraZ) {
//#else
//#if MC>=12100
//$$ BuiltBuffer builtBuffer = instance.end();
//#if MC>=12102
//$$ builtBuffer.sortQuads(SORTED_QUADS_ALLOCATOR, RenderSystem.getProjectionType().getVertexSorter());
//#else
//$$ builtBuffer.sortQuads(SORTED_QUADS_ALLOCATOR, RenderSystem.getVertexSorting());
//#endif
//#endif
//#if MC>=11600
//$$ if (renderLayer != null) {
//#if MC>=12100
Expand Down
8 changes: 8 additions & 0 deletions src/main/kotlin/gg/essential/universal/UImage.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,26 +31,34 @@ class UImage(val nativeImage: BufferedImage) {

fun getPixelRGBA(x: Int, y: Int): Int {
//#if MC>=11600 && !STANDALONE
//#if MC>=12102
//$$ return Integer.rotateLeft(nativeImage.getColorArgb(x, y), 8) // Convert ARGB to RGBA
//#else
//$$ // Convert ABGR to RGBA
//$$ val abgr = nativeImage.getPixelRGBA(x, y) // mappings are incorrect, this returns ABGR
//$$ val a = abgr shr 24 and 0xFF
//$$ val b = abgr shr 16 and 0xFF
//$$ val g = abgr shr 8 and 0xFF
//$$ val r = abgr and 0xFF
//$$ return (r shl 24) or (g shl 16) or (b shl 8) or a
//#endif
//#else
return Integer.rotateLeft(nativeImage.getRGB(x, y), 8) // Convert ARGB to RGBA
//#endif
}

fun setPixelRGBA(x: Int, y: Int, color: Int) {
//#if MC>=11600 && !STANDALONE
//#if MC>=12102
//$$ nativeImage.setColorArgb(x, y, Integer.rotateRight(color, 8)) // Convert RGBA to ARGB
//#else
//$$ // Convert RGBA to ABGR
//$$ val r = color shr 24 and 0xFF
//$$ val g = color shr 16 and 0xFF
//$$ val b = color shr 8 and 0xFF
//$$ val a = color and 0xFF
//$$ nativeImage.setPixelRGBA(x, y, (a shl 24) or (b shl 16) or (g shl 8) or r) // mappings are incorrect, this takes ABGR
//#endif
//#else
nativeImage.setRGB(x, y, Integer.rotateRight(color, 8)) // Convert RGBA to ARGB
//#endif
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/gg/essential/universal/UMatrixStack.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,9 @@ class UMatrixStack private constructor(
//#else
//$$ RenderSystem.getModelViewStack().method_34425(stack.last.model)
//#endif
//#if MC<12102
//$$ RenderSystem.applyModelViewMatrix()
//#endif
//#else
stack.last.model.store(MATRIX_BUFFER)
// Explicit cast to Buffer required so we do not use the JDK9+ override in FloatBuffer
Expand Down Expand Up @@ -247,7 +249,9 @@ class UMatrixStack private constructor(
//#else
//$$ stack.pop()
//#endif
//#if MC<12102
//$$ RenderSystem.applyModelViewMatrix()
//#endif
//#else
UGraphics.GL.popMatrix()
//#endif
Expand Down
4 changes: 2 additions & 2 deletions src/main/kotlin/gg/essential/universal/shader/BlendState.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import gg.essential.universal.UGraphics
import org.lwjgl.opengl.GL11
import org.lwjgl.opengl.GL14

//#if MC>=11700 && !STANDALONE
//#if MC>=11700 && MC<12102
//$$ import net.minecraft.client.gl.GlBlendState
//#endif

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

//#if MC>=11700 && !STANDALONE
//#if MC>=11700 && MC<12102
//$$ private inner class McBlendState : GlBlendState {
//$$ constructor() : super()
//$$ constructor(srcRgb: Int, dstRgb: Int, func: Int) : super(srcRgb, dstRgb, func)
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/gg/essential/universal/wrappers/UPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ object UPlayer {

@JvmStatic
fun sendClientSideMessage(message: UTextComponent) {
//#if MC>=11900
//#if MC>=12102
//$$ getPlayer()!!.sendMessage(message, false)
//#elseif MC>=11900
//$$ getPlayer()!!.sendMessage(message)
//#elseif MC>=11602
//#if FORGE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import org.apache.commons.codec.digest.DigestUtils
import java.io.FileNotFoundException
import kotlin.NoSuchElementException

//#if MC>=12102
//$$ import net.minecraft.client.gl.CompiledShader
//$$ import net.minecraft.client.gl.ShaderProgramDefinition
//#endif

//#if MC>=11903
//$$ import gg.essential.universal.DummyPack
//#endif
Expand Down Expand Up @@ -93,6 +98,7 @@ internal class MCShader(
println(json)
}

//#if MC<12102
val factory = { id: Identifier ->
val content = when {
id.path.endsWith(".json") -> json
Expand All @@ -108,6 +114,7 @@ internal class MCShader(
ResourceImpl("__generated__", id, content.byteInputStream(), null)
//#endif
}
//#endif

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


//#if MC>=12102
//$$ val shaderProgram = ShaderProgram.create(
//$$ CompiledShader.compile(
//$$ Identifier.of("universalcraft", DigestUtils.sha1Hex(transformedVertSource).lowercase()),
//$$ CompiledShader.Type.VERTEX, transformedVertSource
//$$ ),
//$$ CompiledShader.compile(
//$$ Identifier.of("universalcraft", DigestUtils.sha1Hex(transformedFragSource).lowercase()),
//$$ CompiledShader.Type.FRAGMENT, transformedFragSource
//$$ ),
//$$ shaderVertexFormat,
//$$ )
//$$ shaderProgram.set(transformer.uniforms.map { (name, type) ->
//$$ ShaderProgramDefinition.Uniform(name, type.typeName, type.default.size, type.default.map { it.toFloat() })
//$$ }, transformer.samplers.map { name -> ShaderProgramDefinition.Sampler(name) })
//$$ return MCShader(shaderProgram, blendState)
//#else
val name = DigestUtils.sha1Hex(json).lowercase()
//#if FORGE
//$$ @Suppress("DEPRECATION") // Forge wants us to use its overload, but we don't care
//#endif
return MCShader(Shader(factory, name, shaderVertexFormat), blendState)
//#endif
}
}
}
Expand All @@ -166,6 +191,10 @@ internal class MCSamplerUniform(val mc: Shader, val name: String) : SamplerUnifo
override val location: Int = 0

override fun setValue(textureId: Int) {
//#if MC>=12102
//$$ mc.addSamplerTexture(name, textureId)
//#else
mc.addSampler(name, textureId)
//#endif
}
}
2 changes: 2 additions & 0 deletions versions/1.21.2-fabric/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
essential.defaults.loom.minecraft=com.mojang:minecraft:1.21.2-rc1
essential.defaults.loom.mappings=net.fabricmc:yarn:1.21.2-rc1+build.1:v2