summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorElNounch <ElNounch@users.noreply.github.com>2016-08-15 10:41:32 +0200
committerMattes D <github@xoft.cz>2016-08-15 10:41:32 +0200
commit343531bafa8e7b646ec0eb8b65cae69b4abe05d9 (patch)
treedaa58d267f1520856d044e382aa229005353e489 /src
parentFixed cWorld:ChunkStay bindings. (#3319) (diff)
downloadcuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar.gz
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar.bz2
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar.lz
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar.xz
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.tar.zst
cuberite-343531bafa8e7b646ec0eb8b65cae69b4abe05d9.zip
Diffstat (limited to 'src')
-rw-r--r--src/World.cpp41
-rw-r--r--src/World.h3
2 files changed, 32 insertions, 12 deletions
diff --git a/src/World.cpp b/src/World.cpp
index 33bef4600..c687e9549 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -324,6 +324,33 @@ void cWorld::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
+bool cWorld::SetSpawn(double a_X, double a_Y, double a_Z)
+{
+ cIniFile IniFile;
+
+ IniFile.ReadFile(m_IniFileName);
+ IniFile.SetValueF("SpawnPosition", "X", a_X);
+ IniFile.SetValueF("SpawnPosition", "Y", a_Y);
+ IniFile.SetValueF("SpawnPosition", "Z", a_Z);
+ if (IniFile.WriteFile(m_IniFileName))
+ {
+ m_SpawnX = a_X;
+ m_SpawnY = a_Y;
+ m_SpawnZ = a_Z;
+ LOGD("Spawn set at {%f, %f, %f}", m_SpawnX, m_SpawnY, m_SpawnZ);
+ return true;
+ }
+ else
+ {
+ LOGWARNING("Couldn't write new spawn settings to \"%s\".", m_IniFileName.c_str());
+ }
+ return false;
+}
+
+
+
+
+
void cWorld::InitializeSpawn(void)
{
// For the debugging builds, don't make the server build too much world upon start:
@@ -337,12 +364,6 @@ void cWorld::InitializeSpawn(void)
{
// Spawn position wasn't already explicitly set, enumerate random solid-land coordinate and then write it to the world configuration:
GenerateRandomSpawn(DefaultViewDist);
- cIniFile IniFile;
- IniFile.ReadFile(m_IniFileName);
- IniFile.SetValueF("SpawnPosition", "X", m_SpawnX);
- IniFile.SetValueF("SpawnPosition", "Y", m_SpawnY);
- IniFile.SetValueF("SpawnPosition", "Z", m_SpawnZ);
- IniFile.WriteFile(m_IniFileName);
}
cIniFile IniFile;
@@ -649,9 +670,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
double SpawnY = 0.0;
if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z))
{
- m_SpawnX = BiomeOffset.x + 0.5;
- m_SpawnY = SpawnY;
- m_SpawnZ = BiomeOffset.z + 0.5;
+ SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5);
LOGINFO("Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_SpawnX, m_SpawnY, m_SpawnZ);
return;
@@ -681,9 +700,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
if (CanSpawnAt(PotentialSpawn.x, SpawnY, PotentialSpawn.z))
{
- m_SpawnX = PotentialSpawn.x + 0.5;
- m_SpawnY = SpawnY;
- m_SpawnZ = PotentialSpawn.z + 0.5;
+ SetSpawn(PotentialSpawn.x + 0.5, SpawnY, PotentialSpawn.z + 0.5);
int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ);
diff --git a/src/World.h b/src/World.h
index fbe1f4a6d..c1794b159 100644
--- a/src/World.h
+++ b/src/World.h
@@ -475,6 +475,9 @@ public:
bool DigBlock (int a_X, int a_Y, int a_Z);
virtual void SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player) override;
+ /** Set default spawn at the given coordinates. */
+ bool SetSpawn(double a_X, double a_Y, double a_Z);
+
double GetSpawnX(void) const { return m_SpawnX; }
double GetSpawnY(void) const { return m_SpawnY; }
double GetSpawnZ(void) const { return m_SpawnZ; }