use of org.terasology.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.entitySystem.event.ReceiveEvent 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.entitySystem.event.ReceiveEvent 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.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSystem method onAttackRequest.
@ReceiveEvent(components = LocationComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onAttackRequest(AttackRequest event, EntityRef character, CharacterComponent characterComponent) {
// if an item is used, make sure this entity is allowed to attack with it
if (event.getItem().exists()) {
if (!character.equals(event.getItem().getOwner())) {
return;
}
}
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
character.send(onItemUseEvent);
if (!onItemUseEvent.isConsumed()) {
EntityRef gazeEntity = GazeAuthoritySystem.getGazeEntityForCharacter(character);
LocationComponent gazeLocation = gazeEntity.getComponent(LocationComponent.class);
Vector3f direction = gazeLocation.getWorldDirection();
Vector3f originPos = gazeLocation.getWorldPosition();
HitResult result = physics.rayTrace(originPos, direction, characterComponent.interactionRange, Sets.newHashSet(character), DEFAULTPHYSICSFILTER);
if (result.isHit()) {
result.getEntity().send(new AttackEvent(character, event.getItem()));
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSystem method onActivationRequest.
@ReceiveEvent(components = { CharacterComponent.class, LocationComponent.class }, netFilter = RegisterMode.AUTHORITY)
public void onActivationRequest(ActivationRequest event, EntityRef character) {
if (isPredictionOfEventCorrect(character, event)) {
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
event.getInstigator().send(onItemUseEvent);
if (!onItemUseEvent.isConsumed()) {
if (event.getUsedOwnedEntity().exists()) {
event.getUsedOwnedEntity().send(new ActivateEvent(event));
} else {
event.getTarget().send(new ActivateEvent(event));
}
}
} else {
character.send(new ActivationRequestDenied(event.getActivationId()));
}
}
Aggregations