use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ServerCharacterPredictionSystem method onImpulse.
@ReceiveEvent(components = { CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onImpulse(CharacterImpulseEvent event, EntityRef entity) {
Vector3f impulse = event.getDirection();
CircularBuffer<CharacterStateEvent> stateBuffer = characterStates.get(entity);
CharacterStateEvent lastState = stateBuffer.getLast();
CharacterStateEvent newState = new CharacterStateEvent(lastState);
newState.setVelocity(impulse.add(newState.getVelocity()));
newState.setTime(time.getGameTimeInMs());
newState.setGrounded(false);
stateBuffer.add(newState);
characterMovementSystemUtility.setToState(entity, newState);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class InteractionSystem method onActivationPredicted.
@ReceiveEvent(components = { InteractionTargetComponent.class })
public void onActivationPredicted(ActivationPredicted event, EntityRef target) {
EntityRef character = event.getInstigator();
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
if (characterComponent == null) {
return;
}
if (characterComponent.predictedInteractionTarget.exists()) {
InteractionUtil.cancelInteractionAsClient(character);
}
if (target.exists()) {
characterComponent.predictedInteractionTarget = target;
characterComponent.predictedInteractionId = event.getActivationId();
character.saveComponent(characterComponent);
target.send(new InteractionStartPredicted(character));
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class InteractionSystem method onActivate.
@ReceiveEvent(components = { InteractionTargetComponent.class }, netFilter = RegisterMode.AUTHORITY)
public void onActivate(ActivateEvent event, EntityRef target) {
EntityRef instigator = event.getInstigator();
CharacterComponent characterComponent = instigator.getComponent(CharacterComponent.class);
if (characterComponent == null) {
logger.error("Interaction start request instigator has no character component");
return;
}
if (characterComponent.authorizedInteractionTarget.exists()) {
logger.error("Interaction wasn't finished at start of next interaction");
instigator.send(new InteractionEndEvent(characterComponent.authorizedInteractionId));
}
characterComponent.authorizedInteractionTarget = target;
characterComponent.authorizedInteractionId = event.getActivationId();
instigator.saveComponent(characterComponent);
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method updateExtentsOnBlockItemBoxShape.
@ReceiveEvent
public void updateExtentsOnBlockItemBoxShape(OnAddedComponent event, EntityRef itemEntity, BlockItemComponent blockItemComponent, BoxShapeComponent boxShapeComponent) {
BlockFamily blockFamily = blockItemComponent.blockFamily;
if (blockFamily == null) {
LOGGER.warn("Prefab " + itemEntity.getParentPrefab().getName() + " does not have a block family");
return;
}
if (blockFamily.getArchetypeBlock().getCollisionShape() instanceof BoxShape) {
BoxShape collisionShape = (BoxShape) blockFamily.getArchetypeBlock().getCollisionShape();
Vector3f extents = collisionShape.getHalfExtentsWithoutMargin();
extents.scale(2.0f);
extents.x = Math.max(extents.x, 0.5f);
extents.y = Math.max(extents.y, 0.5f);
extents.z = Math.max(extents.z, 0.5f);
boxShapeComponent.extents.set(extents);
itemEntity.saveComponent(boxShapeComponent);
}
}
use of org.terasology.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.
the class ItemPickupAuthoritySystem method onDropItemEvent.
@ReceiveEvent
public void onDropItemEvent(DropItemEvent event, EntityRef itemEntity, ItemComponent itemComponent) {
for (Component component : itemComponent.pickupPrefab.iterateComponents()) {
Component componentCopy = library.getComponentLibrary().copy(component);
if (componentCopy instanceof LocationComponent) {
((LocationComponent) componentCopy).setWorldPosition(event.getPosition());
}
itemEntity.addOrSaveComponent(componentCopy);
}
if (!itemEntity.hasComponent(LocationComponent.class)) {
itemEntity.addComponent(new LocationComponent(event.getPosition()));
}
}
Aggregations