aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/util/render/RenderInWorldContext.kt
diff options
context:
space:
mode:
authorJacob <55346310+Kathund@users.noreply.github.com>2025-08-12 07:27:04 +0800
committerGitHub <noreply@github.com>2025-08-12 01:27:04 +0200
commit98a080099683f9354ec4e02e47ff39b30caa8590 (patch)
treef6f2a2a4deaae6375ecd70c8f4276295f8dd1af3 /src/main/kotlin/util/render/RenderInWorldContext.kt
parent92fb76bb1811dde3bf8e9b1bee9789c8e12cc79c (diff)
downloadFirmament-98a080099683f9354ec4e02e47ff39b30caa8590.tar.gz
Firmament-98a080099683f9354ec4e02e47ff39b30caa8590.tar.bz2
Firmament-98a080099683f9354ec4e02e47ff39b30caa8590.zip
feat: block zapper overlay (#208)
Co-authored-by: Linnea Gräf <nea@nea.moe>
Diffstat (limited to 'src/main/kotlin/util/render/RenderInWorldContext.kt')
-rw-r--r--src/main/kotlin/util/render/RenderInWorldContext.kt115
1 files changed, 80 insertions, 35 deletions
diff --git a/src/main/kotlin/util/render/RenderInWorldContext.kt b/src/main/kotlin/util/render/RenderInWorldContext.kt
index 4963920..c30ee19 100644
--- a/src/main/kotlin/util/render/RenderInWorldContext.kt
+++ b/src/main/kotlin/util/render/RenderInWorldContext.kt
@@ -11,7 +11,6 @@ import net.minecraft.client.render.RenderLayer
import net.minecraft.client.render.RenderTickCounter
import net.minecraft.client.render.VertexConsumer
import net.minecraft.client.render.VertexConsumerProvider
-import net.minecraft.client.render.VertexFormats
import net.minecraft.client.texture.Sprite
import net.minecraft.client.util.math.MatrixStack
import net.minecraft.text.Text
@@ -20,7 +19,6 @@ import net.minecraft.util.math.BlockPos
import net.minecraft.util.math.Vec3d
import moe.nea.firmament.events.WorldRenderLastEvent
import moe.nea.firmament.util.FirmFormatters
-import moe.nea.firmament.util.IntUtil.toRGBA
import moe.nea.firmament.util.MC
@RenderContextDSL
@@ -49,6 +47,38 @@ class RenderInWorldContext private constructor(
matrixStack.pop()
}
+ fun sharedVoxelSurface(blocks: Set<BlockPos>, color: Int) {
+ val m = BlockPos.Mutable()
+ val l = vertexConsumers.getBuffer(CustomRenderLayers.COLORED_QUADS)
+ blocks.forEach {
+ matrixStack.push()
+ matrixStack.translate(it.x.toFloat(), it.y.toFloat(), it.z.toFloat())
+ val p = matrixStack.peek().positionMatrix
+ m.set(it)
+ if (m.setX(it.x + 1) !in blocks) {
+ buildFaceXP(p, l, color)
+ }
+ if (m.setX(it.x - 1) !in blocks) {
+ buildFaceXN(p, l, color)
+ }
+ m.set(it)
+ if (m.setY(it.y + 1) !in blocks) {
+ buildFaceYP(p, l, color)
+ }
+ if (m.setY(it.y - 1) !in blocks) {
+ buildFaceYN(p, l, color)
+ }
+ m.set(it)
+ if (m.setZ(it.z + 1) !in blocks) {
+ buildFaceZP(p, l, color)
+ }
+ if (m.setZ(it.z - 1) !in blocks) {
+ buildFaceZN(p, l, color)
+ }
+ matrixStack.pop()
+ }
+ }
+
enum class VerticalAlign {
TOP, BOTTOM, CENTER;
@@ -205,41 +235,56 @@ class RenderInWorldContext private constructor(
}
}
- private fun buildCube(matrix: Matrix4f, buf: VertexConsumer, colorInt: Int) {
- val (r, g, b, a) = colorInt.toRGBA()
-
- // Y-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- // Y+
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- // X-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- // X+
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
- // Z-
- buf.vertex(matrix, 0F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 0F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 0F).color(r, g, b, a)
- // Z+
- buf.vertex(matrix, 0F, 0F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 0F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 1F, 1F).color(r, g, b, a)
- buf.vertex(matrix, 1F, 0F, 1F).color(r, g, b, a)
+ private fun buildFaceZP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ }
+
+ private fun buildFaceZN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
+ }
+
+ private fun buildFaceXP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ }
+
+ private fun buildFaceXN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
}
+ private fun buildFaceYN(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 0F, 0F).color(rgba)
+ buf.vertex(matrix, 0F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 1F).color(rgba)
+ buf.vertex(matrix, 1F, 0F, 0F).color(rgba)
+ }
+
+ private fun buildFaceYP(matrix: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buf.vertex(matrix, 0F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 0F).color(rgba)
+ buf.vertex(matrix, 1F, 1F, 1F).color(rgba)
+ buf.vertex(matrix, 0F, 1F, 1F).color(rgba)
+ }
+
+ private fun buildCube(matrix4f: Matrix4f, buf: VertexConsumer, rgba: Int) {
+ buildFaceXP(matrix4f, buf, rgba)
+ buildFaceXN(matrix4f, buf, rgba)
+ buildFaceYP(matrix4f, buf, rgba)
+ buildFaceYN(matrix4f, buf, rgba)
+ buildFaceZP(matrix4f, buf, rgba)
+ buildFaceZN(matrix4f, buf, rgba)
+ }
fun renderInWorld(event: WorldRenderLastEvent, block: RenderInWorldContext. () -> Unit) {
// TODO: there should be *no more global state*. the only thing we should be doing is render layers. that includes settings like culling, blending, shader color, and depth testing