Added a notice about a trap for newbies where sounds will always play on the client if they exist in the sound file regardless of registry.
Line 17:
Line 17:
</syntaxhighlight>
</syntaxhighlight>
−
Using the example above, it creates a sound called <code>example_sound</code> and references the file <code><nowiki>assets/<modid>/sounds/example_sound_file.ogg</nowiki></code>.
+
Using the example above, it creates a sound called <code>example_sound</code> and references the file <code><nowiki>assets/<modid>/sounds/example_sound_file.ogg</nowiki></code>.
+
+
+
{{Tip/Danger | Due to [https://bugs.mojang.com/browse/MC-146721 the way OpenAL (Minecraft's sound engine) works], for your sound to have attenuation - that is, for it to get quieter as the player walks away, it absolutely MUST be mono (have one audio channel).
+
+
Stereo sounds are always played at the '''player's''' location, making them ideal for ambient sounds and background music.
+
+
}}
+
Instead of being constructed as a list of strings, each entry could also be an object which allows a greater control over what and how it is played.
Instead of being constructed as a list of strings, each entry could also be an object which allows a greater control over what and how it is played.
Line 61:
Line 69:
For example, to reference <code>example_complex.ogg</code>, you would store the reference name (e.g. <code>example_sound_complex</code>) within a <code>new SoundEvent(new ResourceLocation("examplemod", "example_sound_complex"))</code>. This will locate <code>assets/examplemod/sounds.json</code> and try to find an <code>example_sound_complex</code> object nested within it.
For example, to reference <code>example_complex.ogg</code>, you would store the reference name (e.g. <code>example_sound_complex</code>) within a <code>new SoundEvent(new ResourceLocation("examplemod", "example_sound_complex"))</code>. This will locate <code>assets/examplemod/sounds.json</code> and try to find an <code>example_sound_complex</code> object nested within it.
−
<code>SoundEvent</code>s must be [[Registration/1.16|registered]] to be referenced in code.
+
+
{{Tip/Warning|<code>SoundEvent</code>s must be [[Registration/1.16|registered]] on the <code>ModEventBus</code> to properly reference a sound on a server. However, <code>SoundEvent</code>s or referencing a sound by name will still work on the client when the sound is not registered as long as the sound exists in <code>sounds.json</code>!}}