feat: causality anchor effect on cyber instrument

This commit is contained in:
xtex 2023-07-30 10:24:46 +08:00
parent b183e99b3c
commit fe5eeb0364
Signed by: xtex
GPG Key ID: B918086ED8045B91
2 changed files with 7 additions and 2 deletions

View File

@ -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()
}
}

View File

@ -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)