1
0

Added cWorld:SetSpawn() API and Lua binding (#3316)

This commit is contained in:
ElNounch 2016-08-15 10:41:32 +02:00 committed by Mattes D
parent 0f51f7e358
commit 343531bafa
3 changed files with 33 additions and 12 deletions

View File

@ -2654,6 +2654,7 @@ end
SetMinNetherPortalWidth = { Params = "number", Return = "", Notes = "Sets the minimum width for a nether portal" }, 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." }, 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." }, 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." }, 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." }, 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." }, SetTNTShrapnelLevel = { Params = "{{Globals#ShrapnelLevel|ShrapnelLevel}}", Return = "", Notes = "Sets the Shrampel level of the world." },

View File

@ -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) void cWorld::InitializeSpawn(void)
{ {
// For the debugging builds, don't make the server build too much world upon start: // 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: // Spawn position wasn't already explicitly set, enumerate random solid-land coordinate and then write it to the world configuration:
GenerateRandomSpawn(DefaultViewDist); 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; cIniFile IniFile;
@ -649,9 +670,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
double SpawnY = 0.0; double SpawnY = 0.0;
if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z)) if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z))
{ {
m_SpawnX = BiomeOffset.x + 0.5; SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5);
m_SpawnY = SpawnY;
m_SpawnZ = BiomeOffset.z + 0.5;
LOGINFO("Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_SpawnX, m_SpawnY, m_SpawnZ); LOGINFO("Generated spawnpoint position at {%.2f, %.2f, %.2f}", m_SpawnX, m_SpawnY, m_SpawnZ);
return; return;
@ -681,9 +700,7 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
if (CanSpawnAt(PotentialSpawn.x, SpawnY, PotentialSpawn.z)) if (CanSpawnAt(PotentialSpawn.x, SpawnY, PotentialSpawn.z))
{ {
m_SpawnX = PotentialSpawn.x + 0.5; SetSpawn(PotentialSpawn.x + 0.5, SpawnY, PotentialSpawn.z + 0.5);
m_SpawnY = SpawnY;
m_SpawnZ = PotentialSpawn.z + 0.5;
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ); cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ);

View File

@ -475,6 +475,9 @@ public:
bool DigBlock (int a_X, int a_Y, int a_Z); 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; 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 GetSpawnX(void) const { return m_SpawnX; }
double GetSpawnY(void) const { return m_SpawnY; } double GetSpawnY(void) const { return m_SpawnY; }
double GetSpawnZ(void) const { return m_SpawnZ; } double GetSpawnZ(void) const { return m_SpawnZ; }