Started by
JrBacon
on
Topic category: Help with Minecraft modding (Java Edition)
Hi, I am trying to make it so that when you select an item in offhand or in main hand, it just plays a noise and gives you the effect speed 1. But when i do this, it plays constantly. I know why this happens, but how do you make the sound only play once. Thank you!!
Try making a player-lifetime logic variable, (I'll call it 'sound_played'). When the sound plays, in addition to playing the sound, set this variable to true. Then, nest the code that's playing the sound in an if bracket that first checks if the variable is true. Lastly, on player update tick, if the player isn't holding the item in their main hand, set 'sound_played' back to false.
Essentially, you just need a variable to tell the game whether or not the sound's already been played, and you can then flip it back and forth as needed.