| 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|registered/1.16]] 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>!}} |
| | | | |
| | == Playing Sounds == | | == Playing Sounds == |
| Line 95: |
Line 104: |
| | === <code> PlayerEntity</code> === | | === <code> PlayerEntity</code> === |
| | | | |
| − | # <code><nowiki>playSound(SoundEvent, volume, pitch)</nowiki></code> (overriding the one in <code>[[Sounds#Entity|Entity/1.16]]</code>) | + | # <code><nowiki>playSound(SoundEvent, volume, pitch)</nowiki></code> (overriding the one in <code>[[Sounds#Entity/1.16|Entity]]</code>) |
| | #* Forwards to <code>World</code>‘s overload (2), passing in <code>this</code> as the player. | | #* Forwards to <code>World</code>‘s overload (2), passing in <code>this</code> as the player. |
| − | #* <code>Client Behavior</code>: Does nothing, see override in <code>[[Sounds#clientplayerentity|ClientPlayerEntity/1.16]]</code>. | + | #* <code>Client Behavior</code>: Does nothing, see override in <code>[[Sounds#clientplayerentity/1.16|ClientPlayerEntity]]</code>. |
| | #* <code>Server Behavior</code>: Plays the sound to everyone nearby <code>except</code> this player. | | #* <code>Server Behavior</code>: Plays the sound to everyone nearby <code>except</code> this player. |
| − | #* <code>Usage</code>: See <code>[[Sounds#clientplayerentity|ClientPlayerEntity/1.16]]</code>. | + | #* <code>Usage</code>: See <code>[[Sounds#clientplayerentity/1.16|ClientPlayerEntity]]</code>. |
| | | | |
| | === <code> ClientPlayerEntity</code> === | | === <code> ClientPlayerEntity</code> === |
| | | | |
| − | # <code><nowiki>playSound(SoundEvent, volume, pitch)</nowiki></code> (overriding the one in <code>[[Sounds#playerentity|PlayerEntity/1.16]]</code>) | + | # <code><nowiki>playSound(SoundEvent, volume, pitch)</nowiki></code> (overriding the one in <code>[[Sounds#playerentity/1.16|PlayerEntity]]</code>) |
| | #* Forwards to <code>World</code>‘s overload (2), passing in <code>this</code> as the player. | | #* Forwards to <code>World</code>‘s overload (2), passing in <code>this</code> as the player. |
| | #* <code>Client Behavior</code>: Just plays the Sound Event. | | #* <code>Client Behavior</code>: Just plays the Sound Event. |
| Line 110: |
Line 119: |
| | | | |
| | | | |
| − | [[Category:Game Effects/1.16]] | + | [[Category:Game Effects/1.16|Category:Game Effects]] |