Search in sources :

Example 1 with MolangRuntime

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()));
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) MolangRuntime(io.github.ocelot.molangcompiler.api.MolangRuntime) ResourceLocation(net.minecraft.resources.ResourceLocation) AnimationEffectSound(gg.moonflower.pollen.pinwheel.core.client.animation.AnimationEffectSound) Environment(net.fabricmc.api.Environment)

Aggregations

AnimationEffectSound (gg.moonflower.pollen.pinwheel.core.client.animation.AnimationEffectSound)1 MolangRuntime (io.github.ocelot.molangcompiler.api.MolangRuntime)1 Environment (net.fabricmc.api.Environment)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Entity (net.minecraft.world.entity.Entity)1