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

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

Introduction

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

Prototype

public SoundCategory getCategory() 

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/*from   w  w  w. ja  v  a  2s  .  c  om*/
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());
    }
}