From 90da43ec499b1313634033cad48c53f79e39f533 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Sat, 31 Aug 2024 14:12:18 +0700 Subject: [PATCH] Use global buffer source --- .../mc/otm/android/AndroidActiveFeature.kt | 3 ++- .../mc/otm/android/feature/EnderTeleporterFeature.kt | 11 +++-------- .../mc/otm/client/AndroidAbilityKeyMapping.kt | 3 ++- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidActiveFeature.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidActiveFeature.kt index ff8d06398..0b18e6ebe 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidActiveFeature.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/AndroidActiveFeature.kt @@ -4,6 +4,7 @@ import com.mojang.blaze3d.vertex.PoseStack import net.minecraft.client.Camera import net.neoforged.neoforge.client.event.RenderLevelStageEvent import ru.dbotthepony.mc.otm.capability.MatteryPlayer +import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource abstract class AndroidActiveFeature(type: AndroidFeatureType<*>, android: MatteryPlayer) : AndroidSwitchableFeature(type, android) { /** @@ -22,5 +23,5 @@ abstract class AndroidActiveFeature(type: AndroidFeatureType<*>, android: Matter * * pose stack has pose pushed already */ - abstract fun renderPreview(poseStack: PoseStack, camera: Camera) + abstract fun renderPreview(poseStack: PoseStack, camera: Camera, bufferSource: DynamicBufferSource) } diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt index dd2b85ce3..c1cf82853 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/android/feature/EnderTeleporterFeature.kt @@ -8,7 +8,6 @@ import net.minecraft.core.BlockPos import net.minecraft.core.Direction import net.minecraft.core.Vec3i import net.minecraft.network.protocol.game.ClientboundSoundEntityPacket -import net.minecraft.resources.ResourceLocation import net.minecraft.server.level.ServerPlayer import net.minecraft.sounds.SoundEvents import net.minecraft.sounds.SoundSource @@ -323,7 +322,7 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A override val previewRenderStage: RenderLevelStageEvent.Stage get() = RenderLevelStageEvent.Stage.AFTER_PARTICLES - override fun renderPreview(poseStack: PoseStack, camera: Camera) { + override fun renderPreview(poseStack: PoseStack, camera: Camera, bufferSource: DynamicBufferSource) { if (!canUse()) return val (pos, phasedBlocks) = trace() @@ -350,7 +349,7 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A if (phasedBlocks.isNotEmpty()) { poseStack.popPose() val collisionContext = CollisionContext.of(ply) - val builder = source.getBuffer(linesIgnoreZRenderType) + val builder = bufferSource.getBuffer(linesIgnoreZRenderType) for (blockPos in phasedBlocks) { val blockState = ply.level().getBlockState(blockPos) @@ -367,7 +366,7 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A ) } - source.endBatch(linesIgnoreZRenderType) + bufferSource.endBatch(linesIgnoreZRenderType) } RenderSystem.enableDepthTest() @@ -387,10 +386,6 @@ class EnderTeleporterFeature(capability: MatteryPlayer) : AndroidActiveFeature(A } companion object { - private val source by lazy { - DynamicBufferSource(maximalInitialBufferSize = 256) - } - private val SHAPE_CHECK_NOT_FENCE = Block.box(6.0, 17.0, 6.0, 10.0, 31.0, 10.0) private val SHAPE_CHECK_SUPPORT_PLAYER = Block.box(6.0, 0.0, 6.0, 10.0, 16.0, 10.0) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidAbilityKeyMapping.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidAbilityKeyMapping.kt index 0d65f5591..e24de2183 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidAbilityKeyMapping.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/AndroidAbilityKeyMapping.kt @@ -14,6 +14,7 @@ import ru.dbotthepony.mc.otm.client.render.MGUIGraphics import ru.dbotthepony.mc.otm.client.render.Widgets18 import ru.dbotthepony.mc.otm.client.render.is3DContext import ru.dbotthepony.kommons.math.RGBAColor +import ru.dbotthepony.mc.otm.client.render.DynamicBufferSource import ru.dbotthepony.mc.otm.network.ActivateAndroidFeaturePacket import kotlin.math.roundToInt @@ -83,7 +84,7 @@ object AndroidAbilityKeyMapping : KeyMapping("key.otm.android_ability", KeyConfl try { is3DContext = true event.poseStack.pushPose() - feature.renderPreview(event.poseStack, event.camera) + feature.renderPreview(event.poseStack, event.camera, DynamicBufferSource.WORLD) } finally { is3DContext = false event.poseStack.popPose()