Jump to content

[1.15.2] Check if a sound is played


Recommended Posts

Hi Guys ! I'm trying to do some stuff but it seem it doesn't work.
I just want to check if a sound is played to prevent the game to play it twice.
So... i was telling me there is two ways to do it :

1. put a timer and when it is below zero, the block can play it again when the player go trough it.
2. second option maybe safer, only play it again when the previous sound is over and the player go trough the block.

I tried to check the second option that in a method but... it seem that Soundhandler.isPlaying(Isound) doesn't work.... Or maybe i'm missing something very obvious.
Be gentle with me, i'm auto learning Java haha ;)


private void playSound(IBlockReader world, BlockPos pos, Entity entity) 
		if(timer <=0) 
			SoundEvent sound = InitSound.PASSAGE_TOUR.get();
			System.out.println("before doing it ? " +Minecraft.getInstance().getSoundHandler().isPlaying( SimpleSound.music(sound)));
			//((World) world).playSound((PlayerEntity)entity, pos,sound, SoundCategory.BLOCKS, 1F, 1F);
			entity.playSound(sound, 1.0F, 1.0F);
			System.out.println("the sound is played ? " +Minecraft.getInstance().getSoundHandler().isPlaying( SimpleSound.music(sound)));


 the two output say in the consol that they are false... both.

Thank you for reading this and Thank you even more if you help me with this ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...

Important Information

By using this site, you agree to our Terms of Use.