Search in sources :

Example 71 with ReceiveEvent

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);
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 72 with ReceiveEvent

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));
    }
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 73 with ReceiveEvent

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);
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 74 with ReceiveEvent

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);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) BlockFamily(org.terasology.world.block.family.BlockFamily) BoxShape(org.terasology.physics.shapes.BoxShape) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 75 with ReceiveEvent

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()));
    }
}
Also used : LocationComponent(org.terasology.logic.location.LocationComponent) RigidBodyComponent(org.terasology.physics.components.RigidBodyComponent) OnAddedComponent(org.terasology.entitySystem.entity.lifecycleEvents.OnAddedComponent) Component(org.terasology.entitySystem.Component) BoxShapeComponent(org.terasology.physics.components.shapes.BoxShapeComponent) BlockItemComponent(org.terasology.world.block.items.BlockItemComponent) LocationComponent(org.terasology.logic.location.LocationComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)98 EntityRef (org.terasology.entitySystem.entity.EntityRef)36 Vector3f (org.terasology.math.geom.Vector3f)26 LocationComponent (org.terasology.logic.location.LocationComponent)17 Vector3i (org.terasology.math.geom.Vector3i)17 PlaySoundEvent (org.terasology.audio.events.PlaySoundEvent)15 StaticSound (org.terasology.audio.StaticSound)13 Block (org.terasology.world.block.Block)11 ClientComponent (org.terasology.network.ClientComponent)7 BlockComponent (org.terasology.world.block.BlockComponent)7 BlockRegionComponent (org.terasology.world.block.regions.BlockRegionComponent)7 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)5 CharacterComponent (org.terasology.logic.characters.CharacterComponent)4 OnItemUseEvent (org.terasology.logic.characters.events.OnItemUseEvent)4 ResourceUrn (org.terasology.assets.ResourceUrn)3 Component (org.terasology.entitySystem.Component)3 ItemComponent (org.terasology.logic.inventory.ItemComponent)3 Side (org.terasology.math.Side)3 BoneHealthChangedEvent (org.terasology.anatomy.AnatomySkeleton.event.BoneHealthChangedEvent)2 PartSkeletalDetails (org.terasology.anatomy.component.PartSkeletalDetails)2