Search in sources :

Example 1 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class InputSystemTests method setUpLocalPlayer.

private void setUpLocalPlayer(Context context) {
    LocalPlayer localPlayer = new LocalPlayer();
    localPlayer.setRecordAndReplayClasses(new DirectionAndOriginPosRecorderList(), new RecordAndReplayCurrentStatus());
    clientEntity = mock(EntityRef.class);
    ClientComponent clientComponent = new ClientComponent();
    characterEntity = mock(EntityRef.class);
    clientComponent.character = characterEntity;
    when(clientEntity.getComponent(ClientComponent.class)).thenReturn(clientComponent);
    localPlayer.setClientEntity(clientEntity);
    context.put(LocalPlayer.class, localPlayer);
    registerEntityKeyCapturing();
}
Also used : DirectionAndOriginPosRecorderList(org.terasology.engine.recording.DirectionAndOriginPosRecorderList) LocalPlayer(org.terasology.engine.logic.players.LocalPlayer) RecordAndReplayCurrentStatus(org.terasology.engine.recording.RecordAndReplayCurrentStatus) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 2 with ClientComponent

use of org.terasology.engine.network.ClientComponent 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.engine.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent)

Example 3 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class CharacterSystem method getInstigatorName.

/**
 * Extracts the name from an entity.
 * If the entity is a character, then the display name from the {@link ClientComponent#clientInfo} is used.
 * Otherwise the entity itself is checked for a {@link DisplayNameComponent}.
 * In the last case, the prefab name of the entity is used, e.g. "engine:player" will be parsed to "Player".
 *
 * @param instigator The entity for which an instigator name is needed.
 * @return The instigator name.
 */
public String getInstigatorName(EntityRef instigator) {
    if (instigator.hasComponent(CharacterComponent.class)) {
        EntityRef instigatorClient = instigator.getComponent(CharacterComponent.class).controller;
        EntityRef instigatorClientInfo = instigatorClient.getComponent(ClientComponent.class).clientInfo;
        DisplayNameComponent displayNameComponent = instigatorClientInfo.getComponent(DisplayNameComponent.class);
        return displayNameComponent.name;
    } else if (instigator.getParentPrefab() != null) {
        // A DisplayName can be specified in the entity prefab
        // Otherwise, the game will attempt to generate one from the name of that prefab
        Prefab parentPrefab = instigator.getParentPrefab();
        if (parentPrefab.hasComponent(DisplayNameComponent.class)) {
            DisplayNameComponent displayNameComponent = parentPrefab.getComponent(DisplayNameComponent.class);
            return displayNameComponent.name;
        } else {
            String instigatorName = parentPrefab.getName();
            // getParentPrefab.getName() returns a ResourceUrn String such as "engine:player"
            // The following calls change the damage type to be more readable
            // For instance, "engine:player" becomes "Player"
            instigatorName = instigatorName.replaceAll(".*:(.*)", "$1");
            instigatorName = Character.toUpperCase(instigatorName.charAt(0)) + instigatorName.substring(1);
            return instigatorName;
        }
    } else {
        return null;
    }
}
Also used : DisplayNameComponent(org.terasology.engine.logic.common.DisplayNameComponent) PlayerCharacterComponent(org.terasology.engine.logic.players.PlayerCharacterComponent) EntityRef(org.terasology.engine.entitySystem.entity.EntityRef) ClientComponent(org.terasology.engine.network.ClientComponent) Prefab(org.terasology.engine.entitySystem.prefab.Prefab)

Example 4 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class AudioSystem method onPlaySound.

/**
 * Receives an event send when a sound should be played for the entity owner as well. Calls on the AudioManager to
 * play it.
 *
 * @param playSoundEvent The sound event.
 * @param entity The entity that instigated the event.
 */
@ReceiveEvent
public void onPlaySound(PlaySoundForOwnerEvent playSoundEvent, EntityRef entity) {
    ClientComponent clientComponent = networkSystem.getOwnerEntity(entity).getComponent(ClientComponent.class);
    if (clientComponent != null && !clientComponent.local) {
        return;
    }
    audioManager.playSound(playSoundEvent.getSound(), playSoundEvent.getVolume(), AudioManager.PRIORITY_HIGH);
}
Also used : ClientComponent(org.terasology.engine.network.ClientComponent) ReceiveEvent(org.terasology.engine.entitySystem.event.ReceiveEvent)

Example 5 with ClientComponent

use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.

the class NetClient method setColor.

public void setColor(Color color) {
    this.color = color;
    ClientComponent client = getEntity().getComponent(ClientComponent.class);
    if (client != null) {
        ColorComponent colorInfo = client.clientInfo.getComponent(ColorComponent.class);
        if (colorInfo != null) {
            colorInfo.color = color;
            client.clientInfo.saveComponent(colorInfo);
        }
    }
}
Also used : ColorComponent(org.terasology.engine.network.ColorComponent) ClientComponent(org.terasology.engine.network.ClientComponent)

Aggregations

ClientComponent (org.terasology.engine.network.ClientComponent)54 EntityRef (org.terasology.engine.entitySystem.entity.EntityRef)30 Command (org.terasology.engine.logic.console.commandSystem.annotations.Command)27 Vector3f (org.joml.Vector3f)13 LocationComponent (org.terasology.engine.logic.location.LocationComponent)13 CharacterMovementComponent (org.terasology.engine.logic.characters.CharacterMovementComponent)11 DisplayNameComponent (org.terasology.engine.logic.common.DisplayNameComponent)10 ConsoleCommand (org.terasology.engine.logic.console.commandSystem.ConsoleCommand)8 ReceiveEvent (org.terasology.engine.entitySystem.event.ReceiveEvent)6 CharacterTeleportEvent (org.terasology.engine.logic.characters.CharacterTeleportEvent)6 DropItemEvent (org.terasology.engine.logic.inventory.events.DropItemEvent)4 BlockFamily (org.terasology.engine.world.block.family.BlockFamily)4 BlockItemFactory (org.terasology.engine.world.block.items.BlockItemFactory)4 Quaternionf (org.joml.Quaternionf)3 Prefab (org.terasology.engine.entitySystem.prefab.Prefab)3 LocalPlayer (org.terasology.engine.logic.players.LocalPlayer)3 Client (org.terasology.engine.network.Client)3 Vector3ic (org.joml.Vector3ic)2 EngineEntityManager (org.terasology.engine.entitySystem.entity.internal.EngineEntityManager)2 AliveCharacterComponent (org.terasology.engine.logic.characters.AliveCharacterComponent)2