Search in sources :

Example 1 with CharacterComponent

use of org.terasology.logic.characters.CharacterComponent in project Terasology by MovingBlocks.

the class BaseInteractionScreen method getInteractionTarget.

protected EntityRef getInteractionTarget() {
    EntityRef characterEntity = localPlayer.getCharacterEntity();
    CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
    return characterComponent.predictedInteractionTarget;
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 2 with CharacterComponent

use of org.terasology.logic.characters.CharacterComponent in project Terasology by MovingBlocks.

the class PlayerSystem method restoreCharacter.

private void restoreCharacter(EntityRef entity, EntityRef character) {
    Client clientListener = networkSystem.getOwner(entity);
    updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());
    ClientComponent client = entity.getComponent(ClientComponent.class);
    client.character = character;
    entity.saveComponent(client);
    CharacterComponent characterComp = character.getComponent(CharacterComponent.class);
    if (characterComp != null) {
        characterComp.controller = entity;
        character.saveComponent(characterComp);
        character.setOwner(entity);
        if (!character.hasComponent(AliveCharacterComponent.class)) {
            character.addComponent(new AliveCharacterComponent());
        }
        Location.attachChild(character, entity, new Vector3f(), new Quat4f(0, 0, 0, 1));
    } else {
        character.destroy();
        spawnPlayer(entity);
    }
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) CharacterComponent(org.terasology.logic.characters.CharacterComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Client(org.terasology.network.Client) ClientComponent(org.terasology.network.ClientComponent) AliveCharacterComponent(org.terasology.logic.characters.AliveCharacterComponent) Quat4f(org.terasology.math.geom.Quat4f)

Example 3 with CharacterComponent

use of org.terasology.logic.characters.CharacterComponent in project Terasology by MovingBlocks.

the class InteractionSystem method onInteractionStartPredicted.

@ReceiveEvent(components = { InteractionScreenComponent.class })
public void onInteractionStartPredicted(InteractionStartPredicted event, EntityRef container, InteractionScreenComponent interactionScreenComponent) {
    EntityRef investigator = event.getInstigator();
    CharacterComponent characterComponent = investigator.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        logger.error("Interaction start predicted for entity without character component");
        return;
    }
    ClientComponent controller = characterComponent.controller.getComponent(ClientComponent.class);
    if (controller != null && controller.local) {
        nuiManager.closeAllScreens();
        nuiManager.pushScreen(interactionScreenComponent.screen);
    }
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 4 with CharacterComponent

use of org.terasology.logic.characters.CharacterComponent in project Terasology by MovingBlocks.

the class InteractionUtil method cancelInteractionAsServer.

public static void cancelInteractionAsServer(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        logger.error("Interaction end request instigator has no character component");
        return;
    }
    int oldInteractionId = characterComponent.authorizedInteractionId;
    EntityRef oldTarget = characterComponent.authorizedInteractionTarget;
    if (oldTarget.exists()) {
        characterComponent.authorizedInteractionTarget = EntityRef.NULL;
        character.saveComponent(characterComponent);
    }
    character.send(new InteractionEndEvent(oldInteractionId));
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 5 with CharacterComponent

use of org.terasology.logic.characters.CharacterComponent in project Terasology by MovingBlocks.

the class InteractionUtil method getActiveInteractionScreenUri.

/**
 * @return the active interaction screen uri of the specified character.
 * The method returns null if the player has no interaction screen open.
 * The method is only intended to be called for the own character.
 */
public static ResourceUrn getActiveInteractionScreenUri(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        return null;
    }
    EntityRef interactionTarget = characterComponent.predictedInteractionTarget;
    if (!interactionTarget.exists()) {
        return null;
    }
    InteractionScreenComponent screenComponent = interactionTarget.getComponent(InteractionScreenComponent.class);
    if (screenComponent == null) {
        return null;
    }
    return new ResourceUrn(screenComponent.screen);
}
Also used : CharacterComponent(org.terasology.logic.characters.CharacterComponent) ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Aggregations

CharacterComponent (org.terasology.logic.characters.CharacterComponent)12 EntityRef (org.terasology.entitySystem.entity.EntityRef)11 Vector3f (org.terasology.math.geom.Vector3f)4 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)3 Quat4f (org.terasology.math.geom.Quat4f)2 ClientComponent (org.terasology.network.ClientComponent)2 ArrayList (java.util.ArrayList)1 ResourceUrn (org.terasology.assets.ResourceUrn)1 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)1 AliveCharacterComponent (org.terasology.logic.characters.AliveCharacterComponent)1 ActivationPredicted (org.terasology.logic.characters.events.ActivationPredicted)1 ActivationRequest (org.terasology.logic.characters.events.ActivationRequest)1 InventoryComponent (org.terasology.logic.inventory.InventoryComponent)1 InventoryManager (org.terasology.logic.inventory.InventoryManager)1 LocationComponent (org.terasology.logic.location.LocationComponent)1 FirstPersonHeldItemMountPointComponent (org.terasology.logic.players.FirstPersonHeldItemMountPointComponent)1 LocalPlayer (org.terasology.logic.players.LocalPlayer)1 PlayerTargetChangedEvent (org.terasology.logic.players.PlayerTargetChangedEvent)1 Client (org.terasology.network.Client)1 HitResult (org.terasology.physics.HitResult)1