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;
}
}
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());
}
}
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;
}
}
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);
}
Aggregations