User Tools

Site Tools


tutorial:sounds

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
Next revisionBoth sides next revision
tutorial:sounds [2019/08/01 20:28] fudgetutorial:sounds [2019/08/19 19:57] – [Step 2: Add a sounds.json file, or add to it if you already have one] Add reference to minecraft wiki jamieswhiteshirt
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 =====
Line 20: Line 20:
 <code java> <code java>
 public class ExampleBlock extends Block { public class ExampleBlock extends Block {
-    ...+    [...
 +    
     @Override     @Override
     public boolean activate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {     public boolean activate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {
Line 62: Line 63:
 } }
 </code> </code>
 +
 +See the [[https://minecraft.gamepedia.com/Sounds.json|Minecraft Wiki]] for more details about ''sounds.json''.
 ==== Step 3: Create your sound event ==== ==== Step 3: Create your sound event ====
 Simply create a new instance of ''SoundEvent'' with the identifier ''modid:sound_name'', for example: Simply create a new instance of ''SoundEvent'' with the identifier ''modid:sound_name'', for example:
 <code java> <code java>
 public class ExampleMod { public class ExampleMod {
-    ... +    [...] 
-    public static SoundEvent MY_SOUND_EVENT new SoundEvent(new Identifier("tutorial:my_sound"));+    public static final Identifier MY_SOUND_ID = new Identifier("tutorial:my_sound") 
 +    public static SoundEvent MY_SOUND_EVENT = new SoundEvent(MY_SOUND_ID);
 } }
 </code> </code>
Line 75: Line 79:
 @Override @Override
 public void onInitialize(){ public void onInitialize(){
-     ... +     [...] 
-     Registry.register(Registry.SOUND_EVENT, MY_SOUND_EVENT.getId(), MY_SOUND_EVENT);+     Registry.register(Registry.SOUND_EVENT, ExampleMod.MY_SOUND_ID, MY_SOUND_EVENT);
  
 </code> </code>
tutorial/sounds.txt · Last modified: 2023/01/09 18:20 by slainlight