use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class BlockSelectionSystem method onStartSelectionAtEntity.
@ReceiveEvent
public void onStartSelectionAtEntity(SetBlockSelectionStartingPointEvent event, EntityRef entity, LocationComponent locationComponent) {
if (null == locationComponent) {
// entity isn't LocationComponent, which shouldn't ever be the case
return;
}
BlockSelectionComponent blockSelectionComponent = event.getBlockSelectionComponent();
if (null == blockSelectionComponent) {
// event did not provide a BlockSelection component to modify
return;
}
Vector3i startPosition = new Vector3i(locationComponent.getWorldPosition(new Vector3f()), RoundingMode.FLOOR);
blockSelectionComponent.startPosition = startPosition;
blockSelectionComponent.currentSelection = new BlockRegion(startPosition);
}
use of org.terasology.engine.entitySystem.event.ReceiveEvent 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.engine.entitySystem.event.ReceiveEvent 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.engine.entitySystem.event.ReceiveEvent 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.engine.entitySystem.event.ReceiveEvent 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);
}
}
Aggregations