From 74e79759bf8888ea08a6d244a50e531aaae20f27 Mon Sep 17 00:00:00 2001 From: nea Date: Sun, 11 Jun 2023 22:35:03 +0200 Subject: Rename world renderer events --- .../firmament/features/fishing/FishingWarning.kt | 6 +- .../moe/nea/firmament/features/world/FairySouls.kt | 4 +- .../firmament/util/render/RenderInWorldContext.kt | 128 ++++++++++++++++++++ .../kotlin/moe/nea/firmament/util/render/block.kt | 130 --------------------- 4 files changed, 132 insertions(+), 136 deletions(-) create mode 100644 src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt delete mode 100644 src/main/kotlin/moe/nea/firmament/util/render/block.kt (limited to 'src/main/kotlin/moe/nea') diff --git a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt index 24e31ea..fa8d779 100644 --- a/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt +++ b/src/main/kotlin/moe/nea/firmament/features/fishing/FishingWarning.kt @@ -25,8 +25,6 @@ import kotlin.math.asin import kotlin.math.atan2 import kotlin.math.sqrt import kotlin.time.Duration.Companion.seconds -import net.minecraft.client.render.VertexConsumerProvider -import net.minecraft.client.render.VertexConsumers import net.minecraft.entity.projectile.FishingBobberEntity import net.minecraft.particle.ParticleTypes import net.minecraft.util.math.Vec3d @@ -37,7 +35,7 @@ import moe.nea.firmament.features.FirmamentFeature import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.TimeMark -import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks +import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld object FishingWarning : FirmamentFeature { override val name: String @@ -139,7 +137,7 @@ object FishingWarning : FirmamentFeature { WorldRenderLastEvent.subscribe { recentParticles.removeIf { it.second.passedTime() > 5.seconds } recentCandidates.removeIf { it.timeMark.passedTime() > 5.seconds } - renderBlocks(it.matrices, it.camera) { + renderInWorld(it.matrices, it.camera) { color(0f, 0f, 1f, 1f) recentParticles.forEach { tinyBlock(it.first, 0.1F) diff --git a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt index 318365c..9a04b37 100644 --- a/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt +++ b/src/main/kotlin/moe/nea/firmament/features/world/FairySouls.kt @@ -31,7 +31,7 @@ import moe.nea.firmament.util.SBData import moe.nea.firmament.util.blockPos import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.data.ProfileSpecificDataHolder -import moe.nea.firmament.util.render.RenderBlockContext.Companion.renderBlocks +import moe.nea.firmament.util.render.RenderInWorldContext.Companion.renderInWorld import moe.nea.firmament.util.unformattedString @@ -127,7 +127,7 @@ object FairySouls : FirmamentFeature { } WorldRenderLastEvent.subscribe { if (!TConfig.displaySouls) return@subscribe - renderBlocks(it.matrices, it.camera) { + renderInWorld(it.matrices, it.camera) { color(1F, 1F, 0F, 0.8F) currentMissingSouls.forEach { block(it.blockPos) diff --git a/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt new file mode 100644 index 0000000..59a949a --- /dev/null +++ b/src/main/kotlin/moe/nea/firmament/util/render/RenderInWorldContext.kt @@ -0,0 +1,128 @@ +/* + * Firmament is a Hypixel Skyblock mod for modern Minecraft versions + * Copyright (C) 2023 Linnea Gräf + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package moe.nea.firmament.util.render + +import com.mojang.blaze3d.systems.RenderSystem +import org.joml.Matrix4f +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.client.util.math.MatrixStack +import net.minecraft.util.math.BlockPos +import net.minecraft.util.math.Vec3d + +class RenderInWorldContext private constructor(private val tesselator: Tessellator, private val matrixStack: MatrixStack) { + private val buffer = tesselator.buffer + + fun color(red: Float, green: Float, blue: Float, alpha: Float) { + RenderSystem.setShaderColor(red, green, blue, alpha) + } + + fun block(blockPos: BlockPos) { + matrixStack.push() + matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) + buildCube(matrixStack.peek().positionMatrix, buffer) + tesselator.draw() + matrixStack.pop() + } + + fun tinyBlock(vec3d: Vec3d, size: Float) { + matrixStack.push() + 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() + matrixStack.pop() + } + + fun line(vararg points: Vec3d, size: Double = 2.0) { + + } + + companion object { + private fun buildCube(matrix: Matrix4f, buf: BufferBuilder) { + buf.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) + buf.fixedColor(255, 255, 255, 255) + 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() + buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() + buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() + 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() + } + + fun renderInWorld(matrices: MatrixStack, camera: Camera, block: RenderInWorldContext. () -> Unit) { + RenderSystem.disableDepthTest() + RenderSystem.enableBlend() + RenderSystem.defaultBlendFunc() + RenderSystem.setShader(GameRenderer::getPositionColorProgram) + + matrices.push() + matrices.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z) + + val ctx = RenderInWorldContext(Tessellator.getInstance(), matrices) + block(ctx) + + matrices.pop() + + RenderSystem.setShaderColor(1F,1F,1F,1F) + VertexBuffer.unbind() + RenderSystem.enableDepthTest() + RenderSystem.disableBlend() + } + } +} + + diff --git a/src/main/kotlin/moe/nea/firmament/util/render/block.kt b/src/main/kotlin/moe/nea/firmament/util/render/block.kt deleted file mode 100644 index 7df610b..0000000 --- a/src/main/kotlin/moe/nea/firmament/util/render/block.kt +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Firmament is a Hypixel Skyblock mod for modern Minecraft versions - * Copyright (C) 2023 Linnea Gräf - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -package moe.nea.firmament.util.render - -import com.mojang.blaze3d.systems.RenderSystem -import org.joml.Matrix4f -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.RenderLayer -import net.minecraft.client.render.Tessellator -import net.minecraft.client.render.VertexConsumerProvider -import net.minecraft.client.render.VertexFormat -import net.minecraft.client.render.VertexFormats -import net.minecraft.client.util.math.MatrixStack -import net.minecraft.util.math.BlockPos -import net.minecraft.util.math.Vec3d - -class RenderBlockContext private constructor(private val tesselator: Tessellator, private val matrixStack: MatrixStack) { - private val buffer = tesselator.buffer - - fun color(red: Float, green: Float, blue: Float, alpha: Float) { - RenderSystem.setShaderColor(red, green, blue, alpha) - } - - fun block(blockPos: BlockPos) { - matrixStack.push() - matrixStack.translate(blockPos.x.toFloat(), blockPos.y.toFloat(), blockPos.z.toFloat()) - buildCube(matrixStack.peek().positionMatrix, buffer) - tesselator.draw() - matrixStack.pop() - } - - fun tinyBlock(vec3d: Vec3d, size: Float) { - matrixStack.push() - 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() - matrixStack.pop() - } - - fun line(vararg points: Vec3d, size: Double = 2.0) { - - } - - companion object { - private fun buildCube(matrix: Matrix4f, buf: BufferBuilder) { - buf.begin(VertexFormat.DrawMode.TRIANGLES, VertexFormats.POSITION_COLOR) - buf.fixedColor(255, 255, 255, 255) - 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() - buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 0.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 1.0F, 1.0F, 1.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 0.0F).next() - buf.vertex(matrix, 0.0F, 1.0F, 1.0F).next() - 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() - } - - fun renderBlocks(matrices: MatrixStack, camera: Camera, block: RenderBlockContext. () -> Unit) { - RenderSystem.disableDepthTest() - RenderSystem.enableBlend() - RenderSystem.defaultBlendFunc() - RenderSystem.setShader(GameRenderer::getPositionColorProgram) - - matrices.push() - matrices.translate(-camera.pos.x, -camera.pos.y, -camera.pos.z) - - val ctx = RenderBlockContext(Tessellator.getInstance(), matrices) - block(ctx) - - matrices.pop() - - RenderSystem.setShaderColor(1F,1F,1F,1F) - VertexBuffer.unbind() - RenderSystem.enableDepthTest() - RenderSystem.disableBlend() - } - } -} - - -- cgit