fix: client-side note player

This commit is contained in:
xtex 2023-07-29 21:41:40 +08:00
parent 79b11498c1
commit 314957eeb5
Signed by: xtex
GPG Key ID: B918086ED8045B91
2 changed files with 17 additions and 7 deletions

View File

@ -27,6 +27,7 @@ import net.minecraft.world.level.material.MapColor
import net.minecraft.world.phys.BlockHitResult
import quaedam.Quaedam
import quaedam.projector.Projector
import quaedam.utils.sendBlockUpdated
object CyberInstrument {
@ -176,6 +177,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
if (player == null && !level!!.isClientSide && checkProjections()) {
player = MusicPlayer(level!!.random.nextLong(), level!!, blockPos)
setChanged()
sendBlockUpdated()
}
}
@ -186,6 +188,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
if (player?.isEnd == true) {
player = null
setChanged()
sendBlockUpdated()
if (level!!.random.nextInt(7) != 0) {
startMusic()
}
@ -194,6 +197,7 @@ class CyberInstrumentBlockEntity(pos: BlockPos, state: BlockState) :
} else {
player = null
setChanged()
sendBlockUpdated()
}
}

View File

@ -1,11 +1,15 @@
package quaedam.projection.music
import dev.architectury.utils.GameInstance
import net.minecraft.client.resources.sounds.SimpleSoundInstance
import net.minecraft.client.resources.sounds.SoundInstance
import net.minecraft.core.BlockPos
import net.minecraft.core.Holder
import net.minecraft.core.particles.ParticleTypes
import net.minecraft.nbt.CompoundTag
import net.minecraft.sounds.SoundEvent
import net.minecraft.sounds.SoundSource
import net.minecraft.util.RandomSource
import net.minecraft.world.level.Level
import net.minecraft.world.level.block.NoteBlock
import net.minecraft.world.level.block.entity.SkullBlockEntity
@ -84,17 +88,19 @@ class MusicPlayer(val seed: Long, val level: Level, val pos: BlockPos, val start
)
}
level.playSeededSound(
null,
pos.x.toDouble() + 0.5,
pos.y.toDouble() + 0.5,
pos.z.toDouble() + 0.5,
holder,
val instance = SimpleSoundInstance(
holder.value().location,
SoundSource.RECORDS,
volume,
pitch,
level.random.nextLong()
RandomSource.create(level.random.nextLong()),
false, 0, SoundInstance.Attenuation.NONE,
pos.x.toDouble() + 0.5,
pos.y.toDouble() + 0.5,
pos.z.toDouble() + 0.5,
false
)
GameInstance.getClient().soundManager.play(instance)
}
}
noteTime--