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 revision Previous revision
Next revision
Previous revision
tutorial:sounds [2019/08/19 19:57]
jamieswhiteshirt [Step 2: Add a sounds.json file, or add to it if you already have one] Add reference to minecraft wiki
tutorial:sounds [2020/06/20 04:04] (current)
hydos add ; to code
Line 7: Line 7:
 if (!world.isClient) { if (!world.isClient) {
       world.playSound(       world.playSound(
-              null, // Player ​(purpose unknown, edit if you know)+              null, // Player ​if non-null, will play sound for every nearby player *except* the specified 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,​ // The sound that will play, in this case, the sound the anvil plays when it lands.               SoundEvents.BLOCK_ANVIL_LAND,​ // The sound that will play, in this case, the sound the anvil plays when it lands.
Line 17: Line 17:
 </​code>​ </​code>​
  
-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 ''​onUse'':​
 <code java> <code java>
 public class ExampleBlock extends Block { public class ExampleBlock extends Block {
Line 23: Line 23:
     ​     ​
     @Override     @Override
-    public ​boolean activate(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {+    public ​ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {
         if (!world.isClient) {         if (!world.isClient) {
             world.playSound(null,​ blockPos, SoundEvents.BLOCK_ANVIL_LAND,​ SoundCategory.BLOCKS,​ 1f, 1f);             world.playSound(null,​ blockPos, SoundEvents.BLOCK_ANVIL_LAND,​ SoundCategory.BLOCKS,​ 1f, 1f);
Line 51: Line 51:
 } }
 </​code>​ </​code>​
-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/​assets/​tutorial/​sounds.json>​ <code javascript resources/​assets/​tutorial/​sounds.json>​
 { {
   "​my_sound":​ {   "​my_sound":​ {
-    ​"​category":​ "​my_sounds",​ +    "​subtitle":​ "subtitles.tutorial.my_sound",
-    ​"​subtitle":​ "*punch*",+
     "​sounds":​ [     "​sounds":​ [
       "​tutorial:​my_sound"​       "​tutorial:​my_sound"​
Line 70: Line 69:
 public class ExampleMod { public class ExampleMod {
     [...]     [...]
-    public static final Identifier MY_SOUND_ID = 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);​     public static SoundEvent MY_SOUND_EVENT = new SoundEvent(MY_SOUND_ID);​
 } }
Line 84: Line 83:
 </​code>​ </​code>​
 ==== Step 5: Use your sound event ==== ==== Step 5: Use your sound event ====
-Use the sound event just like we explained at the start (''​activate''​ is just an example, use it anywhere you have access to ''​World''​ instance):+Use the sound event just like we explained at the start (''​onUse''​ is just an example, use it anywhere you have access to ''​World''​ instance):
 <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 ​ActionResult onUse(BlockState blockState, World world, BlockPos blockPos, PlayerEntity placedBy, Hand hand, BlockHitResult blockHitResult) {
         if (!world.isClient) {         if (!world.isClient) {
             world.playSound(             world.playSound(
-                    null, // Player ​(purpose unknown, edit if you know)+                    null, // Player ​if non-null, will play sound for every nearby player *except* the specified 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,​ // The sound that will play                     ExampleMod.MY_SOUND_EVENT,​ // The sound that will play
tutorial/sounds.1566244637.txt.gz · Last modified: 2019/08/19 19:57 by jamieswhiteshirt