From 92c8e36c717143610934b0ecf400d12b3c8af71a Mon Sep 17 00:00:00 2001 From: Username404-59 Date: Wed, 16 Apr 2025 02:46:59 +0200 Subject: [PATCH] Update to 1.21.5 Signed-off-by: Username404-59 --- build.gradle.kts | 4 +- .../mixins/CursedRenderPassMixin.java | 38 ++++++++++++ .../snowygui/config/Configuration.kt | 14 ++--- .../snowygui/gui/elements/ClickBox.kt | 36 ++++++------ .../snowygui/misc/createRenderPassRewrite.kt | 33 +++++++++++ .../snowygui/utils/RenderingUtil.kt | 58 +++++++++++++++---- .../resources/snowygui-fabric.mixins.json | 1 + gradle.properties | 14 ++--- .../resources/snowygui-neoforge.mixins.json | 4 +- 9 files changed, 154 insertions(+), 48 deletions(-) create mode 100644 common/src/main/java/fr/username404/snowygui/mixins/CursedRenderPassMixin.java create mode 100644 common/src/main/kotlin/fr/username404/snowygui/misc/createRenderPassRewrite.kt diff --git a/build.gradle.kts b/build.gradle.kts index fde5157..45c577f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,7 +18,7 @@ plugins { kotlin("plugin.serialization") version "2.0.0" id("com.github.johnrengelman.shadow") version "8.1.1" apply false id("architectury-plugin") version "[3.4.160, 3.5[" - id("dev.architectury.loom") version "1.9-SNAPSHOT" apply false + id("dev.architectury.loom") version "1.10-SNAPSHOT" apply false id("com.github.ben-manes.versions") version "0.51.0" id("net.kyori.indra.git") version "3.1.3" id("org.cqfn.diktat.diktat-gradle-plugin") version "1.2.5" @@ -56,7 +56,7 @@ subprojects { } mappingsDep = layered { silentMojangMappingsLicense() - officialMojangMappings().parchment("org.parchmentmc.data:parchment-1.21:2024.06.23") + officialMojangMappings().parchment("org.parchmentmc.data:parchment-1.21.4:2025.03.23") } val refmap = "snowygui-${project.name}-refmap.json" mixin { diff --git a/common/src/main/java/fr/username404/snowygui/mixins/CursedRenderPassMixin.java b/common/src/main/java/fr/username404/snowygui/mixins/CursedRenderPassMixin.java new file mode 100644 index 0000000..0539589 --- /dev/null +++ b/common/src/main/java/fr/username404/snowygui/mixins/CursedRenderPassMixin.java @@ -0,0 +1,38 @@ +package fr.username404.snowygui.mixins; + +import com.mojang.blaze3d.opengl.*; +import com.mojang.blaze3d.pipeline.RenderPipeline; +import com.mojang.blaze3d.systems.RenderPass; +import com.mojang.blaze3d.textures.GpuTexture; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Overwrite; +import org.spongepowered.asm.mixin.Shadow; + +import static fr.username404.snowygui.misc.CreateRenderPassRewriteKt.createRenderPassRewrite; + +import java.util.OptionalDouble; +import java.util.OptionalInt; + +@Mixin(GlCommandEncoder.class) +abstract class CursedRenderPassMixin { + @Shadow private boolean inRenderPass; + + @Shadow @Final private GlDevice device; + + @Shadow @Nullable private RenderPipeline lastPipeline; + + /** + * @author Username404-59 + * @reason war crimes- I REGRET NOTHING + */ + @Overwrite + public RenderPass createRenderPass(GpuTexture gpuTexture, OptionalInt optionalInt, @Nullable GpuTexture gpuTexture2, OptionalDouble optionalDouble) { + this.inRenderPass = false; // VIP access 😈 + int framebufferId = ((GlTexture)gpuTexture).getFbo(this.device.directStateAccess(), gpuTexture2); + createRenderPassRewrite(framebufferId, gpuTexture, optionalInt, gpuTexture2, optionalDouble); + this.lastPipeline = null; + return new GlRenderPass((GlCommandEncoder) (Object) this, gpuTexture2 != null); + }; +} diff --git a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt index 9db4022..3b63335 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/config/Configuration.kt @@ -11,31 +11,25 @@ import com.typesafe.config.ConfigValueFactory import fr.username404.snowygui.ClickGui import fr.username404.snowygui.Snowy import fr.username404.snowygui.Snowy.Companion.MissingComponent -import fr.username404.snowygui.gui.feature.shouldSave import fr.username404.snowygui.gui.feature.Category import fr.username404.snowygui.gui.feature.Macro +import fr.username404.snowygui.gui.feature.shouldSave import io.github.config4k.extract import io.github.config4k.getValue -import net.minecraft.client.Minecraft - -import java.io.File - -import kotlin.reflect.KProperty import kotlinx.coroutines.CoroutineStart import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking -import kotlinx.serialization.ExperimentalSerializationApi -import kotlinx.serialization.decodeFromString import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json -import net.minecraft.network.chat.MutableComponent +import net.minecraft.client.Minecraft import net.minecraft.network.chat.contents.TranslatableContents import org.jetbrains.annotations.ApiStatus +import java.io.File import kotlin.reflect.KClass +import kotlin.reflect.KProperty import kotlin.reflect.full.isSuperclassOf -@OptIn(ExperimentalSerializationApi::class) object Configuration { @Deprecated("Use the getValue or setValue methods instead", level = DeprecationLevel.ERROR) @JvmStatic diff --git a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt index 43e4fd0..38d9dbf 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/gui/elements/ClickBox.kt @@ -1,8 +1,5 @@ package fr.username404.snowygui.gui.elements -import com.mojang.blaze3d.vertex.BufferUploader -import com.mojang.blaze3d.vertex.DefaultVertexFormat -import com.mojang.blaze3d.vertex.VertexFormat import fr.username404.snowygui.Snowy.Companion.MissingComponent import fr.username404.snowygui.config.Configuration import fr.username404.snowygui.gui.ColoredElement @@ -12,11 +9,12 @@ import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.utils.RenderingUtil.colorShader import fr.username404.snowygui.utils.RenderingUtil.endDraw import fr.username404.snowygui.utils.RenderingUtil.prepareDraw -import fr.username404.snowygui.utils.RenderingUtil.tessellator +import fr.username404.snowygui.utils.RenderingUtil.renderBufferWithPipeline import io.github.config4k.extract import net.minecraft.client.Minecraft import net.minecraft.client.gui.Font import net.minecraft.client.gui.GuiGraphics +import net.minecraft.client.renderer.RenderPipelines import net.minecraft.network.chat.Component import org.jetbrains.annotations.ApiStatus import java.util.TreeSet @@ -82,24 +80,26 @@ class ClickBox( val y = y.toFloat() val currentHeight = y + (height + clickboxHeightOffset) prepareDraw() - with(tessellator.begin(VertexFormat.Mode.TRIANGLE_FAN, DefaultVertexFormat.POSITION_COLOR)) { - // Render the header: - addVertex(x, y + height, 0.0F).colorEnd() - addVertex(x + width + inclination, y + height, 0.0F).colorEnd() - addVertex(x + width, y, 0.0F).colorEnd() - addVertex(x + inclination, y, 0.0F).colorEnd() + renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_TRIANGLE_FAN) { + with(it) { + // Render the header: + addVertex(x, y + height, 0.0F).colorEnd() + addVertex(x + width + inclination, y + height, 0.0F).colorEnd() + addVertex(x + width, y, 0.0F).colorEnd() + addVertex(x + inclination, y, 0.0F).colorEnd() - // Render the box: - addVertex(x, currentHeight, 0.0F).colorEnd() - addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd() - addVertex(x + width + inclination, y + height, 0.0F).colorEnd() - BufferUploader.drawWithShader(buildOrThrow()) + // Render the box: + addVertex(x, currentHeight, 0.0F).colorEnd() + addVertex(x + width + inclination, currentHeight, 0.0F).colorEnd() + addVertex(x + width + inclination, y + height, 0.0F).colorEnd() + } + } - colorShader() - with(tessellator.begin(VertexFormat.Mode.DEBUG_LINES, DefaultVertexFormat.POSITION_COLOR)) { + renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_LINE_STRIP) { + with(it) { + colorShader() addVertex(x + inclination, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) addVertex(x + width, y + height, 0.0F).colorEnd(Colors.WHITE_LINES.hexValue) - BufferUploader.drawWithShader(buildOrThrow()) } } endDraw() diff --git a/common/src/main/kotlin/fr/username404/snowygui/misc/createRenderPassRewrite.kt b/common/src/main/kotlin/fr/username404/snowygui/misc/createRenderPassRewrite.kt new file mode 100644 index 0000000..7e923ba --- /dev/null +++ b/common/src/main/kotlin/fr/username404/snowygui/misc/createRenderPassRewrite.kt @@ -0,0 +1,33 @@ +package fr.username404.snowygui.misc + +import com.mojang.blaze3d.opengl.GlStateManager +import com.mojang.blaze3d.textures.GpuTexture +import net.minecraft.util.ARGB +import org.lwjgl.opengl.GL11 +import java.util.* + +fun createRenderPassRewrite(framebufferId: Int, gpuTexture: GpuTexture, optionalInt: OptionalInt, gpuTexture2: GpuTexture?, optionalDouble: OptionalDouble) { + GlStateManager._glBindFramebuffer(36160, framebufferId) + var clearFlags = 0 + if (optionalInt.isPresent) { + val k: Int = optionalInt.getAsInt() + GL11.glClearColor(ARGB.redFloat(k), ARGB.greenFloat(k), ARGB.blueFloat(k), ARGB.alphaFloat(k)) + clearFlags = 16384 + } + + gpuTexture2?.run { + if (optionalDouble.isPresent) { + GL11.glClearDepth(optionalDouble.asDouble) + clearFlags = clearFlags or 256 + } + } + + if (clearFlags != 0) { + GlStateManager._disableScissorTest() + GlStateManager._depthMask(true) + GlStateManager._colorMask(true, true, true, true) + GlStateManager._clear(clearFlags) + } + + GlStateManager._viewport(0, 0, gpuTexture.getWidth(0), gpuTexture.getHeight(0)) +} \ No newline at end of file diff --git a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt index 325c43b..da30e20 100644 --- a/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt +++ b/common/src/main/kotlin/fr/username404/snowygui/utils/RenderingUtil.kt @@ -1,14 +1,21 @@ package fr.username404.snowygui.utils +import com.mojang.blaze3d.buffers.BufferType +import com.mojang.blaze3d.buffers.BufferUsage +import com.mojang.blaze3d.opengl.GlStateManager +import com.mojang.blaze3d.pipeline.RenderPipeline +import com.mojang.blaze3d.pipeline.RenderTarget +import com.mojang.blaze3d.systems.RenderPass import com.mojang.blaze3d.systems.RenderSystem -import com.mojang.blaze3d.vertex.BufferUploader -import com.mojang.blaze3d.vertex.DefaultVertexFormat +import com.mojang.blaze3d.vertex.BufferBuilder import com.mojang.blaze3d.vertex.Tesselator import com.mojang.blaze3d.vertex.VertexConsumer -import com.mojang.blaze3d.vertex.VertexFormat import fr.username404.snowygui.gui.feature.Colors import fr.username404.snowygui.gui.hextoRGB -import net.minecraft.client.renderer.CoreShaders +import net.minecraft.client.Minecraft +import net.minecraft.client.renderer.RenderPipelines +import java.util.OptionalInt +import java.util.OptionalDouble object RenderingUtil { @JvmField val tessellator: Tesselator = Tesselator.getInstance() @@ -17,27 +24,58 @@ object RenderingUtil { setColor(get(0), get(1), get(2), opacity) } fun colorShader() { - RenderSystem.setShader(CoreShaders.POSITION_COLOR) RenderSystem.setShaderColor(1F, 1F, 1F, 1F) } fun prepareDraw() { colorShader() - RenderSystem.enableBlend() - RenderSystem.defaultBlendFunc() + GlStateManager._enableBlend() } fun endDraw() { - RenderSystem.disableBlend() + GlStateManager._disableBlend() } fun drawRectangle( x: Double, y: Double, height: Int, width: Int, color: Int = Colors.TRANSPARENT(), opacity: Float = 1F - ): Unit = tessellator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR).run { + ): Unit = renderBufferWithPipeline(renderPipeline = RenderPipelines.DEBUG_QUADS) { buffer -> buffer.run { fun VertexConsumer.colorIt() = colorIt(color, opacity) val x = x.toFloat() ; val y = y.toFloat() addVertex(x, y + height, 0.0F).colorIt() addVertex(x + width, y + height, 0.0F).colorIt() addVertex(x + width, y, 0.0F).colorIt() addVertex(x, y, 0.0F).colorIt() - BufferUploader.drawWithShader(buildOrThrow()) + } } + + fun renderBufferWithPipeline( + name: String? = "Dynamic vertex buffer", + renderPipeline: RenderPipeline, + renderTarget: RenderTarget = Minecraft.getInstance().mainRenderTarget, + uniformAndSamplerConsumer: ((RenderPass) -> Unit)? = null, + bufferBuilderConsumer: (BufferBuilder) -> Unit, + ) { + val mode = renderPipeline.vertexFormatMode + val builder = Tesselator.getInstance().begin(mode, renderPipeline.vertexFormat) + bufferBuilderConsumer(builder) + builder.buildOrThrow().use { meshData -> + RenderSystem.getDevice().createCommandEncoder().createRenderPass( + renderTarget.colorTexture!!, + OptionalInt.empty(), + renderTarget.depthTexture, + OptionalDouble.empty() + ).use { renderPass -> + RenderSystem.getDevice().createBuffer( + { name }, BufferType.VERTICES, BufferUsage.DYNAMIC_WRITE, meshData.vertexBuffer() + ).use { buffer -> + val autoStorageIndexBuffer = RenderSystem.getSequentialBuffer(mode) + renderPass.setPipeline(renderPipeline) + renderPass.setVertexBuffer(0, buffer) + renderPass.setIndexBuffer( + autoStorageIndexBuffer.getBuffer(meshData.drawState().indexCount()), + autoStorageIndexBuffer.type() + ) + uniformAndSamplerConsumer?.invoke(renderPass) + renderPass.drawIndexed(0, meshData.drawState().indexCount()) + } + } + } } } diff --git a/fabric/src/main/resources/snowygui-fabric.mixins.json b/fabric/src/main/resources/snowygui-fabric.mixins.json index e4f15d8..2f93a94 100644 --- a/fabric/src/main/resources/snowygui-fabric.mixins.json +++ b/fabric/src/main/resources/snowygui-fabric.mixins.json @@ -3,6 +3,7 @@ "package": "fr.username404.snowygui.mixins", "compatibilityLevel": "JAVA_18", "client": [ + "CursedRenderPassMixin", "EndTickMixin", "TitleScreenMixin", "KeysAccessor", diff --git a/gradle.properties b/gradle.properties index 9ab16af..56e31d7 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,16 +7,16 @@ org.gradle.parallel=true org.gradle.unsafe.configuration-cache=on org.gradle.vfs.watch=true -minecraft=1.21.2 -forge_version=21.2.1-beta +minecraft=1.21.5 +forge_version=21.5.40-beta kotlinforforge=5.7.0 kotlinVer=2.1.0 kotlin_coroutines_version=1.9.0 serializationVer=1.7.3 fabric_loader_version=0.14.20 fabric_language_kotlin=1.13.0+kotlin.2.1.0 -fabric_resource_loader_version=3.0.5+c47b9d4373 -fabric_rendering_api_version=8.0.5+c47b9d4373 -fabric_api_base_version=0.4.48+c47b9d4373 -clothconfig_version=16.0.143 -modmenu_version=12.0.0 +fabric_resource_loader_version=3.1.6+02ca679607 +fabric_rendering_api_version=11.1.11+081cc04307 +fabric_api_base_version=0.4.62+73a52b4b07 +clothconfig_version=18.0.145 +modmenu_version=14.0.0-rc.2 diff --git a/neoforge/src/main/resources/snowygui-neoforge.mixins.json b/neoforge/src/main/resources/snowygui-neoforge.mixins.json index 74c07cf..775b8fc 100644 --- a/neoforge/src/main/resources/snowygui-neoforge.mixins.json +++ b/neoforge/src/main/resources/snowygui-neoforge.mixins.json @@ -2,7 +2,9 @@ "required": false, "package": "fr.username404.snowygui.mixins", "compatibilityLevel": "JAVA_21", - "client": [], + "client": [ + "CursedRenderPassMixin" + ], "injectors": { "defaultRequire": 1 },