Search in sources :

Example 56 with ReceiveEvent

use of org.terasology.engine.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);
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 57 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class VisualCharacterSystem method onCreateDefaultVisualCharacter.

@ReceiveEvent(priority = EventPriority.PRIORITY_TRIVIAL)
public void onCreateDefaultVisualCharacter(CreateVisualCharacterEvent event, EntityRef characterEntity) {
    Prefab prefab = assetManager.getAsset("engine:defaultVisualCharacter", Prefab.class).get();
    EntityBuilder entityBuilder = event.getVisualCharacterBuilder();
    entityBuilder.addPrefab(prefab);
    event.consume();
}
Also used : EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) Prefab(org.terasology.engine.entitySystem.prefab.Prefab) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 58 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class PlayerSystem method setSpawnLocationOnRespawnRequest.

@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
    ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
    EntityRef character = clientComponent.character;
    EntityRef clientInfo = clientComponent.clientInfo;
    Vector3fc spawnPosition;
    if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
        spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
    } else {
        spawnPosition = worldGenerator.getSpawnPosition(entity);
    }
    LocationComponent loc = character.getComponent(LocationComponent.class);
    loc.setWorldPosition(spawnPosition);
    // reset rotation
    loc.setLocalRotation(new Quaternionf());
    character.saveComponent(loc);
}
Also used : Vector3fc(org.joml.Vector3fc) Quaternionf(org.joml.Quaternionf) ClientComponent(org.terasology.engine.network.ClientComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 59 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class LocalPlayerBlockSelectionByItemSystem method onCamTargetChanged.

@ReceiveEvent(components = LocationComponent.class)
public void onCamTargetChanged(CameraTargetChangedEvent event, EntityRef entity) {
    // This method will update the block selection to whatever block is targeted in the players view
    if (null == blockSelectionComponentEntity) {
        return;
    }
    BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
    if (blockSelectionComponent == null) {
        return;
    }
    EntityRef target = event.getNewTarget();
    LocationComponent locationComponent = target.getComponent(LocationComponent.class);
    if (locationComponent == null) {
        return;
    }
    Vector3f targetLocation = locationComponent.getWorldPosition(new Vector3f());
    if (blockSelectionComponent.isMovable) {
        Vector3i pos = new Vector3i(targetLocation, RoundingMode.FLOOR);
        Vector3i size = blockSelectionComponent.currentSelection.getSize(new Vector3i());
        blockSelectionComponent.currentSelection.set(pos, pos).expand(size.x() / 2, 0, size.z() / 2);
        blockSelectionComponentEntity.saveComponent(blockSelectionComponent);
        return;
    }
    if (blockSelectionComponent.startPosition == null) {
        return;
    }
    target.send(new SetBlockSelectionEndingPointEvent(blockSelectionComponentEntity));
}
Also used : SetBlockSelectionEndingPointEvent(org.terasology.engine.world.selection.event.SetBlockSelectionEndingPointEvent) BlockSelectionComponent(org.terasology.engine.world.selection.BlockSelectionComponent) Vector3f(org.joml.Vector3f) Vector3i(org.joml.Vector3i) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) LocationComponent(org.terasology.engine.logic.location.LocationComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 60 with ReceiveEvent

use of org.terasology.engine.entitySystem.event.ReceiveEvent in project Terasology by MovingBlocks.

the class LocalPlayerBlockSelectionByItemSystem method onLeftMouseButtonDown.

/**
 * This marks the end of the camera position binding with the region position.
 * @param event LeftMouseButtonDownEvent
 * @param entity Entity sending the event
 */
@ReceiveEvent
public void onLeftMouseButtonDown(LeftMouseDownButtonEvent event, EntityRef entity) {
    if (this.blockSelectionComponentEntity != null && this.blockSelectionComponentEntity != EntityRef.NULL) {
        BlockSelectionComponent blockSelectionComponent = blockSelectionComponentEntity.getComponent(BlockSelectionComponent.class);
        if (blockSelectionComponent != null && blockSelectionComponent.isMovable) {
            blockSelectionComponentEntity.send(new MovableSelectionEndEvent(blockSelectionComponent.currentSelection));
            blockSelectionComponentEntity.destroy();
        }
    }
}
Also used : BlockSelectionComponent(org.terasology.engine.world.selection.BlockSelectionComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)83 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)27 Vector3f (org.joml.Vector3f)18 LocationComponent (org.terasology.engine.logic.location.LocationComponent)12 Vector3i (org.joml.Vector3i)10 StaticSound (org.terasology.engine.audio.StaticSound)10 Vector3ic (org.joml.Vector3ic)9 PlaySoundEvent (org.terasology.engine.audio.events.PlaySoundEvent)9 ClientComponent (org.terasology.engine.network.ClientComponent)8 Quaternionf (org.joml.Quaternionf)6 BlockComponent (org.terasology.engine.world.block.BlockComponent)6 OnItemUseEvent (org.terasology.engine.logic.characters.events.OnItemUseEvent)5 Block (org.terasology.engine.world.block.Block)5 CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)4 BlockRegion (org.terasology.engine.world.block.BlockRegion)4 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)3 BlockRegionComponent (org.terasology.engine.world.block.regions.BlockRegionComponent)3 Component (org.terasology.gestalt.entitysystem.component.Component)3 Method (java.lang.reflect.Method)2 Vector3fc (org.joml.Vector3fc)2