Search in sources :

Example 1 with ITrackedSound

use of org.blockartistry.lib.sound.ITrackedSound in project DynamicSurroundings by OreCruncher.

the class EntitySwingEffect method update.

@Override
public void update(@Nonnull final Entity subject) {
    final EntityLivingBase entity = (EntityLivingBase) subject;
    // Boats are strange - ignore them for now
    if (entity.getRidingEntity() instanceof EntityBoat)
        return;
    // Is the swing in motion
    if (entity.swingingHand != null && entity.swingProgressInt > this.swingProgress) {
        if (!this.isSwinging) {
            final ItemStack currentItem = entity.getHeldItem(entity.swingingHand);
            final SoundEffect soundEffect = ClientRegistry.ITEMS.getSwingSound(currentItem);
            if (soundEffect != null) {
                final RayTraceResult whatImHitting = RayTrace.trace(entity);
                if (whatImHitting == null || whatImHitting.typeOfHit != Type.BLOCK) {
                    final ITrackedSound snd = getState().createSound(soundEffect, entity);
                    getState().playSound(snd);
                }
            }
        }
        this.isSwinging = true;
        this.swingProgress = entity.swingProgressInt;
    } else {
        this.isSwinging = false;
        this.swingProgress = entity.swingProgressInt;
    }
}
Also used : SoundEffect(org.blockartistry.DynSurround.client.sound.SoundEffect) EntityBoat(net.minecraft.entity.item.EntityBoat) EntityLivingBase(net.minecraft.entity.EntityLivingBase) RayTraceResult(net.minecraft.util.math.RayTraceResult) ITrackedSound(org.blockartistry.lib.sound.ITrackedSound) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ITrackedSound

use of org.blockartistry.lib.sound.ITrackedSound in project DynamicSurroundings by OreCruncher.

the class SoundEngine method onSoundSourceEvent.

/**
 * Event raised when a sound is going to be played. Use this time to set the ID
 * of an ITrackedSound as well as check whether the current thread is the client
 * thread.
 *
 * @param event
 *            Incoming event that has been raised
 */
@SubscribeEvent
public void onSoundSourceEvent(@Nonnull final SoundSourceEvent event) {
    this.guard.check("playSound");
    final ISound sound = event.getSound();
    if (sound instanceof ITrackedSound) {
        ((ITrackedSound) sound).setId(event.getUuid());
    }
}
Also used : ISound(net.minecraft.client.audio.ISound) ITrackedSound(org.blockartistry.lib.sound.ITrackedSound) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with ITrackedSound

use of org.blockartistry.lib.sound.ITrackedSound in project DynamicSurroundings by OreCruncher.

the class EntityBowSoundEffect method update.

@Override
public void update(@Nonnull final Entity subject) {
    final EntityLivingBase entity = (EntityLivingBase) subject;
    final ItemStack currentStack = entity.getActiveItemStack();
    if (ItemStackUtil.isValidItemStack(currentStack)) {
        if (this.lastActiveStack == null || !ItemStack.areItemStacksEqual(currentStack, this.lastActiveStack)) {
            if (ClientRegistry.ITEMS.isBow(currentStack) || ClientRegistry.ITEMS.isShield(currentStack)) {
                final SoundEffect soundEffect = ClientRegistry.ITEMS.getUseSound(currentStack);
                if (soundEffect != null) {
                    final ITrackedSound fx = getState().createSound(soundEffect, entity);
                    getState().playSound(fx);
                }
            }
            this.lastActiveStack = currentStack;
        }
    } else {
        this.lastActiveStack = null;
    }
}
Also used : SoundEffect(org.blockartistry.DynSurround.client.sound.SoundEffect) EntityLivingBase(net.minecraft.entity.EntityLivingBase) ITrackedSound(org.blockartistry.lib.sound.ITrackedSound) ItemStack(net.minecraft.item.ItemStack)

Example 4 with ITrackedSound

use of org.blockartistry.lib.sound.ITrackedSound in project DynamicSurroundings by OreCruncher.

the class CraftingSoundEffect method onEvent.

@SubscribeEvent
public void onEvent(@Nonnull final ItemCraftedEvent event) {
    if (!ModOptions.sound.enableCraftingSound || !isClientValid(event))
        return;
    if (this.craftSoundThrottle >= (EnvironState.getTickCounter() - 30))
        return;
    this.craftSoundThrottle = EnvironState.getTickCounter();
    final ITrackedSound fx = getState().createSound(Sounds.CRAFTING, event.player);
    ((BasicSound<?>) fx).setRoutable(true);
    getState().playSound(fx);
}
Also used : ITrackedSound(org.blockartistry.lib.sound.ITrackedSound) BasicSound(org.blockartistry.DynSurround.client.sound.BasicSound) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ITrackedSound (org.blockartistry.lib.sound.ITrackedSound)4 EntityLivingBase (net.minecraft.entity.EntityLivingBase)2 ItemStack (net.minecraft.item.ItemStack)2 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)2 SoundEffect (org.blockartistry.DynSurround.client.sound.SoundEffect)2 ISound (net.minecraft.client.audio.ISound)1 EntityBoat (net.minecraft.entity.item.EntityBoat)1 RayTraceResult (net.minecraft.util.math.RayTraceResult)1 BasicSound (org.blockartistry.DynSurround.client.sound.BasicSound)1