use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class DoorSystem method closeDoor.
@ReceiveEvent
public void closeDoor(CloseDoorEvent event, EntityRef player) {
EntityRef entity = event.getDoorEntity();
DoorComponent door = entity.getComponent(DoorComponent.class);
Side newSide = door.closedSide;
BlockRegionComponent regionComp = entity.getComponent(BlockRegionComponent.class);
Block bottomBlock = door.bottomBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.min(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.min(), bottomBlock);
Block topBlock = door.topBlockFamily.getBlockForPlacement(worldProvider, blockEntityRegistry, regionComp.region.max(), newSide, Side.TOP);
worldProvider.setBlock(regionComp.region.max(), topBlock);
if (door.closeSound != null) {
entity.send(new PlaySoundEvent(door.closeSound, 1f));
}
door.isOpen = false;
entity.saveComponent(door);
}
use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class ExplosionAuthoritySystem method doExplosion.
void doExplosion(ExplosionActionComponent explosionComp, Vector3f origin, EntityRef instigatingBlockEntity) {
EntityBuilder builder = entityManager.newBuilder("core:smokeExplosion");
builder.getComponent(LocationComponent.class).setWorldPosition(origin);
EntityRef smokeEntity = builder.build();
smokeEntity.send(new PlaySoundEvent(getRandomExplosionSound(), 1f));
Vector3i blockPos = new Vector3i();
for (int i = 0; i < explosionComp.maxRange; i++) {
Vector3f direction = random.nextVector3f(1.0f);
for (int j = 0; j < 4; j++) {
Vector3f target = new Vector3f(origin);
target.x += direction.x * j;
target.y += direction.y * j;
target.z += direction.z * j;
blockPos.set((int) target.x, (int) target.y, (int) target.z);
Block currentBlock = worldProvider.getBlock(blockPos);
/* PHYSICS */
if (currentBlock.isDestructible()) {
EntityRef blockEntity = blockEntityRegistry.getEntityAt(blockPos);
// allow explosions to chain together, but do not chain on the instigating block
if (!blockEntity.equals(instigatingBlockEntity) && blockEntity.hasComponent(ExplosionActionComponent.class)) {
doExplosion(blockEntity.getComponent(ExplosionActionComponent.class), blockPos.toVector3f(), blockEntity);
} else {
blockEntity.send(new DoDamageEvent(explosionComp.damageAmount, explosionComp.damageType));
}
}
}
}
}
use of org.terasology.audio.events.PlaySoundEvent 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);
}
}
use of org.terasology.audio.events.PlaySoundEvent 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.PlaySoundEvent in project Terasology by MovingBlocks.
the class BlockEntitySystem method commonDestroyed.
private void commonDestroyed(DoDestroyEvent event, EntityRef entity, Block block) {
entity.send(new CreateBlockDropsEvent(event.getInstigator(), event.getDirectCause(), event.getDamageType()));
BlockDamageModifierComponent blockDamageModifierComponent = event.getDamageType().getComponent(BlockDamageModifierComponent.class);
// TODO: Configurable via block definition
if (blockDamageModifierComponent == null || !blockDamageModifierComponent.skipPerBlockEffects) {
// dust particle effect
if (entity.hasComponent(LocationComponent.class) && block.isDebrisOnDestroy()) {
EntityBuilder dustBuilder = entityManager.newBuilder("core:dustEffect");
// TODO: particle system stuff should be split out better - this is effectively a stealth dependency on Core from the engine
if (dustBuilder.hasComponent(LocationComponent.class)) {
dustBuilder.getComponent(LocationComponent.class).setWorldPosition(entity.getComponent(LocationComponent.class).getWorldPosition());
dustBuilder.build();
}
}
// sound to play for destroyed block
BlockSounds sounds = block.getSounds();
if (!sounds.getDestroySounds().isEmpty()) {
StaticSound sound = random.nextItem(sounds.getDestroySounds());
entity.send(new PlaySoundEvent(sound, 0.6f));
}
}
}
Aggregations