diff options
Diffstat (limited to 'src/main/kotlin/features/misc')
| -rw-r--r-- | src/main/kotlin/features/misc/CustomCapes.kt | 65 | ||||
| -rw-r--r-- | src/main/kotlin/features/misc/Hud.kt | 19 |
2 files changed, 44 insertions, 40 deletions
diff --git a/src/main/kotlin/features/misc/CustomCapes.kt b/src/main/kotlin/features/misc/CustomCapes.kt index dc5187a..77a5c2d 100644 --- a/src/main/kotlin/features/misc/CustomCapes.kt +++ b/src/main/kotlin/features/misc/CustomCapes.kt @@ -1,8 +1,13 @@ package moe.nea.firmament.features.misc +import com.mojang.blaze3d.buffers.GpuBuffer +import com.mojang.blaze3d.buffers.Std140Builder import com.mojang.blaze3d.systems.RenderSystem +import java.nio.ByteBuffer +import java.nio.ByteOrder import java.util.OptionalDouble import java.util.OptionalInt +import org.joml.Vector4f import util.render.CustomRenderPipelines import kotlin.time.Duration import kotlin.time.Duration.Companion.seconds @@ -14,12 +19,14 @@ import net.minecraft.client.render.VertexConsumerProvider import net.minecraft.client.render.entity.state.PlayerEntityRenderState import net.minecraft.client.util.BufferAllocator import net.minecraft.client.util.SkinTextures +import net.minecraft.client.util.math.MatrixStack import net.minecraft.util.Identifier import moe.nea.firmament.Firmament 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.mc.CustomRenderPassHelper object CustomCapes : FirmamentFeature { override val identifier: String @@ -36,6 +43,7 @@ object CustomCapes : FirmamentFeature { fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) } @@ -46,6 +54,7 @@ object CustomCapes : FirmamentFeature { override fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) { model(vertexConsumerProvider.getBuffer(RenderLayer.getEntitySolid(location))) @@ -61,37 +70,27 @@ object CustomCapes : FirmamentFeature { override fun replaceRender( renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) { - BufferAllocator(2048).use { allocator -> - val bufferBuilder = BufferBuilder(allocator, renderLayer.drawMode, renderLayer.vertexFormat) - model(bufferBuilder) - bufferBuilder.end().use { buffer -> - val commandEncoder = RenderSystem.getDevice().createCommandEncoder() - val vertexBuffer = renderLayer.vertexFormat.uploadImmediateVertexBuffer(buffer.buffer) - val indexBufferConstructor = RenderSystem.getSequentialBuffer(renderLayer.drawMode) - val indexBuffer = indexBufferConstructor.getIndexBuffer(buffer.drawParameters.indexCount) - val templateTexture = MC.textureManager.getTexture(template) - val backgroundTexture = MC.textureManager.getTexture(background) - val foregroundTexture = MC.textureManager.getTexture(overlay) - commandEncoder.createRenderPass( - MC.instance.framebuffer.colorAttachment, - OptionalInt.empty(), - MC.instance.framebuffer.depthAttachment, - OptionalDouble.empty(), - ).use { renderPass -> - // TODO: account for lighting - renderPass.setPipeline(CustomRenderPipelines.PARALLAX_CAPE_SHADER) - renderPass.bindSampler("Sampler0", templateTexture.glTexture) - renderPass.bindSampler("Sampler1", backgroundTexture.glTexture) - renderPass.bindSampler("Sampler3", foregroundTexture.glTexture) - val animationValue = (startTime.passedTime() / animationSpeed).mod(1F) - renderPass.setUniform("Animation", animationValue.toFloat()) - renderPass.setIndexBuffer(indexBuffer, indexBufferConstructor.indexType) - renderPass.setVertexBuffer(0, vertexBuffer) - renderPass.drawIndexed(0, buffer.drawParameters.indexCount) - } + val animationValue = (startTime.passedTime() / animationSpeed).mod(1F) + CustomRenderPassHelper( + { "Firmament Cape Renderer" }, + renderLayer.drawMode, + renderLayer.vertexFormat, + MC.instance.framebuffer, + true, + ).use { renderPass -> + renderPass.setPipeline(CustomRenderPipelines.PARALLAX_CAPE_SHADER) + renderPass.setAllDefaultUniforms() + renderPass.setUniform("Animation", 4) { + it.putFloat(animationValue.toFloat()) } + renderPass.bindSampler("Sampler0", template) + renderPass.bindSampler("Sampler1", background) + renderPass.bindSampler("Sampler3", overlay) + renderPass.uploadVertices(2048, model) + renderPass.draw() } } } @@ -122,7 +121,10 @@ object CustomCapes : FirmamentFeature { 110.seconds ) ), - + UNPLEASANT_GRADIENT( + "unpleasant_gradient", + TexturedCapeRenderer(Firmament.identifier("textures/cape/unpleasant_gradient.png")) + ), FURFSKY_STATIC( "FurfSky", TexturedCapeRenderer(Firmament.identifier("textures/cape/fsr_static.png")) @@ -141,7 +143,7 @@ object CustomCapes : FirmamentFeature { val byUuid = listOf( listOf( - Devs.nea to AllCapes.FIRMAMENT_ANIMATED, + Devs.nea to AllCapes.UNPLEASANT_GRADIENT, Devs.kath to AllCapes.FIRMAMENT_STATIC, Devs.jani to AllCapes.FIRMAMENT_ANIMATED, ), @@ -154,12 +156,13 @@ object CustomCapes : FirmamentFeature { vertexConsumer: VertexConsumer, renderLayer: RenderLayer, vertexConsumerProvider: VertexConsumerProvider, + matrixStack: MatrixStack, model: (VertexConsumer) -> Unit ) { val capeStorage = CapeStorage.cast(playerEntityRenderState) val firmCape = capeStorage.cape_firmament if (firmCape != null) { - firmCape.render.replaceRender(renderLayer, vertexConsumerProvider, model) + firmCape.render.replaceRender(renderLayer, vertexConsumerProvider, matrixStack, model) } else { model(vertexConsumer) } diff --git a/src/main/kotlin/features/misc/Hud.kt b/src/main/kotlin/features/misc/Hud.kt index 9661fc5..8c785ab 100644 --- a/src/main/kotlin/features/misc/Hud.kt +++ b/src/main/kotlin/features/misc/Hud.kt @@ -7,6 +7,7 @@ import moe.nea.firmament.gui.config.ManagedConfig import moe.nea.firmament.util.MC import moe.nea.firmament.util.tr import moe.nea.jarvis.api.Point +import org.joml.Vector2i import net.minecraft.client.network.PlayerListEntry import net.minecraft.text.Text @@ -16,11 +17,11 @@ object Hud : FirmamentFeature { object TConfig : ManagedConfig(identifier, Category.MISC) { var dayCount by toggle("day-count") { false } - val dayCountHud by position("day-count-hud", 80, 10) { Point(0.5, 0.8) } + val dayCountHud by position("day-count-hud", 80, 10) { Vector2i() } var fpsCount by toggle("fps-count") { false } - val fpsCountHud by position("fps-count-hud", 80, 10) { Point(0.5, 0.9) } + val fpsCountHud by position("fps-count-hud", 80, 10) { Vector2i() } var pingCount by toggle("ping-count") { false } - val pingCountHud by position("ping-count-hud", 80, 10) { Point(0.5, 1.0) } + val pingCountHud by position("ping-count-hud", 80, 10) { Vector2i() } } override val config: ManagedConfig @@ -29,7 +30,7 @@ object Hud : FirmamentFeature { @Subscribe fun onRenderHud(it: HudRenderEvent) { if (TConfig.dayCount) { - it.context.matrices.push() + it.context.matrices.pushMatrix() TConfig.dayCountHud.applyTransformations(it.context.matrices) val day = (MC.world?.timeOfDay ?: 0L) / 24000 it.context.drawText( @@ -40,11 +41,11 @@ object Hud : FirmamentFeature { -1, true ) - it.context.matrices.pop() + it.context.matrices.popMatrix() } if (TConfig.fpsCount) { - it.context.matrices.push() + it.context.matrices.pushMatrix() TConfig.fpsCountHud.applyTransformations(it.context.matrices) it.context.drawText( MC.font, Text.literal( @@ -53,11 +54,11 @@ object Hud : FirmamentFeature { ) ), 36, MC.font.fontHeight, -1, true ) - it.context.matrices.pop() + it.context.matrices.popMatrix() } if (TConfig.pingCount) { - it.context.matrices.push() + it.context.matrices.pushMatrix() TConfig.pingCountHud.applyTransformations(it.context.matrices) val ping = MC.player?.let { val entry: PlayerListEntry? = MC.networkHandler?.getPlayerListEntry(it.uuid) @@ -71,7 +72,7 @@ object Hud : FirmamentFeature { ), 36, MC.font.fontHeight, -1, true ) - it.context.matrices.pop() + it.context.matrices.popMatrix() } } } |
