Search in sources :

Example 66 with ReceiveEvent

use of org.terasology.engine.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.engine.rendering.nui.layers.ingame.DeathScreen) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 67 with ReceiveEvent

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

the class ThirdPersonRemoteClientSystem method ensureClientSideEntityOnHeldItemMountPoint.

/**
 * Ensures held item mount point entity exists, attaches it to the character and sets its transform.
 *
 * @param event the activation that triggered the need to consider changing a held item
 * @param character the character for which we need to consider the held item
 * @param remotePersonHeldItemMountPointComponent data for the mount point on the remote character
 */
@ReceiveEvent
public void ensureClientSideEntityOnHeldItemMountPoint(OnActivatedComponent event, EntityRef character, RemotePersonHeldItemMountPointComponent remotePersonHeldItemMountPointComponent) {
    if (relatesToLocalPlayer(character)) {
        logger.debug("ensureClientSideEntityOnHeldItemMountPoint found its given character to relate to the local" + " player, ignoring: {}", character);
        return;
    }
    // In case we haven't dealt with a given remote player yet set up a non-persistent mount point
    if (!remotePersonHeldItemMountPointComponent.mountPointEntity.exists()) {
        EntityBuilder builder = entityManager.newBuilder("engine:RemotePersonHeldItemMountPoint");
        builder.setPersistent(false);
        remotePersonHeldItemMountPointComponent.mountPointEntity = builder.build();
        character.saveComponent(remotePersonHeldItemMountPointComponent);
    }
    // Link the mount point entity to the camera
    Location.removeChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity);
    Location.attachChild(character, remotePersonHeldItemMountPointComponent.mountPointEntity, remotePersonHeldItemMountPointComponent.translate, new Quaternionf().rotationYXZ(Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.y), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.x), Math.toRadians(remotePersonHeldItemMountPointComponent.rotateDegrees.z)), remotePersonHeldItemMountPointComponent.scale);
}
Also used : Quaternionf(org.joml.Quaternionf) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 68 with ReceiveEvent

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

the class ThirdPersonRemoteClientSystem method ensureHeldItemIsMountedOnLoad.

@ReceiveEvent
public void ensureHeldItemIsMountedOnLoad(OnChangedComponent event, EntityRef clientEntity, ClientComponent clientComponent) {
    if (relatesToLocalPlayer(clientEntity)) {
        logger.debug("ensureHeldItemIsMountedOnLoad found its given clientEntity to relate to the local player, " + "ignoring: {}", clientEntity);
        return;
    }
    if (clientEntity.exists() && clientComponent.character != EntityRef.NULL) {
        logger.debug("ensureHeldItemIsMountedOnLoad says a given clientEntity exists, has a character, and isn't " + "related to the local player: {}", clientEntity);
        CharacterHeldItemComponent characterHeldItemComponent = clientComponent.character.getComponent(CharacterHeldItemComponent.class);
        if (characterHeldItemComponent != null && !(clientComponent.character.equals(localPlayer.getCharacterEntity()))) {
            linkHeldItemLocationForRemotePlayer(characterHeldItemComponent.selectedItem, clientComponent.character);
        }
    } else {
        logger.debug("ensureHeldItemIsMountedOnLoad given a remote client, but one that didn't properly exist?");
    }
}
Also used : CharacterHeldItemComponent(org.terasology.engine.logic.characters.CharacterHeldItemComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 69 with ReceiveEvent

use of org.terasology.engine.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 Quaternionf().rotationYXZ(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 : Quaternionf(org.joml.Quaternionf) EntityBuilder(org.terasology.engine.entitySystem.entity.EntityBuilder) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 70 with ReceiveEvent

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

the class FirstPersonClientSystem method onHeldItemActivated.

@ReceiveEvent
public void onHeldItemActivated(OnActivatedComponent event, EntityRef character, CharacterHeldItemComponent heldItemComponent, CharacterComponent characterComponents) {
    if (localPlayer.getCharacterEntity().equals(character)) {
        EntityRef newItem = heldItemComponent.selectedItem;
        linkHeldItemLocationForLocalPlayer(newItem);
    }
}
Also used : EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) 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