Example usage for net.minecraftforge.event.entity PlaySoundAtEntityEvent getVolume

List of usage examples for net.minecraftforge.event.entity PlaySoundAtEntityEvent getVolume

Introduction

In this page you can find the example usage for net.minecraftforge.event.entity PlaySoundAtEntityEvent getVolume.

Prototype

public float getVolume() 

Source Link

Usage

From source file:jayavery.accesstweaks.Sounds.java

License:Open Source License

/** Play or prevent sound and subtitle according to settings.
 * This event catches player & some other entity sounds */
@SubscribeEvent/*  ww  w.  java2 s  . c  o m*/
public static void playEntitySound(PlaySoundAtEntityEvent event) {

    Entity entity = event.getEntity();
    ISound sound = null;

    if (entity != null) {

        sound = new PositionedSoundRecord(event.getSound(), event.getCategory(), event.getVolume(),
                event.getPitch(), (float) entity.posX, (float) entity.posY, (float) entity.posZ);
    }

    SoundCategory category;

    if (Minecraft.getMinecraft().player != null && entity == Minecraft.getMinecraft().player) {

        category = SoundCategory.ME;

    } else {

        category = SoundCategory.categorise(sound);
    }

    SoundResult result = categoryResults.get(category);

    if (!result.playSound()) {

        event.setCanceled(true);
    }

    if (result.showSubtitle()) {

        guiSubtitles.addSubtitle(sound,
                Minecraft.getMinecraft().getSoundHandler().getAccessor(event.getSound().getSoundName()),
                result.getColour());
    }
}