Search in sources :

Example 76 with ReceiveEvent

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

the class Location method onDestroyed.

@ReceiveEvent
public void onDestroyed(BeforeRemoveComponent event, EntityRef entity, LocationComponent location) {
    if (location.parent.exists()) {
        removeChild(location.parent, entity);
    }
    Iterator<EntityRef> childIterator = location.getChildren().iterator();
    while (childIterator.hasNext()) {
        EntityRef child = childIterator.next();
        LocationComponent childLoc = child.getComponent(LocationComponent.class);
        if (childLoc != null) {
            Vector3f oldWorldPos = childLoc.getWorldPosition();
            childLoc.parent = EntityRef.NULL;
            childLoc.setWorldPosition(oldWorldPos);
            child.saveComponent(childLoc);
        }
        childIterator.remove();
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 77 with ReceiveEvent

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

the class FirstPersonClientSystem method ensureClientSideEntityOnHeldItemMountPoint.

// ensures held item mount point entity exists, attaches it to the camera and sets its transform
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef camera, FirstPersonHeldItemMountPointComponent firstPersonHeldItemMountPointComponent) {
    if (!firstPersonHeldItemMountPointComponent.mountPointEntity.exists()) {
        EntityBuilder builder = entityManager.newBuilder("engine:FirstPersonHeldItemMountPoint");
        builder.setPersistent(false);
        firstPersonHeldItemMountPointComponent.mountPointEntity = builder.build();
        camera.saveComponent(firstPersonHeldItemMountPointComponent);
    }
    // link the mount point entity to the camera
    Location.removeChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity);
    Location.attachChild(camera, firstPersonHeldItemMountPointComponent.mountPointEntity, firstPersonHeldItemMountPointComponent.translate, new Quat4f(TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.y, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.x, TeraMath.DEG_TO_RAD * firstPersonHeldItemMountPointComponent.rotateDegrees.z), firstPersonHeldItemMountPointComponent.scale);
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) Quat4f(org.terasology.math.geom.Quat4f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 78 with ReceiveEvent

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

the class LocalPlayerSystem method onFrobButton.

@ReceiveEvent(components = { CharacterComponent.class })
public void onFrobButton(FrobButton event, EntityRef character) {
    if (event.getState() != ButtonState.DOWN) {
        return;
    }
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if (activeInteractionScreenUri != null) {
        InteractionUtil.cancelInteractionAsClient(character);
        return;
    }
    boolean activeRequestSent = localPlayer.activateTargetAsClient();
    if (activeRequestSent) {
        event.consume();
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 79 with ReceiveEvent

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

the class LocalPlayerSystem method onPlayerSpawn.

@ReceiveEvent
public void onPlayerSpawn(OnPlayerSpawnedEvent event, EntityRef character) {
    if (character.equals(localPlayer.getCharacterEntity())) {
        // Change height as per PlayerSettings
        Float height = config.getPlayer().getHeight();
        movementDebugCommands.playerHeight(localPlayer.getClientEntity(), height);
        // Change eyeHeight as per PlayerSettings
        Float eyeHeight = config.getPlayer().getEyeHeight();
        GazeMountPointComponent gazeMountPointComponent = character.getComponent(GazeMountPointComponent.class);
        gazeMountPointComponent.translate = new Vector3f(0, eyeHeight, 0);
        // Trigger updating the player camera position as soon as the local player is spawned.
        // This is not done while the game is still loading, since systems are not updated.
        // RenderableWorldImpl pre-generates chunks around the player camera and therefore needs
        // the correct location.
        lookYaw = 0f;
        lookPitch = 0f;
        update(0);
    }
}
Also used : GazeMountPointComponent(org.terasology.logic.characters.GazeMountPointComponent) Vector3f(org.terasology.math.geom.Vector3f) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 80 with ReceiveEvent

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

the class MenuControlSystem method onPlayerDeath.

@ReceiveEvent(components = { CharacterComponent.class })
public void onPlayerDeath(PlayerDeathEvent event, EntityRef character) {
    EntityRef client = character.getComponent(CharacterComponent.class).controller;
    if (client.getComponent(ClientComponent.class).local) {
        nuiManager.removeOverlay("engine:onlinePlayersOverlay");
        nuiManager.pushScreen("engine:deathScreen");
        if (event.damageTypeName != null) {
            ((DeathScreen) nuiManager.getScreen("engine:deathScreen")).setDeathDetails(event.instigatorName, event.damageTypeName);
        }
    }
}
Also used : DeathScreen(org.terasology.rendering.nui.layers.ingame.DeathScreen) CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) 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