tutorial:sounds
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| tutorial:sounds [2020/02/11 20:23] – The purpose of the player argument is not unknown earthcomputer | tutorial:sounds [2024/06/23 16:23] (current) – slainlight | ||
|---|---|---|---|
| Line 17: | Line 17: | ||
| </ | </ | ||
| - | You can do this when the block is right clicked for example, by overriding '' | + | You can do this when the block is right clicked for example, by overriding '' |
| <code java> | <code java> | ||
| public class ExampleBlock extends Block { | public class ExampleBlock extends Block { | ||
| Line 23: | Line 23: | ||
| | | ||
| @Override | @Override | ||
| - | public | + | public |
| if (!world.isClient) { | if (!world.isClient) { | ||
| world.playSound(null, | world.playSound(null, | ||
| Line 38: | Line 38: | ||
| To play a sound, you first need a sound file. Minecraft uses the '' | To play a sound, you first need a sound file. Minecraft uses the '' | ||
| If your sound file is in a different format (like the one in the provided link), you can use an online converter to convert from your format to '' | If your sound file is in a different format (like the one in the provided link), you can use an online converter to convert from your format to '' | ||
| - | Now put your .ogg file in the '' | + | Make sure your sound has only one channel, otherwise the attenuation effect (gradual loss of volume with distance) won't be applied to it. |
| + | Now put your .ogg file in the '' | ||
| ==== Step 2: Add a sounds.json file, or add to it if you already have one ==== | ==== Step 2: Add a sounds.json file, or add to it if you already have one ==== | ||
| Under '' | Under '' | ||
| Line 69: | Line 70: | ||
| public class ExampleMod { | public class ExampleMod { | ||
| [...] | [...] | ||
| - | public static final Identifier MY_SOUND_ID = new Identifier(" | + | public static final Identifier MY_SOUND_ID = Identifier.of(" |
| - | public static SoundEvent MY_SOUND_EVENT = new SoundEvent(MY_SOUND_ID); | + | public static SoundEvent MY_SOUND_EVENT = SoundEvent.of(MY_SOUND_ID); |
| } | } | ||
| </ | </ | ||
| + | If you're using version 1.19.2 or below, please replace '' | ||
| + | if you're using versions below 1.21, replace '' | ||
| ==== Step 4: Register your sound event ==== | ==== Step 4: Register your sound event ==== | ||
| Register your sound event under the '' | Register your sound event under the '' | ||
| Line 79: | Line 82: | ||
| public void onInitialize(){ | public void onInitialize(){ | ||
| [...] | [...] | ||
| - | | + | |
| } | } | ||
| </ | </ | ||
| + | If you're using version 1.19.2 or below, please replace '' | ||
| ==== Step 5: Use your sound event ==== | ==== Step 5: Use your sound event ==== | ||
| - | Use the sound event just like we explained at the start ('' | + | Use the sound event just like we explained at the start ('' |
| <code java> | <code java> | ||
| public class ExampleBlock extends Block { | public class ExampleBlock extends Block { | ||
| @Override | @Override | ||
| - | public | + | public |
| if (!world.isClient) { | if (!world.isClient) { | ||
| world.playSound( | world.playSound( | ||
tutorial/sounds.1581452631.txt.gz · Last modified: 2020/02/11 20:23 by earthcomputer