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