diff --git a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt index 32ea83048..332eadc9e 100644 --- a/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt +++ b/src/data/kotlin/ru/dbotthepony/mc/otm/datagen/SoundDataProvider.kt @@ -42,7 +42,10 @@ class SoundDataProvider(event: GatherDataEvent) : SoundDefinitionsProvider(event add( MSoundEvents.BLACK_HOLE, definition().subtitle("otm.sound.black_hole") - .with(SoundDefinition.Sound.sound(modLocation("singularity/amb_singularity"), SoundDefinition.SoundType.SOUND).stream())) + .with(SoundDefinition.Sound.sound(modLocation("singularity/amb_singularity"), SoundDefinition.SoundType.SOUND) + .attenuationDistance(32) + .stream() + )) add( MSoundEvents.ANDROID_PROJ_PARRY, 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 71b261fd4..9d2e4ffc6 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 @@ -20,12 +20,16 @@ import net.minecraft.world.level.block.state.BlockState import net.minecraft.world.level.levelgen.structure.BoundingBox import net.minecraft.world.phys.AABB import net.minecraft.world.phys.Vec3 +import net.neoforged.api.distmarker.Dist +import net.neoforged.api.distmarker.OnlyIn import net.neoforged.neoforge.common.Tags import ru.dbotthepony.kommons.util.getValue import ru.dbotthepony.kommons.util.setValue import ru.dbotthepony.mc.otm.block.BlackHoleBlock import ru.dbotthepony.mc.otm.block.entity.tech.GravitationStabilizerBlockEntity import ru.dbotthepony.mc.otm.block.entity.MatteryBlockEntity +import ru.dbotthepony.mc.otm.client.minecraft +import ru.dbotthepony.mc.otm.client.sound.BlackHoleAmbientSoundInstance import ru.dbotthepony.mc.otm.config.ServerConfig import ru.dbotthepony.mc.otm.core.addAll import ru.dbotthepony.mc.otm.core.collect.map @@ -305,6 +309,13 @@ class BlackHoleBlockEntity(p_155229_: BlockPos, p_155230_: BlockState) : Mattery } } + @OnlyIn(Dist.CLIENT) + private val ambientSound = BlackHoleAmbientSoundInstance(this) + + init { + 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 new file mode 100644 index 000000000..3a3077151 --- /dev/null +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/client/sound/BlackHoleAmbientSound.kt @@ -0,0 +1,23 @@ +package ru.dbotthepony.mc.otm.client.sound + +import net.minecraft.client.resources.sounds.AbstractSoundInstance +import net.minecraft.client.resources.sounds.SoundInstance +import net.minecraft.sounds.SoundSource +import net.minecraft.world.phys.Vec3 +import net.neoforged.api.distmarker.Dist +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()) { + private val center = Vec3.atCenterOf(tile.blockPos) + + init { + looping = true + x = center.x + y = center.y + z = center.z + } +} diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MSoundEvents.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MSoundEvents.kt index a235706e8..375b3dd39 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MSoundEvents.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/registry/game/MSoundEvents.kt @@ -4,14 +4,15 @@ import net.minecraft.core.registries.BuiltInRegistries import net.minecraft.sounds.SoundEvent import net.neoforged.bus.api.IEventBus import ru.dbotthepony.mc.otm.OverdriveThatMatters -import ru.dbotthepony.mc.otm.core.ResourceLocation +import ru.dbotthepony.mc.otm.OverdriveThatMatters.loc import ru.dbotthepony.mc.otm.registry.MDeferredRegister object MSoundEvents { private val registry: MDeferredRegister = MDeferredRegister(BuiltInRegistries.SOUND_EVENT, OverdriveThatMatters.MOD_ID) // TODO: 1.19.3 - private fun make(name: String): MDeferredRegister.Entry = registry.register(name) { SoundEvent.createVariableRangeEvent(ResourceLocation(OverdriveThatMatters.MOD_ID, name)) } + private fun make(name: String): MDeferredRegister.Entry = registry.register(name) { SoundEvent.createVariableRangeEvent(loc(name)) } + private fun make(name: String, range: Float): MDeferredRegister.Entry = registry.register(name) { SoundEvent.createFixedRangeEvent(loc(name), range) } val RIFLE_SHOT by make("item.rifle_shot") val PLASMA_WEAPON_OVERHEAT by make("item.plasma_weapon_overheat") @@ -22,7 +23,7 @@ object MSoundEvents { val ANDROID_SHOCKWAVE by make("android.shockwave") val ANDROID_PROJ_PARRY by make("android.projectile_parry") - val BLACK_HOLE by make("black_hole") + val BLACK_HOLE by make("black_hole", 32F) fun register(bus: IEventBus) { registry.register(bus)