Search in sources :

Example 46 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class CharacterSystem method getPlayerNameFromCharacter.

private String getPlayerNameFromCharacter(EntityRef character) {
    CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
    if (characterComponent == null) {
        return "?";
    }
    EntityRef controller = characterComponent.controller;
    ClientComponent clientComponent = controller.getComponent(ClientComponent.class);
    EntityRef clientInfo = clientComponent.clientInfo;
    DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
    if (displayNameComponent == null) {
        return "?";
    }
    return displayNameComponent.name;
}
Also used : DisplayNameComponent(org.terasology.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.entitySystem.entity.EntityRef) ClientComponent(org.terasology.network.ClientComponent)

Example 47 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class GazeAuthoritySystem method createGazeEntity.

private EntityRef createGazeEntity() {
    EntityBuilder gazeContainerBuilder = entityManager.newBuilder("engine:gaze");
    EntityRef gazeEntity = gazeContainerBuilder.build();
    return gazeEntity;
}
Also used : EntityBuilder(org.terasology.entitySystem.entity.EntityBuilder) EntityRef(org.terasology.entitySystem.entity.EntityRef)

Example 48 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef in project Terasology by MovingBlocks.

the class InteractionSystem method onScreenLayerClosed.

/**
 * The method listens for the event that the user closes the screen of the current interaction target.
 * <p>
 * When it happens then it cancels the interaction.
 */
@ReceiveEvent(components = { ClientComponent.class })
public void onScreenLayerClosed(ScreenLayerClosedEvent event, EntityRef container, ClientComponent clientComponent) {
    EntityRef character = clientComponent.character;
    ResourceUrn activeInteractionScreenUri = InteractionUtil.getActiveInteractionScreenUri(character);
    if ((activeInteractionScreenUri != null) && (activeInteractionScreenUri.equals(event.getClosedScreenUri()))) {
        InteractionUtil.cancelInteractionAsClient(clientComponent.character);
    }
}
Also used : ResourceUrn(org.terasology.assets.ResourceUrn) EntityRef(org.terasology.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.entitySystem.event.ReceiveEvent)

Example 49 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef 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 50 with EntityRef

use of org.terasology.entitySystem.entity.EntityRef 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)

Aggregations

EntityRef (org.terasology.entitySystem.entity.EntityRef)337 Test (org.junit.Test)106 ClientComponent (org.terasology.network.ClientComponent)49 LocationComponent (org.terasology.logic.location.LocationComponent)45 Vector3f (org.terasology.math.geom.Vector3f)44 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)36 Vector3i (org.terasology.math.geom.Vector3i)34 Command (org.terasology.logic.console.commandSystem.annotations.Command)28 StringComponent (org.terasology.entitySystem.stubs.StringComponent)26 NetworkComponent (org.terasology.network.NetworkComponent)21 EntityData (org.terasology.protobuf.EntityData)21 DisplayNameComponent (org.terasology.logic.common.DisplayNameComponent)17 Block (org.terasology.world.block.Block)16 Component (org.terasology.entitySystem.Component)15 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)15 CharacterComponent (org.terasology.logic.characters.CharacterComponent)14 Quat4f (org.terasology.math.geom.Quat4f)14 BlockComponent (org.terasology.world.block.BlockComponent)13 Map (java.util.Map)11 LocalPlayer (org.terasology.logic.players.LocalPlayer)11