spawn player in center of single player world
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2024-12-03 16:36:35 -05:00
parent ddaab9a2db
commit 1ea758705f
4 changed files with 25 additions and 3 deletions

View File

@ -1230,6 +1230,7 @@ Refactoring native code
Fix gravity tree not deactivating when body is disabled Fix gravity tree not deactivating when body is disabled
Refactoring world menu generators into dedicated class Refactoring world menu generators into dedicated class
Fix single player loading Fix single player loading
Spawn player in center of single player world

View File

@ -13,6 +13,7 @@ import electrosphere.server.content.ServerContentManager;
import electrosphere.server.datacell.GriddedDataCellManager; import electrosphere.server.datacell.GriddedDataCellManager;
import electrosphere.server.datacell.Realm; import electrosphere.server.datacell.Realm;
import electrosphere.server.terrain.generation.DefaultChunkGenerator; import electrosphere.server.terrain.generation.DefaultChunkGenerator;
import electrosphere.server.terrain.manager.ServerTerrainChunk;
import electrosphere.util.FileUtils; import electrosphere.util.FileUtils;
/** /**
@ -86,6 +87,15 @@ public class SceneLoader {
} break; } break;
case RealmDescriptor.REALM_DESCRIPTOR_PROCEDURAL: { case RealmDescriptor.REALM_DESCRIPTOR_PROCEDURAL: {
realm = Globals.realmManager.createGriddedRealm(serverWorldData,serverContentManager); realm = Globals.realmManager.createGriddedRealm(serverWorldData,serverContentManager);
//generate spawns
Vector3d spawnPoint = new Vector3d(serverWorldData.getWorldSizeDiscrete() * ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET / 2);
spawnPoint.y = serverWorldData.getServerTerrainManager().getElevation(
serverWorldData.getWorldSizeDiscrete() / 2,
serverWorldData.getWorldSizeDiscrete() / 2,
ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET / 2,
ServerTerrainChunk.CHUNK_PLACEMENT_OFFSET / 2
);
realm.registerSpawnPoint(spawnPoint);
} break; } break;
case RealmDescriptor.REALM_DESCRIPTOR_GENERATION_TESTING: { case RealmDescriptor.REALM_DESCRIPTOR_GENERATION_TESTING: {
ServerWorldData newWorldData = ServerWorldData.createGenerationTestWorldData(); ServerWorldData newWorldData = ServerWorldData.createGenerationTestWorldData();

View File

@ -123,7 +123,7 @@ public class CharacterProtocol implements ServerProtocolTemplate<CharacterMessag
} }
Entity rVal = PlayerCharacterCreation.spawnPlayerCharacter(connectionHandler); Entity rVal = PlayerCharacterCreation.spawnPlayerCharacter(connectionHandler);
Realm realm = Globals.playerManager.getPlayerRealm(connectionHandler.getPlayer()); Realm realm = Globals.playerManager.getPlayerRealm(connectionHandler.getPlayer());
Vector3d spawnPoint = realm.getSpawnPoint(); Vector3d spawnPoint = PlayerCharacterCreation.solveSpawnPoint(realm, connectionHandler);
//set client initial discrete position //set client initial discrete position
connectionHandler.addMessagetoOutgoingQueue( connectionHandler.addMessagetoOutgoingQueue(
PlayerMessage.constructSetInitialDiscretePositionMessage( PlayerMessage.constructSetInitialDiscretePositionMessage(

View File

@ -33,7 +33,7 @@ public class PlayerCharacterCreation {
// //
//spawn entity in world //spawn entity in world
Vector3d spawnPoint = realm.getSpawnPoint(); Vector3d spawnPoint = PlayerCharacterCreation.solveSpawnPoint(realm, connectionHandler);
Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template); Entity newPlayerEntity = CreatureUtils.serverSpawnBasicCreature(realm,new Vector3d(spawnPoint.x,spawnPoint.y,spawnPoint.z),raceName,template);
// //
@ -84,4 +84,15 @@ public class PlayerCharacterCreation {
ServerPlayerViewDirTree.attachServerPlayerViewDirTree(entity); ServerPlayerViewDirTree.attachServerPlayerViewDirTree(entity);
} }
/**
* Solves the spawn point for the player
* @param realm The realm that the entity is being spawned in
* @param connectionHandler The connection object
* @return The spawn point for the player
*/
public static Vector3d solveSpawnPoint(Realm realm, ServerConnectionHandler connectionHandler){
Vector3d spawnPoint = realm.getSpawnPoint();
return spawnPoint;
}
} }