Skip to content

Commit

Permalink
finished basic sound instance creation and usage
Browse files Browse the repository at this point in the history
  • Loading branch information
JR1811 committed Jul 23, 2024
1 parent c36362e commit 641396e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
6 changes: 5 additions & 1 deletion develop/sounds/dynamic-sounds.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ Simply create a new class for your custom `SoundInstance` and extend from `Movin

@[code lang=java transcludeWith=:::1](@/reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java)

Then just call this custom `SoundInstance` from the client side place, where you wan't to call it from.
Using your custom `Entity` or `BlockEntity` instead of that basic `LivingEntity` instance can give you even more control e.g. in the `tick()` method based
on getter methods.

After you finished creating your custom `SoundInstance`, just call it from the client side place, where you wan't to call it from.
In the same way you can also stop the custom `SoundInstance` manually, if necessary.

@[code lang=java transcludeWith=:::2](@/reference/latest/src/client/java/com/example/docs/FabricDocsDynamicSound.java)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ public void onInitializeClient() {
client.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F));
// :::1
// :::2
client.getSoundManager().play(
new CustomSoundInstance(client.player, CustomSounds.ENGINE_LOOP, SoundCategory.NEUTRAL)
);
CustomSoundInstance instance = new CustomSoundInstance(client.player, CustomSounds.ENGINE_LOOP, SoundCategory.NEUTRAL);

// play the sound instance
client.getSoundManager().play(instance);

// stop the sound instance
client.getSoundManager().stop(instance);
// :::2
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public void tick() {
this.setDone();
return;
}

Check failure on line 32 in reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java

View workflow job for this annotation

GitHub Actions / mod

missing blank line after block at same indentation level

// move sound position over to the new position for every tick
setPositionToEntity();
}
Expand Down

0 comments on commit 641396e

Please sign in to comment.