use of org.terasology.audio.events.PlaySoundForOwnerEvent in project Terasology by MovingBlocks.
the class HealthAuthoritySystem method onDamaged.
@ReceiveEvent
public void onDamaged(OnDamagedEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
if (characterSounds.lastSoundTime + CharacterSoundSystem.MIN_TIME < time.getGameTimeInMs()) {
// play the sound of damage hitting the character for everyone
DamageSoundComponent damageSounds = event.getType().getComponent(DamageSoundComponent.class);
if (damageSounds != null && !damageSounds.sounds.isEmpty()) {
StaticSound sound = random.nextItem(damageSounds.sounds);
if (sound != null) {
entity.send(new PlaySoundEvent(sound, 1f));
}
}
// play the sound of a client's character being damaged to the client
if (!characterSounds.damageSounds.isEmpty()) {
StaticSound sound = random.nextItem(characterSounds.damageSounds);
if (sound != null) {
entity.send(new PlaySoundForOwnerEvent(sound, characterSounds.damageVolume));
}
}
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
use of org.terasology.audio.events.PlaySoundForOwnerEvent in project Terasology by MovingBlocks.
the class CharacterInventorySystem method onGiveItemToEntity.
@ReceiveEvent(netFilter = RegisterMode.AUTHORITY)
public void onGiveItemToEntity(GiveItemEvent event, EntityRef entity) {
if (event.getTargetEntity().hasComponent(InventoryComponent.class)) {
if (inventoryManager.giveItem(event.getTargetEntity(), entity, entity)) {
event.getTargetEntity().send(new PlaySoundForOwnerEvent(Assets.getSound("engine:Loot").get(), 1.0f));
event.setHandled(true);
}
}
}
Aggregations