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 revisionBoth sides next revision
tutorial:sounds [2020/02/11 20:23] – The purpose of the player argument is not unknown earthcomputertutorial:sounds [2020/05/16 19:35] – activate -> onUse yanis48
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 83: 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(
tutorial/sounds.txt · Last modified: 2023/01/09 18:20 by slainlight