use of org.terasology.network.Client in project Terasology by MovingBlocks.
the class ServerViewDistanceSystem method onChangeViewDistanceChanged.
@ReceiveEvent(components = ClientComponent.class)
public void onChangeViewDistanceChanged(ViewDistanceChangedEvent request, EntityRef entity) {
Client client = networkSystem.getOwner(entity);
if (client != null) {
client.setViewDistanceMode(request.getNewViewRange());
chunkProvider.updateRelevanceEntity(entity, client.getViewDistance().getChunkDistance());
}
}
use of org.terasology.network.Client in project Terasology by MovingBlocks.
the class PlayerSystem method respawnPlayer.
private void respawnPlayer(EntityRef clientEntity) {
ClientComponent client = clientEntity.getComponent(ClientComponent.class);
EntityRef playerCharacter = client.character;
LocationComponent location = clientEntity.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
location.setWorldPosition(spawnPosition);
clientEntity.saveComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3i distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
playerCharacter.send(new OnPlayerRespawnedEvent());
}
use of org.terasology.network.Client in project Terasology by MovingBlocks.
the class PlayerSystem method restoreCharacter.
private void restoreCharacter(EntityRef entity, EntityRef character) {
Client clientListener = networkSystem.getOwner(entity);
updateRelevanceEntity(entity, clientListener.getViewDistance().getChunkDistance());
ClientComponent client = entity.getComponent(ClientComponent.class);
client.character = character;
entity.saveComponent(client);
CharacterComponent characterComp = character.getComponent(CharacterComponent.class);
if (characterComp != null) {
characterComp.controller = entity;
character.saveComponent(characterComp);
character.setOwner(entity);
if (!character.hasComponent(AliveCharacterComponent.class)) {
character.addComponent(new AliveCharacterComponent());
}
Location.attachChild(character, entity, new Vector3f(), new Quat4f(0, 0, 0, 1));
} else {
character.destroy();
spawnPlayer(entity);
}
}
use of org.terasology.network.Client in project Terasology by MovingBlocks.
the class NetworkSystemImpl method update.
@Override
public void update() {
if (mode != NetworkMode.NONE) {
if (entityManager != null) {
processPendingConnections();
processPendingDisconnects();
long currentTimer = time.getRealTimeInMs();
boolean netTick = false;
if (currentTimer > nextNetworkTick) {
nextNetworkTick += NET_TICK_RATE;
netTick = true;
}
PerformanceMonitor.startActivity("Client update");
for (Client client : clientList) {
client.update(netTick);
}
PerformanceMonitor.endActivity();
if (server != null) {
server.update(netTick);
}
}
}
}
use of org.terasology.network.Client in project Terasology by MovingBlocks.
the class StorageManagerTest method setup.
@Before
public void setup() throws Exception {
super.setup();
JavaArchive homeArchive = ShrinkWrap.create(JavaArchive.class);
FileSystem vfs = ShrinkWrapFileSystems.newFileSystem(homeArchive);
PathManager.getInstance().useOverrideHomePath(temporaryFolder.getRoot().toPath());
savePath = PathManager.getInstance().getSavePath("testSave");
assert !Files.isRegularFile(vfs.getPath("global.dat"));
entityManager = context.get(EngineEntityManager.class);
moduleEnvironment = context.get(ModuleEnvironment.class);
blockManager = context.get(BlockManager.class);
biomeManager = context.get(BiomeManager.class);
esm = new ReadWriteStorageManager(savePath, moduleEnvironment, entityManager, blockManager, biomeManager, false);
context.put(StorageManager.class, esm);
this.character = entityManager.create();
Client client = createClientMock(PLAYER_ID, character);
NetworkSystem networkSystem = mock(NetworkSystem.class);
when(networkSystem.getMode()).thenReturn(NetworkMode.NONE);
when(networkSystem.getPlayers()).thenReturn(Arrays.asList(client));
context.put(NetworkSystem.class, networkSystem);
AssetManager assetManager = context.get(AssetManager.class);
BlockFamilyDefinitionData data = new BlockFamilyDefinitionData();
data.setFamilyFactory(new SymmetricBlockFamilyFactory());
assetManager.loadAsset(new ResourceUrn("test:testblock"), data, BlockFamilyDefinition.class);
assetManager.loadAsset(new ResourceUrn("test:testblock2"), data, BlockFamilyDefinition.class);
testBlock = context.get(BlockManager.class).getBlock("test:testblock");
testBlock2 = context.get(BlockManager.class).getBlock("test:testblock2");
context.put(ChunkProvider.class, mock(ChunkProvider.class));
BiomeManager mockBiomeManager = mock(BiomeManager.class);
when(mockBiomeManager.getBiomes()).thenReturn(Collections.<Biome>emptyList());
context.put(BiomeManager.class, mockBiomeManager);
WorldProvider worldProvider = mock(WorldProvider.class);
when(worldProvider.getWorldInfo()).thenReturn(new WorldInfo());
context.put(WorldProvider.class, worldProvider);
}
Aggregations