use of org.terasology.engine.logic.characters.CharacterComponent in project Anatomy by Terasology.
the class AnatomyScreenWindow method onOpened.
@Override
public void onOpened() {
EntityRef characterEntity = CoreRegistry.get(LocalPlayer.class).getCharacterEntity();
CharacterComponent characterComponent = characterEntity.getComponent(CharacterComponent.class);
// In case the player has been created yet, exit out early to prevent an error.
if (characterComponent == null) {
return;
}
// erroneously marked as existent.
if (!player.exists() || (player.exists() && (player == EntityRef.NULL || player.getId() == 0 || player == null))) {
reInit();
}
// As long as there's an interaction target, open this window.
if (getInteractionTarget() != EntityRef.NULL) {
initializeWithInteractionTarget(getInteractionTarget());
super.onOpened();
}
// Every time the character screen window is opened, update the Anatomy part statuses.
updateStatuses();
}
use of org.terasology.engine.logic.characters.CharacterComponent in project Terasology by MovingBlocks.
the class PlayerTargetSystem method update.
@Override
public void update(float delta) {
EntityRef charEntity = player.getCharacterEntity();
if (charEntity.exists()) {
Vector3f cameraPos = player.getViewPosition(new Vector3f());
CharacterComponent charComp = charEntity.getComponent(CharacterComponent.class);
if (charComp != null) {
Vector3f dir = player.getViewDirection(new Vector3f());
float maxDist = charComp.interactionRange;
FirstPersonHeldItemMountPointComponent heldItemMountPoint = player.getCameraEntity().getComponent(FirstPersonHeldItemMountPointComponent.class);
if (heldItemMountPoint != null && heldItemMountPoint.isTracked()) {
maxDist = heldItemMountPoint.translate.length() + 0.25f;
dir = new Vector3f(heldItemMountPoint.translate).normalize();
}
if (targetSystem.updateTarget(cameraPos, dir, maxDist)) {
EntityRef oldTarget = targetSystem.getPreviousTarget();
EntityRef newTarget = targetSystem.getTarget();
charEntity.send(new PlayerTargetChangedEvent(oldTarget, newTarget));
}
}
}
}
use of org.terasology.engine.logic.characters.CharacterComponent in project Terasology by MovingBlocks.
the class InteractionSystem method onActivate.
@ReceiveEvent(components = InteractionTargetComponent.class, netFilter = RegisterMode.AUTHORITY)
public void onActivate(ActivateEvent event, EntityRef target) {
EntityRef instigator = event.getInstigator();
CharacterComponent characterComponent = instigator.getComponent(CharacterComponent.class);
if (characterComponent == null) {
logger.error("Interaction start request instigator has no character component");
return;
}
if (characterComponent.authorizedInteractionTarget.exists()) {
logger.error("Interaction wasn't finished at start of next interaction");
instigator.send(new InteractionEndEvent(characterComponent.authorizedInteractionId));
}
characterComponent.authorizedInteractionTarget = target;
characterComponent.authorizedInteractionId = event.getActivationId();
instigator.saveComponent(characterComponent);
}
use of org.terasology.engine.logic.characters.CharacterComponent in project Terasology by MovingBlocks.
the class InteractionSystem method onActivationPredicted.
@ReceiveEvent(components = InteractionTargetComponent.class)
public void onActivationPredicted(ActivationPredicted event, EntityRef target) {
EntityRef character = event.getInstigator();
CharacterComponent characterComponent = character.getComponent(CharacterComponent.class);
if (characterComponent == null) {
return;
}
if (characterComponent.predictedInteractionTarget.exists()) {
InteractionUtil.cancelInteractionAsClient(character);
}
if (target.exists()) {
characterComponent.predictedInteractionTarget = target;
characterComponent.predictedInteractionId = event.getActivationId();
character.saveComponent(characterComponent);
target.send(new InteractionStartPredicted(character));
}
}
use of org.terasology.engine.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);
}
}
Aggregations