From ba5d3a404386a33bc8919352e7016139cd965159 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Fri, 21 Feb 2025 19:38:26 +0700 Subject: [PATCH] Someplace i don't fucking know --- .../entity/blackhole/BlackHoleBlockEntity.kt | 30 ++++++++++++++----- .../otm/client/sound/BlackHoleAmbientSound.kt | 4 +-- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt index 022ea1ecd..25e5efc70 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/block/entity/blackhole/BlackHoleBlockEntity.kt @@ -48,10 +48,12 @@ import ru.dbotthepony.mc.otm.isClient import ru.dbotthepony.mc.otm.matter.MatterManager import ru.dbotthepony.mc.otm.registry.MDamageTypes import ru.dbotthepony.mc.otm.registry.MatteryDamageSource +import ru.dbotthepony.mc.otm.runIfClient import ru.dbotthepony.mc.otm.triggers.BlackHoleTrigger import kotlin.math.pow import kotlin.math.roundToInt import kotlin.math.sqrt +import kotlin.properties.Delegates class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : MatteryBlockEntity(MBlockEntities.BLACK_HOLE, p_155229_, p_155230_) { var mass by syncher.decimal(ServerConfig.Blackhole.BASELINE_MASS, setter = setter@{ field, mass -> @@ -174,7 +176,27 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mattery } } + private var ambientSound: BlackHoleAmbientSoundInstance? = null + + private fun stopSound() { + minecraft.soundManager.stop(ambientSound!!) + ambientSound = null + } + + override fun setRemoved() { + super.setRemoved() + + if (ambientSound != null) { + stopSound() + } + } + fun clientTick() { + if (ambientSound == null) { + ambientSound = BlackHoleAmbientSoundInstance(this) + minecraft.soundManager.play(ambientSound!!) + } + if (--sleepTicks > 0) return val ply = Minecraft.getInstance().player ?: return val center = Vec3.atCenterOf(blockPos) @@ -310,14 +332,6 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mattery } } - private val ambientSound: BlackHoleAmbientSoundInstance - @OnlyIn(Dist.CLIENT) - get() = BlackHoleAmbientSoundInstance(this) - - init { - if (isClient) minecraft.soundManager.play(ambientSound) - } - companion object { const val ITERATIONS = 30_000 val HAWKING_MASS_LOSE_STEP = Decimal(-100) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/client/sound/BlackHoleAmbientSound.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/client/sound/BlackHoleAmbientSound.kt index 3a3077151..438bee519 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/client/sound/BlackHoleAmbientSound.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/sound/BlackHoleAmbientSound.kt @@ -9,9 +9,7 @@ import net.neoforged.api.distmarker.OnlyIn import ru.dbotthepony.mc.otm.block.entity.blackhole.BlackHoleBlockEntity import ru.dbotthepony.mc.otm.registry.game.MSoundEvents -@OnlyIn(Dist.CLIENT) -class BlackHoleAmbientSoundInstance(val tile: BlackHoleBlockEntity) - : AbstractSoundInstance(MSoundEvents.BLACK_HOLE, SoundSource.AMBIENT, SoundInstance.createUnseededRandom()) { +class BlackHoleAmbientSoundInstance(val tile: BlackHoleBlockEntity) : AbstractSoundInstance(MSoundEvents.BLACK_HOLE, SoundSource.AMBIENT, SoundInstance.createUnseededRandom()) { private val center = Vec3.atCenterOf(tile.blockPos) init {