Search in sources :

Example 1 with CharacterComponent

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();
}
Also used : LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef)

Example 2 with CharacterComponent

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));
            }
        }
    }
}
Also used : PlayerTargetChangedEvent(org.terasology.engine.logic.players.PlayerTargetChangedEvent) Vector3f(org.joml.Vector3f) CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) FirstPersonHeldItemMountPointComponent(org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent)

Example 3 with CharacterComponent

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);
}
Also used : CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 4 with 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));
    }
}
Also used : CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 5 with CharacterComponent

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);
    }
}
Also used : CharacterComponent(org.terasology.engine.logic.characters.CharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Aggregations

CharacterComponent (org.terasology.engine.logic.characters.CharacterComponent)12 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)11 Vector3f (org.joml.Vector3f)4 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)3 Quaternionf (org.joml.Quaternionf)2 ClientComponent (org.terasology.engine.network.ClientComponent)2 EntityBuilder (org.terasology.engine.entitySystem.entity.EntityBuilder)1 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)1 ActivationPredicted (org.terasology.engine.logic.characters.events.ActivationPredicted)1 ActivationRequest (org.terasology.engine.logic.characters.events.ActivationRequest)1 RangeComponent (org.terasology.engine.logic.common.RangeComponent)1 LocationComponent (org.terasology.engine.logic.location.LocationComponent)1 FirstPersonHeldItemMountPointComponent (org.terasology.engine.logic.players.FirstPersonHeldItemMountPointComponent)1 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)1 PlayerTargetChangedEvent (org.terasology.engine.logic.players.PlayerTargetChangedEvent)1 Client (org.terasology.engine.network.Client)1 HitResult (org.terasology.engine.physics.HitResult)1 Physics (org.terasology.engine.physics.Physics)1 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)1