feat: causality anchor effect on cyber instrument
This commit is contained in:
parent
b183e99b3c
commit
fe5eeb0364
@ -26,6 +26,7 @@ import net.minecraft.world.level.block.state.properties.NoteBlockInstrument
|
|||||||
import net.minecraft.world.level.material.MapColor
|
import net.minecraft.world.level.material.MapColor
|
||||||
import net.minecraft.world.phys.BlockHitResult
|
import net.minecraft.world.phys.BlockHitResult
|
||||||
import quaedam.Quaedam
|
import quaedam.Quaedam
|
||||||
|
import quaedam.misc.causality.CausalityAnchor
|
||||||
import quaedam.projector.Projector
|
import quaedam.projector.Projector
|
||||||
import quaedam.utils.getChunksNearby
|
import quaedam.utils.getChunksNearby
|
||||||
import quaedam.utils.sendBlockUpdated
|
import quaedam.utils.sendBlockUpdated
|
||||||
@ -122,7 +123,9 @@ object CyberInstrumentBlock : Block(
|
|||||||
hand: InteractionHand,
|
hand: InteractionHand,
|
||||||
hit: BlockHitResult
|
hit: BlockHitResult
|
||||||
): InteractionResult {
|
): 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
|
val entity = level.getBlockEntity(pos) as CyberInstrumentBlockEntity
|
||||||
if (entity.player == null) {
|
if (entity.player == null) {
|
||||||
entity.startMusic()
|
entity.startMusic()
|
||||||
@ -173,6 +176,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
|
|
||||||
private fun checkProjections() =
|
private fun checkProjections() =
|
||||||
Projector.findNearbyProjections(level!!, blockPos, MusicProjection.effect.get()).isNotEmpty()
|
Projector.findNearbyProjections(level!!, blockPos, MusicProjection.effect.get()).isNotEmpty()
|
||||||
|
|| CausalityAnchor.checkEffect(level!!, blockPos)
|
||||||
|
|
||||||
fun startMusic(force: Boolean = false, synced: Boolean = false) {
|
fun startMusic(force: Boolean = false, synced: Boolean = false) {
|
||||||
if ((player == null || force) && !level!!.isClientSide && checkProjections()) {
|
if ((player == null || force) && !level!!.isClientSide && checkProjections()) {
|
||||||
@ -203,7 +207,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
|
|||||||
player = null
|
player = null
|
||||||
setChanged()
|
setChanged()
|
||||||
sendBlockUpdated()
|
sendBlockUpdated()
|
||||||
if (level!!.random.nextInt(7) != 0) {
|
if (CausalityAnchor.checkEffect(level!!, blockPos) || level!!.random.nextInt(7) != 0) {
|
||||||
startMusic()
|
startMusic()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -62,6 +62,7 @@ class MusicPlayer(val seed: Long, val level: Level, val pos: BlockPos, val start
|
|||||||
if (level.isClientSide) {
|
if (level.isClientSide) {
|
||||||
// play note
|
// play note
|
||||||
val projections = Projector.findNearbyProjections(level, pos, MusicProjection.effect.get())
|
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 volume = 3.0f * projections.maxOf { it.volumeFactor } * note.volume
|
||||||
val particle = projections.any { it.particle }
|
val particle = projections.any { it.particle }
|
||||||
val instrument = level.getBlockState(pos).getValue(BlockStateProperties.NOTEBLOCK_INSTRUMENT)
|
val instrument = level.getBlockState(pos).getValue(BlockStateProperties.NOTEBLOCK_INSTRUMENT)
|
||||||
|
Loading…
Reference in New Issue
Block a user