use of org.terasology.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.entitySystem.event.ReceiveEvent 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);
}
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSystem method onAttackRequest.
@ReceiveEvent(components = { CharacterComponent.class }, netFilter = RegisterMode.CLIENT)
public void onAttackRequest(AttackButton event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
if (!event.isDown()) {
return;
}
boolean attackRequestIsValid;
if (networkSystem.getMode().isAuthority()) {
// Let the AttackRequest handler trigger the OnItemUseEvent if this is a local client
attackRequestIsValid = true;
} else {
OnItemUseEvent onItemUseEvent = new OnItemUseEvent();
entity.send(onItemUseEvent);
attackRequestIsValid = !onItemUseEvent.isConsumed();
}
if (attackRequestIsValid) {
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
entity.send(new AttackRequest(selectedItemEntity));
event.consume();
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class CharacterSystem method onItemUse.
@ReceiveEvent(components = { CharacterComponent.class })
public void onItemUse(OnItemUseEvent event, EntityRef entity, CharacterHeldItemComponent characterHeldItemComponent) {
long currentTime = time.getGameTimeInMs();
if (characterHeldItemComponent.nextItemUseTime > currentTime) {
// this character is not yet ready to use another item, they are still cooling down from last use
event.consume();
return;
}
EntityRef selectedItemEntity = characterHeldItemComponent.selectedItem;
characterHeldItemComponent.lastItemUsedTime = currentTime;
characterHeldItemComponent.nextItemUseTime = currentTime;
ItemComponent itemComponent = selectedItemEntity.getComponent(ItemComponent.class);
// Add the cooldown time for the next use of this item.
if (itemComponent != null) {
// Send out this event so other systems can alter the cooldown time.
AffectItemUseCooldownTimeEvent affectItemUseCooldownTimeEvent = new AffectItemUseCooldownTimeEvent(itemComponent.cooldownTime);
entity.send(affectItemUseCooldownTimeEvent);
characterHeldItemComponent.nextItemUseTime += affectItemUseCooldownTimeEvent.getResultValue();
} else {
characterHeldItemComponent.nextItemUseTime += 200;
}
entity.saveComponent(characterHeldItemComponent);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ClientCharacterPredictionSystem method onDestroy.
@ReceiveEvent(components = { CharacterComponent.class, CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onDestroy(final BeforeDeactivateComponent event, final EntityRef entity) {
CharacterComponent character = entity.getComponent(CharacterComponent.class);
ClientComponent controller = character.controller.getComponent(ClientComponent.class);
if (controller != null && controller.local) {
predictedState = null;
authoritiveState = null;
inputs.clear();
}
physics.removeCharacterCollider(entity);
playerStates.remove(entity);
}
Aggregations