BlockCarpentry

BlockCarpentry

7M Downloads

Missing sounds.

Flatgub opened this issue ยท 2 comments

commented

This is technically a duplicate of #4 but that issue is closed and there's more than one place where this bug exists.

Fence gates make no sound when opening or closing.

world.playEvent(player, state.get(OPEN) ? 1008 : 1014, pos, 0);

Buttons make no sound when being pressed.

These issues exist because World.playSound (and by extension World.playEvent and AbstractButtonBlock.playSound) sends the sound to every player on the server except the player named in the first argument, which means that in the above lines the player who interacts with the gate or button is the only player who doesn't hear the sound. To fix this the first argument needs to be null so that the sound is sent to everybody.

On a side note, you should avoid using World.playEvent, I assume you're using it because you've copied it out of chunks of vanilla code which use it, but the forge API provides World.playSound and SoundEvents which you should use instead because the numeric sound IDs are impossible to figure out, like for example where you have 1008, which is the sound of a fence gate opening, you would instead put SoundEvents.BLOCK_FENCE_GATE_OPEN so that its more obvious which sound you're trying to use.

In a full line that would look like
world.playSound(null, pos, state.get(OPEN) ? SoundEvents.BLOCK_FENCE_GATE_OPEN : SoundEvents.BLOCK_FENCE_GATE_CLOSE, SoundCategory.BLOCKS,1f, 1f);

You can read more about playSound and SoundEvents here: https://mcforge.readthedocs.io/en/latest/effects/sounds/

commented

Thanks for reporting and for your detailed help. I really appreciate it! I'll fix this when I have some time. Right now I'm under a lot of stress because I'm deep in the exam phase and have six more exams in the next three weeks. After that, I'll fix this problem.
Thank you again for your hints!!
Regards, Manu

commented

Finally found time to fix it. It works now! Thanks again for reporting and your detailed help!
Regards, Manu