summaryrefslogtreecommitdiffstats
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
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 '')
-rw-r--r--Server/Plugins/APIDump/APIDesc.lua1
-rw-r--r--src/World.cpp41
-rw-r--r--src/World.h3
3 files changed, 33 insertions, 12 deletions
diff --git a/Server/Plugins/APIDump/APIDesc.lua b/Server/Plugins/APIDump/APIDesc.lua
index 77b61cb6d..667723662 100644
--- a/Server/Plugins/APIDump/APIDesc.lua
+++ b/Server/Plugins/APIDump/APIDesc.lua
@@ -2654,6 +2654,7 @@ end
SetMinNetherPortalWidth = { Params = "number", Return = "", Notes = "Sets the minimum width for a nether portal" },
SetShouldUseChatPrefixes = { Params = "", Return = "ShouldUse (bool)", Notes = "Sets whether coloured chat prefixes such as [INFO] is used with the SendMessageXXX() or BroadcastChatXXX(), or simply the entire message is coloured in the respective colour." },
SetSignLines = { Params = "X, Y, Z, Line1, Line2, Line3, Line4, [{{cPlayer|Player}}]", Return = "", Notes = "Sets the sign text at the specified coords. The sign-updating hooks are called for the change. The Player parameter is used to indicate the player from whom the change has come, it may be nil." },
+ SetSpawn = { Params = "X, Y, Z", Return = "bool", Notes = "Sets the default spawn at the specified coords." },
SetTicksUntilWeatherChange = { Params = "NumTicks", Return = "", Notes = "Sets the number of ticks after which the weather will be changed." },
SetTimeOfDay = { Params = "TimeOfDayTicks", Return = "", Notes = "Sets the time of day, expressed as number of ticks past sunrise, in the range 0 .. 24000." },
SetTNTShrapnelLevel = { Params = "{{Globals#ShrapnelLevel|ShrapnelLevel}}", Return = "", Notes = "Sets the Shrampel level of the world." },
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; }