use of org.terasology.engine.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);
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerSystem method spawnPlayer.
private void spawnPlayer(EntityRef clientEntity) {
ClientComponent client = clientEntity.getComponent(ClientComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
EntityRef playerCharacter = playerFactory.newInstance(clientEntity);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
client.character = playerCharacter;
clientEntity.saveComponent(client);
playerCharacter.send(new OnPlayerSpawnedEvent());
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerSystem method setSpawnLocationOnRespawnRequest.
@ReceiveEvent(priority = EventPriority.PRIORITY_CRITICAL, components = ClientComponent.class)
public void setSpawnLocationOnRespawnRequest(RespawnRequestEvent event, EntityRef entity) {
ClientComponent clientComponent = entity.getComponent(ClientComponent.class);
EntityRef character = clientComponent.character;
EntityRef clientInfo = clientComponent.clientInfo;
Vector3fc spawnPosition;
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
spawnPosition = clientInfo.getComponent(StaticSpawnLocationComponent.class).position;
} else {
spawnPosition = worldGenerator.getSpawnPosition(entity);
}
LocationComponent loc = character.getComponent(LocationComponent.class);
loc.setWorldPosition(spawnPosition);
// reset rotation
loc.setLocalRotation(new Quaternionf());
character.saveComponent(loc);
}
use of org.terasology.engine.network.ClientComponent in project Terasology by MovingBlocks.
the class PlayerSystem method restoreCharacter.
private void restoreCharacter(EntityRef entity, EntityRef character) {
Client clientListener = networkSystem.getOwner(entity);
System.out.println(clientListener);
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)) {
respawnPlayer(entity);
}
Location.attachChild(character, entity, new Vector3f(), new Quaternionf());
} else {
character.destroy();
spawnPlayer(entity);
}
}
use of org.terasology.engine.network.ClientComponent 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 = playerCharacter.getComponent(LocationComponent.class);
PlayerFactory playerFactory = new PlayerFactory(entityManager, worldProvider);
Vector3f spawnPosition = playerFactory.findSpawnPositionFromLocationComponent(location);
playerCharacter.addComponent(new AliveCharacterComponent());
playerCharacter.send(new CharacterTeleportEvent(spawnPosition));
logger.debug("Re-spawing player at: {}", spawnPosition);
Client clientListener = networkSystem.getOwner(clientEntity);
Vector3ic distance = clientListener.getViewDistance().getChunkDistance();
updateRelevanceEntity(clientEntity, distance);
playerCharacter.send(new OnPlayerRespawnedEvent());
}
Aggregations