From fe5eeb03643322e06bfa98b910437ca1f87ed033 Mon Sep 17 00:00:00 2001 From: xtex Date: Sun, 30 Jul 2023 10:24:46 +0800 Subject: [PATCH] feat: causality anchor effect on cyber instrument --- .../kotlin/quaedam/projection/music/CyberInstrument.kt | 8 ++++++-- .../main/kotlin/quaedam/projection/music/MusicPlayer.kt | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/common/src/main/kotlin/quaedam/projection/music/CyberInstrument.kt b/common/src/main/kotlin/quaedam/projection/music/CyberInstrument.kt index 1bd1b0a..03189ac 100644 --- a/common/src/main/kotlin/quaedam/projection/music/CyberInstrument.kt +++ b/common/src/main/kotlin/quaedam/projection/music/CyberInstrument.kt @@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.NoteBlockInstrument import net.minecraft.world.level.material.MapColor import net.minecraft.world.phys.BlockHitResult import quaedam.Quaedam +import quaedam.misc.causality.CausalityAnchor import quaedam.projector.Projector import quaedam.utils.getChunksNearby import quaedam.utils.sendBlockUpdated @@ -122,7 +123,9 @@ object CyberInstrumentBlock : Block( hand: InteractionHand, hit: BlockHitResult ): InteractionResult { - if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty()) { + if (Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()).isNotEmpty() + || CausalityAnchor.checkEffect(level, pos) + ) { val entity = level.getBlockEntity(pos) as CyberInstrumentBlockEntity if (entity.player == null) { entity.startMusic() @@ -173,6 +176,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) : private fun checkProjections() = Projector.findNearbyProjections(level!!, blockPos, MusicProjection.effect.get()).isNotEmpty() + || CausalityAnchor.checkEffect(level!!, blockPos) fun startMusic(force: Boolean = false, synced: Boolean = false) { if ((player == null || force) && !level!!.isClientSide && checkProjections()) { @@ -203,7 +207,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) : player = null setChanged() sendBlockUpdated() - if (level!!.random.nextInt(7) != 0) { + if (CausalityAnchor.checkEffect(level!!, blockPos) || level!!.random.nextInt(7) != 0) { startMusic() } } diff --git a/common/src/main/kotlin/quaedam/projection/music/MusicPlayer.kt b/common/src/main/kotlin/quaedam/projection/music/MusicPlayer.kt index fd0501f..e464759 100644 --- a/common/src/main/kotlin/quaedam/projection/music/MusicPlayer.kt +++ b/common/src/main/kotlin/quaedam/projection/music/MusicPlayer.kt @@ -62,6 +62,7 @@ class MusicPlayer(val seed: Long, val level: Level, val pos: BlockPos, val start if (level.isClientSide) { // play note val projections = Projector.findNearbyProjections(level, pos, MusicProjection.effect.get()) + .takeIf { it.isNotEmpty() } ?: listOf(MusicProjectionEffect()) val volume = 3.0f * projections.maxOf { it.volumeFactor } * note.volume val particle = projections.any { it.particle } val instrument = level.getBlockState(pos).getValue(BlockStateProperties.NOTEBLOCK_INSTRUMENT)