diff --git a/develop/sounds/dynamic-sounds.md b/develop/sounds/dynamic-sounds.md index 8929e48bf..8bf033e52 100644 --- a/develop/sounds/dynamic-sounds.md +++ b/develop/sounds/dynamic-sounds.md @@ -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) diff --git a/reference/latest/src/client/java/com/example/docs/FabricDocsDynamicSound.java b/reference/latest/src/client/java/com/example/docs/FabricDocsDynamicSound.java index 2ece67855..b213f82ea 100644 --- a/reference/latest/src/client/java/com/example/docs/FabricDocsDynamicSound.java +++ b/reference/latest/src/client/java/com/example/docs/FabricDocsDynamicSound.java @@ -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 } } diff --git a/reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java b/reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java index ae8c317d3..e24da9602 100644 --- a/reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java +++ b/reference/latest/src/client/java/com/example/docs/sound/instance/CustomSoundInstance.java @@ -30,7 +30,6 @@ public void tick() { this.setDone(); return; } - // move sound position over to the new position for every tick setPositionToEntity(); }