use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class BlockItemSystem method onPlaceBlock.
@ReceiveEvent(components = { BlockItemComponent.class, ItemComponent.class })
public void onPlaceBlock(ActivateEvent event, EntityRef item) {
if (!event.getTarget().exists()) {
event.consume();
return;
}
BlockItemComponent blockItem = item.getComponent(BlockItemComponent.class);
BlockFamily type = blockItem.blockFamily;
Side surfaceSide = Side.inDirection(event.getHitNormal());
Side secondaryDirection = ChunkMath.getSecondaryPlacementDirection(event.getDirection(), event.getHitNormal());
BlockComponent blockComponent = event.getTarget().getComponent(BlockComponent.class);
if (blockComponent == null) {
// If there is no block there (i.e. it's a BlockGroup, we don't allow placing block, try somewhere else)
event.consume();
return;
}
Vector3i targetBlock = blockComponent.getPosition();
Vector3i placementPos = new Vector3i(targetBlock);
placementPos.add(surfaceSide.getVector3i());
Block block = type.getBlockForPlacement(worldProvider, blockEntityRegistry, placementPos, surfaceSide, secondaryDirection);
if (canPlaceBlock(block, targetBlock, placementPos)) {
// TODO: Fix this for changes.
if (networkSystem.getMode().isAuthority()) {
PlaceBlocks placeBlocks = new PlaceBlocks(placementPos, block, event.getInstigator());
worldProvider.getWorldEntity().send(placeBlocks);
if (!placeBlocks.isConsumed()) {
item.send(new OnBlockItemPlaced(placementPos, blockEntityRegistry.getBlockEntityAt(placementPos)));
} else {
event.consume();
}
}
recordBlockPlaced(event, type);
event.getInstigator().send(new PlaySoundEvent(Assets.getSound("engine:PlaceBlock").get(), 0.5f));
} else {
event.consume();
}
}
use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onPlayerDeath.
@ReceiveEvent
public void onPlayerDeath(PlayerDeathEvent event, EntityRef character) {
CharacterSoundComponent characterSounds = character.getComponent(CharacterSoundComponent.class);
if (characterSounds.deathSounds.size() > 0) {
StaticSound sound = random.nextItem(characterSounds.deathSounds);
character.send(new PlaySoundEvent(character, sound, characterSounds.deathVolume));
}
}
use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onSwimStroke.
@ReceiveEvent
public void onSwimStroke(SwimStrokeEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
if (characterSounds.swimSounds.size() > 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = random.nextItem(characterSounds.swimSounds);
entity.send(new PlaySoundEvent(entity, sound, characterSounds.swimmingVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onLanded.
@ReceiveEvent
public void onLanded(VerticalCollisionEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
Vector3f velocity = event.getVelocity();
float soundVolumeModifier = (velocity.y * -1 - LANDING_VELOCITY_THRESHOLD) * LANDING_VOLUME_MODIFIER;
if (soundVolumeModifier <= 0f) {
return;
}
if (soundVolumeModifier > LANDING_VOLUME_MAX) {
soundVolumeModifier = LANDING_VOLUME_MAX;
}
if (characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
StaticSound sound = null;
if (characterSounds.landingSounds.size() > 0) {
sound = random.nextItem(characterSounds.landingSounds);
} else if (characterSounds.footstepSounds.size() > 0) {
sound = random.nextItem(characterSounds.footstepSounds);
}
if (sound != null) {
entity.send(new PlaySoundEvent(entity, sound, characterSounds.landingVolume * soundVolumeModifier));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
use of org.terasology.audio.events.PlaySoundEvent in project Terasology by MovingBlocks.
the class CharacterSoundSystem method onEnterBlock.
@ReceiveEvent
public void onEnterBlock(OnEnterBlockEvent event, EntityRef entity, CharacterSoundComponent characterSounds) {
// only play this sound if the feet hit the water
if (event.getCharacterRelativePosition().y == 0 && characterSounds.lastSoundTime + MIN_TIME < time.getGameTimeInMs()) {
boolean oldBlockIsLiquid = event.getOldBlock().isLiquid();
boolean newBlockIsLiquid = event.getNewBlock().isLiquid();
StaticSound sound = null;
if (!oldBlockIsLiquid && newBlockIsLiquid) {
sound = random.nextItem(characterSounds.enterWaterSounds);
} else if (oldBlockIsLiquid && !newBlockIsLiquid) {
sound = random.nextItem(characterSounds.leaveWaterSounds);
}
if (sound != null) {
entity.send(new PlaySoundEvent(entity, sound, characterSounds.diveVolume));
characterSounds.lastSoundTime = time.getGameTimeInMs();
entity.saveComponent(characterSounds);
}
}
}
Aggregations