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;
}
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;
}
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);
}
}
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);
}
}
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));
}
Aggregations