use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onJump.
@ReceiveEvent
public void onJump(JumpEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = null;
if (characterSounds.jumpSounds.size() > 0) {
sound = random.nextItem(characterSounds.jumpSounds);
} else if (characterSounds.footstepSounds.size() > 0) {
sound = random.nextItem(characterSounds.footstepSounds);
}
if (sound != null) {
entity.send(new PlaySoundEvent(entity, sound, characterSounds.jumpVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onDeath.
@ReceiveEvent
public void onDeath(DoDestroyEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
if (characterSounds.deathSounds.size() > 0) {
StaticSound sound = random.nextItem(characterSounds.deathSounds);
entity.send(new PlaySoundEvent(entity, sound, characterSounds.deathVolume));
}
}
use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onFootstep.
@ReceiveEvent
public void onFootstep(FootstepEvent event, EntityRef entity, LocationComponent locationComponent, CharacterSoundComponent characterSounds) {
List<StaticSound> footstepSounds = characterSounds.footstepSounds;
// Check if the block the character is standing on has footstep sounds
Vector3i blockPos = new Vector3i(locationComponent.getLocalPosition());
// The block *below* the character's feet is interesting to us
blockPos.y--;
Block block = worldProvider.getBlock(blockPos);
if (block != null) {
if (block.getSounds() == null) {
logger.error("Block '{}' has no sounds", block.getURI());
} else if (!block.getSounds().getStepSounds().isEmpty()) {
footstepSounds = block.getSounds().getStepSounds();
}
}
if (footstepSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = random.nextItem(footstepSounds);
entity.send(new PlaySoundEvent(entity, sound, characterSounds.footstepVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onRespawn.
@ReceiveEvent
public void onRespawn(OnPlayerRespawnedEvent event, EntityRef character, CharacterSoundComponent characterSounds) {
if (characterSounds.respawnSounds.size() > 0) {
StaticSound sound = random.nextItem(characterSounds.respawnSounds);
character.send(new PlaySoundEvent(character, sound, characterSounds.respawnVolume));
}
}
use of org.terasology.audio.StaticSound in project Terasology by MovingBlocks.
the class ExplosionAuthoritySystem method onActivateFuseOnBlock.
@ReceiveEvent(components = ItemComponent.class)
public void onActivateFuseOnBlock(ActivateEvent event, EntityRef entityRef, TimedExplosionComponent timedExplosionComponent) {
if (event.getTarget().hasComponent(BlockComponent.class) && event.getTarget().hasComponent(ExplosionActionComponent.class) && !event.getTarget().hasComponent(TimedExplosionComponent.class)) {
Optional<StaticSound> fuseBurningSound = Assets.getSound("core:FuseBurning");
if (fuseBurningSound.isPresent()) {
event.getTarget().send(new PlaySoundEvent(fuseBurningSound.get(), 1f));
}
// add a timed explosion to the block so that it stays active
event.getTarget().addComponent(new TimedExplosionComponent());
delayManager.addDelayedAction(event.getTarget(), DELAYED_EXPLOSION_ACTION_ID, timedExplosionComponent.fuseTimeMs);
}
}
Aggregations