Hello I have a question. I want to create a simple block mechanic: make a sound when powered by redstone. I assigned the property "powered" to the block. I also created a system that manipulates its value accordingly. I managed to make that when a signal is detected, the sound is played. But how do I make it play in a loop until the signal is interrupted? Please note that when you rejoin the world, the activity is supposed to resume.
My existing code:
@Override
public void neighborChanged(BlockState blockState, Level level, BlockPos blockPos, Block block, BlockPos p_60513_, boolean p_60514_) {
if (!level.isClientSide()) {
if (blockState.getValue(POWERED) !=
level.hasNeighborSignal(blockPos)) {
BlockState cycledBlockState = blockState.cycle(POWERED);
level.setBlock(blockPos, cycledBlockState, 2);
if (cycledBlockState.getValue(POWERED))
level.playSound(null, blockPos, MyMod.SOUND.get(),
SoundSource.BLOCKS, 2, 1); //This plays a single sound
}
}
}