use of io.github.ocelot.molangcompiler.api.MolangRuntime in project pollen by MoonflowerTeam.
the class AnimatedEntity method handleSoundEffect.
/**
* Called when a sound event should be played.
*
* @param animation The animation the effect is playing for
* @param soundEffect The effect to play
*/
@Environment(EnvType.CLIENT)
@Override
default void handleSoundEffect(AnimationData animation, AnimationData.SoundEffect soundEffect) {
if (!(this instanceof Entity))
return;
Entity entity = (Entity) this;
ResourceLocation sound = ResourceLocation.tryParse(soundEffect.getEffect());
if (sound != null) {
// 1.0 is the default pitch and volume
MolangRuntime runtime = MolangRuntime.runtime().create(1.0F);
Minecraft.getInstance().getSoundManager().play(new AnimationEffectSound(sound, entity.getSoundSource(), animation, entity, soundEffect.getPitch().safeResolve(runtime), soundEffect.getVolume().safeResolve(runtime), soundEffect.isLoop()));
}
}
Aggregations