tutorial:sounds
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| tutorial:sounds [2019/08/01 20:26] – created fudge | tutorial:sounds [2024/06/23 16:23] (current) – slainlight | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Playing Sounds ====== | ====== Playing Sounds ====== | ||
| - | Ready to replace those zombie sounds with your own cool sounds? You've come to the right place. | + | Ready to replace those zombie sounds with your own sounds? You've come to the right place. |
| ===== Playing a pre-existing sound ===== | ===== Playing a pre-existing sound ===== | ||
| - | Playing a pre-exisiting is fairly simple. Make sure you are on the logical server and call '' | + | Playing a pre-exisiting |
| <code java> | <code java> | ||
| if (!world.isClient) { | if (!world.isClient) { | ||
| world.playSound( | world.playSound( | ||
| - | null, // Player | + | null, // Player |
| blockPos, // The position of where the sound will come from | blockPos, // The position of where the sound will come from | ||
| SoundEvents.BLOCK_ANVIL_LAND, | SoundEvents.BLOCK_ANVIL_LAND, | ||
| Line 17: | Line 17: | ||
| </ | </ | ||
| - | You can do this when the block is right clicked for example, by overriding 'activate`: | + | 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 { | ||
| - | ... | + | |
| + | | ||
| @Override | @Override | ||
| - | public | + | public |
| if (!world.isClient) { | if (!world.isClient) { | ||
| world.playSound(null, | world.playSound(null, | ||
| Line 37: | 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 50: | Line 52: | ||
| } | } | ||
| </ | </ | ||
| - | You can also add a category and subtitle to your sound: | + | You can also add a subtitle to your sound. The subtitle is a translation key, which should go in your language file. |
| <code javascript resources/ | <code javascript resources/ | ||
| { | { | ||
| " | " | ||
| - | | + | " |
| - | | + | |
| " | " | ||
| " | " | ||
| Line 62: | Line 63: | ||
| } | } | ||
| </ | </ | ||
| + | |||
| + | See the [[https:// | ||
| ==== Step 3: Create your sound event ==== | ==== Step 3: Create your sound event ==== | ||
| Simply create a new instance of '' | Simply create a new instance of '' | ||
| <code java> | <code java> | ||
| public class ExampleMod { | public class ExampleMod { | ||
| - | ... | + | |
| - | public static | + | public static |
| + | 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 75: | Line 81: | ||
| @Override | @Override | ||
| 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( | ||
| - | null, // Player | + | null, // Player |
| blockPos, // The position of where the sound will come from | blockPos, // The position of where the sound will come from | ||
| ExampleMod.MY_SOUND_EVENT, | ExampleMod.MY_SOUND_EVENT, | ||
| Line 99: | Line 106: | ||
| } | } | ||
| </ | </ | ||
| - | You should now here a punch sound when you right click your block! | + | You should now hear a punch sound when you right click your block! |
| ==== Troubleshooting ==== | ==== Troubleshooting ==== | ||
| Don't hear anything? Try: | Don't hear anything? Try: | ||
| * Turning up your in-game volume sliders. | * Turning up your in-game volume sliders. | ||
| * Deleting the output directory. | * Deleting the output directory. | ||
tutorial/sounds.1564691187.txt.gz · Last modified: 2019/08/01 20:26 by fudge