diff options
author | Linnea Gräf <nea@nea.moe> | 2024-07-05 22:17:02 +0200 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-07-05 22:17:02 +0200 |
commit | 3d792dbef7c7e0f186e29f2e3999f99c2c14f5d7 (patch) | |
tree | b383c2c584a96b93c46d1dae3efcd3c6571e3d05 /src/main/kotlin/moe/nea/firmament/util/render | |
parent | 5ee4b8d925eb12e068038a1fd2e1f35cdd8ef87e (diff) | |
download | firmament-3d792dbef7c7e0f186e29f2e3999f99c2c14f5d7.tar.gz firmament-3d792dbef7c7e0f186e29f2e3999f99c2c14f5d7.tar.bz2 firmament-3d792dbef7c7e0f186e29f2e3999f99c2c14f5d7.zip |
Port to 1.21
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/render')
3 files changed, 32 insertions, 36 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt index 178422d..01a7083 100644 --- a/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt +++ b/src/main/kotlin/moe/nea/firmament/util/render/FacingThePlayerContext.kt @@ -7,6 +7,7 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem +import io.github.notenoughupdates.moulconfig.platform.next import org.joml.Matrix4f import net.minecraft.client.font.TextRenderer import net.minecraft.client.render.BufferRenderer @@ -80,22 +81,24 @@ class FacingThePlayerContext(val worldContext: RenderInWorldContext) { u2: Float, v2: Float, ) { RenderSystem.setShaderTexture(0, texture) - RenderSystem.setShader(GameRenderer::getPositionColorTexProgram) + RenderSystem.setShader(GameRenderer::getPositionTexColorProgram) val hw = width / 2F val hh = height / 2F val matrix4f: Matrix4f = worldContext.matrixStack.peek().positionMatrix - val buf = Tessellator.getInstance().buffer - buf.begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_COLOR_TEXTURE) - buf.fixedColor(255, 255, 255, 255) + val buf = Tessellator.getInstance() + .begin(VertexFormat.DrawMode.QUADS, VertexFormats.POSITION_TEXTURE_COLOR) buf.vertex(matrix4f, -hw, -hh, 0F) + .color(-1) .texture(u1, v1).next() buf.vertex(matrix4f, -hw, +hh, 0F) + .color(-1) .texture(u1, v2).next() buf.vertex(matrix4f, +hw, +hh, 0F) + .color(-1) .texture(u2, v2).next() buf.vertex(matrix4f, +hw, -hh, 0F) + .color(-1) .texture(u2, v1).next() - buf.unfixColor() BufferRenderer.drawWithGlobalProgram(buf.end()) } diff --git a/src/main/kotlin/moe/nea/firmament/util/render/RenderCircleProgress.kt b/src/main/kotlin/moe/nea/firmament/util/render/RenderCircleProgress.kt index a8245ca..28dcb5e 100644 --- a/src/main/kotlin/moe/nea/firmament/util/render/RenderCircleProgress.kt +++ b/src/main/kotlin/moe/nea/firmament/util/render/RenderCircleProgress.kt @@ -7,6 +7,7 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem +import io.github.notenoughupdates.moulconfig.platform.next import org.joml.Matrix4f import org.joml.Vector2f import kotlin.math.atan2 @@ -31,12 +32,10 @@ object RenderCircleProgress { v2: Float, ) { RenderSystem.setShaderTexture(0, texture) - RenderSystem.setShader { GameRenderer.getPositionColorTexProgram() } + RenderSystem.setShader(GameRenderer::getPositionTexColorProgram) RenderSystem.enableBlend() val matrix: Matrix4f = drawContext.matrices.peek().positionMatrix - val bufferBuilder = Tessellator.getInstance().buffer - bufferBuilder.begin(DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR_TEXTURE) - bufferBuilder.fixedColor(255, 255, 255, 255) + val bufferBuilder = Tessellator.getInstance().begin(DrawMode.TRIANGLES, VertexFormats.POSITION_TEXTURE_COLOR) val corners = listOf( Vector2f(0F, -1F), @@ -79,17 +78,19 @@ object RenderCircleProgress { bufferBuilder .vertex(matrix, second.x, second.y, 0F) .texture(lerp(u1, u2, ilerp(second.x)), lerp(v1, v2, ilerp(second.y))) + .color(-1) .next() bufferBuilder .vertex(matrix, first.x, first.y, 0F) .texture(lerp(u1, u2, ilerp(first.x)), lerp(v1, v2, ilerp(first.y))) + .color(-1) .next() bufferBuilder .vertex(matrix, 0F, 0F, 0F) .texture(lerp(u1, u2, ilerp(0F)), lerp(v1, v2, ilerp(0F))) + .color(-1) .next() } - bufferBuilder.unfixColor() BufferRenderer.drawWithGlobalProgram(bufferBuilder.end()) RenderSystem.disableBlend() } diff --git a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt index 750d8ac..2db4cad 100644 --- a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt +++ b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt @@ -8,15 +8,16 @@ package moe.nea.firmament.util.render import com.mojang.blaze3d.systems.RenderSystem +import io.github.notenoughupdates.moulconfig.platform.next import java.lang.Math.pow -import java.lang.Math.toRadians import org.joml.Matrix4f import org.joml.Vector3f -import kotlin.math.tan import net.minecraft.client.gl.VertexBuffer import net.minecraft.client.render.BufferBuilder +import net.minecraft.client.render.BufferRenderer import net.minecraft.client.render.Camera import net.minecraft.client.render.GameRenderer +import net.minecraft.client.render.RenderTickCounter import net.minecraft.client.render.Tessellator import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.VertexFormat @@ -28,7 +29,6 @@ import net.minecraft.util.Identifier import net.minecraft.util.math.BlockPos import net.minecraft.util.math.Vec3d import moe.nea.firmament.events.WorldRenderLastEvent -import moe.nea.firmament.mixins.accessor.AccessorGameRenderer import moe.nea.firmament.util.FirmFormatters import moe.nea.firmament.util.MC @@ -37,12 +37,9 @@ class RenderInWorldContext private constructor( private val tesselator: Tessellator, val matrixStack: MatrixStack, private val camera: Camera, - private val tickDelta: Float, + private val tickCounter: RenderTickCounter, val vertexConsumers: VertexConsumerProvider.Immediate, ) { - private val buffer = tesselator.buffer - val effectiveFov = (MC.instance.gameRenderer as AccessorGameRenderer).getFov_firmament(camera, tickDelta, true) - val effectiveFovScaleFactor = 1 / tan(toRadians(effectiveFov) / 2) fun color(color: me.shedaniel.math.Color) { color(color.red / 255F, color.green / 255f, color.blue / 255f, color.alpha / 255f) @@ -56,8 +53,7 @@ class RenderInWorldContext private constructor( RenderSystem.setShader(GameRenderer::getPositionColorProgram) matrixStack.push() matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) - buildCube(matrixStack.peek().positionMatrix, buffer) - tesselator.draw() + buildCube(matrixStack.peek().positionMatrix, tesselator) matrixStack.pop() } @@ -125,8 +121,7 @@ class RenderInWorldContext private constructor( matrixStack.translate(vec3d.x, vec3d.y, vec3d.z) matrixStack.scale(size, size, size) matrixStack.translate(-.5, -.5, -.5) - buildCube(matrixStack.peek().positionMatrix, buffer) - tesselator.draw() + buildCube(matrixStack.peek().positionMatrix, tesselator) matrixStack.pop() } @@ -135,8 +130,7 @@ class RenderInWorldContext private constructor( matrixStack.push() RenderSystem.lineWidth(lineWidth / pow(camera.pos.squaredDistanceTo(blockPos.toCenterPos()), 0.25).toFloat()) matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) - buildWireFrameCube(matrixStack.peek(), buffer) - tesselator.draw() + buildWireFrameCube(matrixStack.peek(), tesselator) matrixStack.pop() } @@ -152,8 +146,7 @@ class RenderInWorldContext private constructor( fun line(points: List<Vec3d>, lineWidth: Float = 10F) { RenderSystem.setShader(GameRenderer::getRenderTypeLinesProgram) RenderSystem.lineWidth(lineWidth) - buffer.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) - buffer.fixedColor(255, 255, 255, 255) + val buffer = tesselator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) val matrix = matrixStack.peek() var lastNormal: Vector3f? = null @@ -170,9 +163,8 @@ class RenderInWorldContext private constructor( .normal(matrix, normal.x, normal.y, normal.z) .next() } - buffer.unfixColor() - tesselator.draw() + BufferRenderer.drawWithGlobalProgram(buffer.end()) } companion object { @@ -191,16 +183,17 @@ class RenderInWorldContext private constructor( .normalize() buf.vertex(matrix.positionMatrix, i, j, k) .normal(matrix, normal.x, normal.y, normal.z) + .color(-1) .next() buf.vertex(matrix.positionMatrix, x, y, z) .normal(matrix, normal.x, normal.y, normal.z) + .color(-1) .next() } - private fun buildWireFrameCube(matrix: MatrixStack.Entry, buf: BufferBuilder) { - buf.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) - buf.fixedColor(255, 255, 255, 255) + private fun buildWireFrameCube(matrix: MatrixStack.Entry, tessellator: Tessellator) { + val buf = tessellator.begin(VertexFormat.DrawMode.LINES, VertexFormats.LINES) for (i in 0..1) { for (j in 0..1) { @@ -211,12 +204,11 @@ class RenderInWorldContext private constructor( doLine(matrix, buf, i, j, 0F, i, j, 1F) } } - buf.unfixColor() + BufferRenderer.drawWithGlobalProgram(buf.end()) } - private fun buildCube(matrix: Matrix4f, buf: BufferBuilder) { - buf.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) - buf.fixedColor(255, 255, 255, 255) + private fun buildCube(matrix: Matrix4f, tessellator: Tessellator) { + val buf = tessellator.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION) buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() buf.vertex(matrix, 0.0F, 0.0F, 1.0F).next() buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() @@ -253,7 +245,7 @@ class RenderInWorldContext private constructor( buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() - buf.unfixColor() + BufferRenderer.drawWithGlobalProgram(buf.end()) } @@ -270,7 +262,7 @@ class RenderInWorldContext private constructor( RenderSystem.renderThreadTesselator(), event.matrices, event.camera, - event.tickDelta, + event.tickCounter, event.vertexConsumers ) |