use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class OnlinePlayersOverlay method determinePlayerListText.
private String determinePlayerListText() {
Iterable<EntityRef> allClients = entityManager.getEntitiesWith(ClientComponent.class);
StringBuilder sb = new StringBuilder();
boolean first = true;
for (EntityRef clientEntity : allClients) {
if (!first) {
sb.append("\n");
}
ClientComponent clientComp = clientEntity.getComponent(ClientComponent.class);
sb.append(PlayerUtil.getColoredPlayerName(clientComp.clientInfo));
first = false;
}
return sb.toString();
}
use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class StateMainMenu method init.
@Override
public void init(GameEngine gameEngine) {
context = gameEngine.createChildContext();
CoreRegistry.setContext(context);
// let's get the entity event system running
EntitySystemSetupUtil.addEntityManagementRelatedClasses(context);
entityManager = context.get(EngineEntityManager.class);
eventSystem = context.get(EventSystem.class);
console = new ConsoleImpl(context);
context.put(Console.class, console);
nuiManager = new NUIManagerInternal(context.get(CanvasRenderer.class), context);
context.put(NUIManager.class, nuiManager);
eventSystem.registerEventHandler(nuiManager);
componentSystemManager = new ComponentSystemManager(context);
context.put(ComponentSystemManager.class, componentSystemManager);
// TODO: Reduce coupling between Input system and CameraTargetSystem,
// TODO: potentially eliminating the following lines. See Issue #1126
CameraTargetSystem cameraTargetSystem = new CameraTargetSystem();
context.put(CameraTargetSystem.class, cameraTargetSystem);
componentSystemManager.register(cameraTargetSystem, "engine:CameraTargetSystem");
componentSystemManager.register(new ConsoleSystem(), "engine:ConsoleSystem");
componentSystemManager.register(new CoreCommands(), "engine:CoreCommands");
NUIEditorSystem nuiEditorSystem = new NUIEditorSystem();
context.put(NUIEditorSystem.class, nuiEditorSystem);
componentSystemManager.register(nuiEditorSystem, "engine:NUIEditorSystem");
NUISkinEditorSystem nuiSkinEditorSystem = new NUISkinEditorSystem();
context.put(NUISkinEditorSystem.class, nuiSkinEditorSystem);
componentSystemManager.register(nuiSkinEditorSystem, "engine:NUISkinEditorSystem");
inputSystem = context.get(InputSystem.class);
// TODO: REMOVE this and handle refreshing of core game state at the engine level - see Issue #1127
new RegisterInputSystem(context).step();
EntityRef localPlayerEntity = entityManager.create(new ClientComponent());
LocalPlayer localPlayer = new LocalPlayer();
context.put(LocalPlayer.class, localPlayer);
localPlayer.setClientEntity(localPlayerEntity);
componentSystemManager.initialise();
storageServiceWorker = context.get(StorageServiceWorker.class);
playBackgroundMusic();
// guiManager.openWindow("main");
context.get(NUIManager.class).pushScreen("engine:mainMenuScreen");
if (!messageOnLoad.isEmpty()) {
nuiManager.pushScreen(MessagePopup.ASSET_URI, MessagePopup.class).setMessage("Error", messageOnLoad);
}
// TODO: enable it when exposing the telemetry to users
// pushLaunchPopup();
}
use of org.terasology.network.ClientComponent in project Terasology by MovingBlocks.
the class AbstractClient method createEntity.
protected void createEntity(String preferredName, Color color, EntityManager entityManager) {
// Create player entity
clientEntity = entityManager.create("engine:client");
// TODO: Send event for clientInfo creation, don't create here.
EntityRef clientInfo = findClientEntityRef(entityManager);
if (!clientInfo.exists()) {
clientInfo = createClientInfoEntity(entityManager);
}
ClientInfoComponent clientInfoComp = clientInfo.getComponent(ClientInfoComponent.class);
clientInfoComp.client = clientEntity;
clientInfo.saveComponent(clientInfoComp);
ClientComponent clientComponent = clientEntity.getComponent(ClientComponent.class);
clientComponent.clientInfo = clientInfo;
clientEntity.saveComponent(clientComponent);
addOrSetColorComponent(clientInfo, color);
DisplayNameComponent displayNameComponent = clientInfo.getComponent(DisplayNameComponent.class);
if (displayNameComponent == null || !displayNameComponent.name.equals(preferredName)) {
String bestAvailableName = findUniquePlayerName(preferredName, entityManager, clientInfo);
addOrSetDisplayNameComponent(clientInfo, bestAvailableName);
}
}
use of org.terasology.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.network.ClientComponent in project Terasology by MovingBlocks.
the class ClientCharacterPredictionSystem method onDestroy.
@ReceiveEvent(components = { CharacterComponent.class, CharacterMovementComponent.class, LocationComponent.class, AliveCharacterComponent.class })
public void onDestroy(final BeforeDeactivateComponent event, final EntityRef entity) {
CharacterComponent character = entity.getComponent(CharacterComponent.class);
ClientComponent controller = character.controller.getComponent(ClientComponent.class);
if (controller != null && controller.local) {
predictedState = null;
authoritiveState = null;
inputs.clear();
}
physics.removeCharacterCollider(entity);
playerStates.remove(entity);
}
Aggregations