diff options
author | nea <romangraef@gmail.com> | 2022-09-28 12:45:56 +0200 |
---|---|---|
committer | nea <romangraef@gmail.com> | 2022-09-28 12:45:56 +0200 |
commit | 4d73331a449f0b0647066f7dde0628730fe0e178 (patch) | |
tree | 047f463e13d14ea6cf9c8b37602a756f6880f9a0 /src/main/kotlin/moe/nea/notenoughupdates/util/render | |
parent | ec66c82198fe2d61d699d553c1254f08b43fcc65 (diff) | |
download | firmament-4d73331a449f0b0647066f7dde0628730fe0e178.tar.gz firmament-4d73331a449f0b0647066f7dde0628730fe0e178.tar.bz2 firmament-4d73331a449f0b0647066f7dde0628730fe0e178.zip |
Fairy souls
Diffstat (limited to 'src/main/kotlin/moe/nea/notenoughupdates/util/render')
-rw-r--r-- | src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt b/src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt new file mode 100644 index 0000000..9b5432a --- /dev/null +++ b/src/main/kotlin/moe/nea/notenoughupdates/util/render/block.kt @@ -0,0 +1,91 @@ +package moe.nea.notenoughupdates.util.render + +import com.mojang.blaze3d.systems.RenderSystem +import net.minecraft.client.gl.VertexBuffer +import net.minecraft.client.render.BufferBuilder +import net.minecraft.client.render.Camera +import net.minecraft.client.render.GameRenderer +import net.minecraft.client.render.Tessellator +import net.minecraft.client.render.VertexFormat +import net.minecraft.client.render.VertexFormats +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d + +class RenderBlockContext(val tesselator: Tessellator, val camPos: Vec3d) { + val buffer = tesselator.buffer + fun color(red: Float, green: Float, blue: Float, alpha: Float) { + RenderSystem.setShaderColor(red, green, blue, alpha) + } + + fun block(blockPos: BlockPos) { + val matrixStack = RenderSystem.getModelViewStack() + matrixStack.push() + matrixStack.translate(blockPos.x - camPos.x, blockPos.y - camPos.y, blockPos.z - camPos.z) + RenderSystem.applyModelViewMatrix() + RenderSystem.setShader(GameRenderer::getPositionColorShader) + buildCube(buffer) + tesselator.draw() + matrixStack.pop() + } + + companion object { + fun buildCube(buf: BufferBuilder) { + buf.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) + buf.fixedColor(255, 255, 255, 255) + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(0.0, 0.0, 1.0).next() + buf.vertex(0.0, 1.0, 1.0).next() + buf.vertex(1.0, 1.0, 0.0).next() + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(0.0, 1.0, 0.0).next() + buf.vertex(1.0, 0.0, 1.0).next() + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(1.0, 0.0, 0.0).next() + buf.vertex(1.0, 1.0, 0.0).next() + buf.vertex(1.0, 0.0, 0.0).next() + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(0.0, 1.0, 1.0).next() + buf.vertex(0.0, 1.0, 0.0).next() + buf.vertex(1.0, 0.0, 1.0).next() + buf.vertex(0.0, 0.0, 1.0).next() + buf.vertex(0.0, 0.0, 0.0).next() + buf.vertex(0.0, 1.0, 1.0).next() + buf.vertex(0.0, 0.0, 1.0).next() + buf.vertex(1.0, 0.0, 1.0).next() + buf.vertex(1.0, 1.0, 1.0).next() + buf.vertex(1.0, 0.0, 0.0).next() + buf.vertex(1.0, 1.0, 0.0).next() + buf.vertex(1.0, 0.0, 0.0).next() + buf.vertex(1.0, 1.0, 1.0).next() + buf.vertex(1.0, 0.0, 1.0).next() + buf.vertex(1.0, 1.0, 1.0).next() + buf.vertex(1.0, 1.0, 0.0).next() + buf.vertex(0.0, 1.0, 0.0).next() + buf.vertex(1.0, 1.0, 1.0).next() + buf.vertex(0.0, 1.0, 0.0).next() + buf.vertex(0.0, 1.0, 1.0).next() + buf.vertex(1.0, 1.0, 1.0).next() + buf.vertex(0.0, 1.0, 1.0).next() + buf.vertex(1.0, 0.0, 1.0).next() + buf.unfixColor() + } + + fun renderBlocks(camera: Camera, block: RenderBlockContext. () -> Unit) { + RenderSystem.disableDepthTest() + RenderSystem.disableTexture() + RenderSystem.enableBlend() + RenderSystem.defaultBlendFunc() + + val ctx = RenderBlockContext(Tessellator.getInstance(), camera.pos) + block(ctx) + + VertexBuffer.unbind() + RenderSystem.enableDepthTest() + RenderSystem.enableTexture() + RenderSystem.disableBlend() + } + } +} + + |