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