World: change spawnpoint type to int (#5313)
* World: change spawnpoint type to int As Vanilla does.
This commit is contained in:
parent
8b0d0e96c3
commit
1e4850a6c5
|
@ -1645,7 +1645,7 @@ bool cEntity::MoveToWorld(cWorld & a_World, Vector3d a_NewPosition, bool a_SetPo
|
||||||
|
|
||||||
bool cEntity::MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn)
|
bool cEntity::MoveToWorld(cWorld & a_World, bool a_ShouldSendRespawn)
|
||||||
{
|
{
|
||||||
return MoveToWorld(a_World, a_ShouldSendRespawn, Vector3d(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ()));
|
return MoveToWorld(a_World, a_ShouldSendRespawn, Vector3i(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1661,7 +1661,7 @@ bool cEntity::MoveToWorld(const AString & a_WorldName, bool a_ShouldSendRespawn)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MoveToWorld(*World, Vector3d(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()), false, a_ShouldSendRespawn);
|
return MoveToWorld(*World, Vector3i(World->GetSpawnX(), World->GetSpawnY(), World->GetSpawnZ()), false, a_ShouldSendRespawn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -965,7 +965,7 @@ void cPlayer::Respawn(void)
|
||||||
const auto & DefaultWorld = *cRoot::Get()->GetDefaultWorld();
|
const auto & DefaultWorld = *cRoot::Get()->GetDefaultWorld();
|
||||||
|
|
||||||
// If not, reset spawn to default and inform:
|
// If not, reset spawn to default and inform:
|
||||||
SetRespawnPosition(Vector3d(DefaultWorld.GetSpawnX(), DefaultWorld.GetSpawnY(), DefaultWorld.GetSpawnZ()), DefaultWorld);
|
SetRespawnPosition(Vector3i(DefaultWorld.GetSpawnX(), DefaultWorld.GetSpawnY(), DefaultWorld.GetSpawnZ()), DefaultWorld);
|
||||||
SendAboveActionBarMessage("Your home bed was missing or obstructed");
|
SendAboveActionBarMessage("Your home bed was missing or obstructed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -82,7 +82,7 @@ void cProtocol_1_14::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
|
||||||
// Send the spawn position:
|
// Send the spawn position:
|
||||||
{
|
{
|
||||||
cPacketizer Pkt(*this, pktSpawnPosition);
|
cPacketizer Pkt(*this, pktSpawnPosition);
|
||||||
Pkt.WriteXZYPosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
|
Pkt.WriteXZYPosition64(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the server difficulty:
|
// Send the server difficulty:
|
||||||
|
|
|
@ -844,7 +844,7 @@ void cProtocol_1_8_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World
|
||||||
// Send the spawn position:
|
// Send the spawn position:
|
||||||
{
|
{
|
||||||
cPacketizer Pkt(*this, pktSpawnPosition);
|
cPacketizer Pkt(*this, pktSpawnPosition);
|
||||||
Pkt.WriteXYZPosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
|
Pkt.WriteXYZPosition64(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the server difficulty:
|
// Send the server difficulty:
|
||||||
|
|
|
@ -2265,7 +2265,7 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World
|
||||||
// Send the spawn position:
|
// Send the spawn position:
|
||||||
{
|
{
|
||||||
cPacketizer Pkt(*this, pktSpawnPosition);
|
cPacketizer Pkt(*this, pktSpawnPosition);
|
||||||
Pkt.WriteXYZPosition64(FloorC(a_World.GetSpawnX()), FloorC(a_World.GetSpawnY()), FloorC(a_World.GetSpawnZ()));
|
Pkt.WriteXYZPosition64(a_World.GetSpawnX(), a_World.GetSpawnY(), a_World.GetSpawnZ());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Send the server difficulty:
|
// Send the server difficulty:
|
||||||
|
|
|
@ -270,9 +270,9 @@ cWorld::cWorld(
|
||||||
if (m_IsSpawnExplicitlySet)
|
if (m_IsSpawnExplicitlySet)
|
||||||
{
|
{
|
||||||
LOGD("Spawnpoint explicitly set!");
|
LOGD("Spawnpoint explicitly set!");
|
||||||
m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX);
|
m_SpawnX = IniFile.GetValueI("SpawnPosition", "X", m_SpawnX);
|
||||||
m_SpawnY = IniFile.GetValueF("SpawnPosition", "Y", m_SpawnY);
|
m_SpawnY = IniFile.GetValueI("SpawnPosition", "Y", m_SpawnY);
|
||||||
m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ);
|
m_SpawnZ = IniFile.GetValueI("SpawnPosition", "Z", m_SpawnZ);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
|
m_StorageSchema = IniFile.GetValueSet ("Storage", "Schema", m_StorageSchema);
|
||||||
|
@ -626,27 +626,27 @@ void cWorld::SetNextBlockToTick(const Vector3i a_BlockPos)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cWorld::SetSpawn(double a_X, double a_Y, double a_Z)
|
bool cWorld::SetSpawn(int a_X, int a_Y, int a_Z)
|
||||||
{
|
{
|
||||||
cIniFile IniFile;
|
cIniFile IniFile;
|
||||||
|
|
||||||
IniFile.ReadFile(m_IniFileName);
|
IniFile.ReadFile(m_IniFileName);
|
||||||
IniFile.SetValueF("SpawnPosition", "X", a_X);
|
IniFile.SetValueI("SpawnPosition", "X", a_X);
|
||||||
IniFile.SetValueF("SpawnPosition", "Y", a_Y);
|
IniFile.SetValueI("SpawnPosition", "Y", a_Y);
|
||||||
IniFile.SetValueF("SpawnPosition", "Z", a_Z);
|
IniFile.SetValueI("SpawnPosition", "Z", a_Z);
|
||||||
if (IniFile.WriteFile(m_IniFileName))
|
if (IniFile.WriteFile(m_IniFileName))
|
||||||
{
|
{
|
||||||
m_SpawnX = a_X;
|
m_SpawnX = a_X;
|
||||||
m_SpawnY = a_Y;
|
m_SpawnY = a_Y;
|
||||||
m_SpawnZ = a_Z;
|
m_SpawnZ = a_Z;
|
||||||
FLOGD("Spawn set at {0}", Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
|
FLOGD("Spawn set at {}", Vector3i{m_SpawnX, m_SpawnY, m_SpawnZ});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
LOGWARNING("Couldn't write new spawn settings to \"%s\".", m_IniFileName.c_str());
|
LOGWARNING("Couldn't write new spawn settings to \"%s\".", m_IniFileName.c_str());
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -674,7 +674,7 @@ void cWorld::InitializeSpawn(void)
|
||||||
IniFile.WriteFile(m_IniFileName);
|
IniFile.WriteFile(m_IniFileName);
|
||||||
|
|
||||||
int ChunkX = 0, ChunkZ = 0;
|
int ChunkX = 0, ChunkZ = 0;
|
||||||
cChunkDef::BlockToChunk(FloorC(m_SpawnX), FloorC(m_SpawnZ), ChunkX, ChunkZ);
|
cChunkDef::BlockToChunk(m_SpawnX, m_SpawnZ, ChunkX, ChunkZ);
|
||||||
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, ViewDist);
|
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, ViewDist);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -724,17 +724,17 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check 0, 0 first.
|
// Check 0, 0 first.
|
||||||
double SpawnY = 0.0;
|
int SpawnY = 0;
|
||||||
if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z))
|
if (CanSpawnAt(BiomeOffset.x, SpawnY, BiomeOffset.z))
|
||||||
{
|
{
|
||||||
SetSpawn(BiomeOffset.x + 0.5, SpawnY, BiomeOffset.z + 0.5);
|
SetSpawn(BiomeOffset.x, SpawnY, BiomeOffset.z);
|
||||||
|
|
||||||
FLOGINFO("World \"{0}\": Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
|
FLOGINFO("World \"{}\": Generated spawnpoint position at {}", m_WorldName, Vector3i{m_SpawnX, m_SpawnY, m_SpawnZ});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// A search grid (searches clockwise around the origin)
|
// A search grid (searches clockwise around the origin)
|
||||||
static const int HalfChunk = static_cast<int>(cChunkDef::Width / 2.0f);
|
static const int HalfChunk = cChunkDef::Width / 2;
|
||||||
static const Vector3i ChunkOffset[] =
|
static const Vector3i ChunkOffset[] =
|
||||||
{
|
{
|
||||||
Vector3i(0, 0, HalfChunk),
|
Vector3i(0, 0, HalfChunk),
|
||||||
|
@ -757,27 +757,27 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
|
||||||
|
|
||||||
if (CanSpawnAt(PotentialSpawn.x, SpawnY, PotentialSpawn.z))
|
if (CanSpawnAt(PotentialSpawn.x, SpawnY, PotentialSpawn.z))
|
||||||
{
|
{
|
||||||
SetSpawn(PotentialSpawn.x + 0.5, SpawnY, PotentialSpawn.z + 0.5);
|
SetSpawn(PotentialSpawn.x, SpawnY, PotentialSpawn.z);
|
||||||
|
|
||||||
int ChunkX, ChunkZ;
|
int ChunkX, ChunkZ;
|
||||||
cChunkDef::BlockToChunk(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ), ChunkX, ChunkZ);
|
cChunkDef::BlockToChunk(m_SpawnX, m_SpawnZ, ChunkX, ChunkZ);
|
||||||
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, a_MaxSpawnRadius);
|
cSpawnPrepare::PrepareChunks(*this, ChunkX, ChunkZ, a_MaxSpawnRadius);
|
||||||
|
|
||||||
FLOGINFO("World \"{0}\":Generated spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
|
FLOGINFO("World \"{}\":Generated spawnpoint position at {}", m_WorldName, Vector3i{m_SpawnX, m_SpawnY, m_SpawnZ});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m_SpawnY = GetHeight(static_cast<int>(m_SpawnX), static_cast<int>(m_SpawnZ));
|
m_SpawnY = GetHeight(m_SpawnX, m_SpawnZ);
|
||||||
FLOGWARNING("World \"{0}\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {1:.2f}", m_WorldName, Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
|
FLOGWARNING("World \"{}\": Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {}", m_WorldName, Vector3i{m_SpawnX, m_SpawnY, m_SpawnZ});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
|
bool cWorld::CanSpawnAt(int a_X, int & a_Y, int a_Z)
|
||||||
{
|
{
|
||||||
// All this blocks can only be found above ground.
|
// All this blocks can only be found above ground.
|
||||||
// Apart from netherrack (as the Nether is technically a massive cave)
|
// Apart from netherrack (as the Nether is technically a massive cave)
|
||||||
|
@ -793,12 +793,12 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
|
||||||
static const int ValidSpawnBlocksCount = ARRAYCOUNT(ValidSpawnBlocks);
|
static const int ValidSpawnBlocksCount = ARRAYCOUNT(ValidSpawnBlocks);
|
||||||
|
|
||||||
// Increase this by two, because we need two more blocks for body and head
|
// Increase this by two, because we need two more blocks for body and head
|
||||||
static const int HighestSpawnPoint = GetHeight(static_cast<int>(a_X), static_cast<int>(a_Z)) + 2;
|
static const int HighestSpawnPoint = GetHeight(a_X, a_Z) + 2;
|
||||||
static const int LowestSpawnPoint = static_cast<int>(HighestSpawnPoint / 2.0f);
|
static const int LowestSpawnPoint = HighestSpawnPoint / 2;
|
||||||
|
|
||||||
for (int PotentialY = HighestSpawnPoint; PotentialY > LowestSpawnPoint; --PotentialY)
|
for (int PotentialY = HighestSpawnPoint; PotentialY > LowestSpawnPoint; --PotentialY)
|
||||||
{
|
{
|
||||||
BLOCKTYPE HeadBlock = GetBlock({ static_cast<int>(a_X), PotentialY, static_cast<int>(a_Z) });
|
BLOCKTYPE HeadBlock = GetBlock({ a_X, PotentialY, a_Z });
|
||||||
|
|
||||||
// Is this block safe for spawning
|
// Is this block safe for spawning
|
||||||
if (HeadBlock != E_BLOCK_AIR)
|
if (HeadBlock != E_BLOCK_AIR)
|
||||||
|
@ -806,7 +806,7 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCKTYPE BodyBlock = GetBlock({ static_cast<int>(a_X), PotentialY - 1, static_cast<int>(a_Z) });
|
BLOCKTYPE BodyBlock = GetBlock({ a_X, PotentialY - 1, a_Z });
|
||||||
|
|
||||||
// Is this block safe for spawning
|
// Is this block safe for spawning
|
||||||
if (BodyBlock != E_BLOCK_AIR)
|
if (BodyBlock != E_BLOCK_AIR)
|
||||||
|
@ -814,7 +814,7 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
BLOCKTYPE FloorBlock = GetBlock({ static_cast<int>(a_X), PotentialY - 2, static_cast<int>(a_Z) });
|
BLOCKTYPE FloorBlock = GetBlock({ a_X, PotentialY - 2, a_Z });
|
||||||
|
|
||||||
// Early out - Is the floor block air
|
// Early out - Is the floor block air
|
||||||
if (FloorBlock == E_BLOCK_AIR)
|
if (FloorBlock == E_BLOCK_AIR)
|
||||||
|
@ -834,12 +834,12 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!CheckPlayerSpawnPoint(static_cast<int>(a_X), PotentialY - 1, static_cast<int>(a_Z)))
|
if (!CheckPlayerSpawnPoint(a_X, PotentialY - 1, a_Z))
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
a_Y = PotentialY - 1.0;
|
a_Y = PotentialY - 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
16
src/World.h
16
src/World.h
|
@ -573,11 +573,11 @@ public:
|
||||||
|
|
||||||
/** Set default spawn at the given coordinates.
|
/** Set default spawn at the given coordinates.
|
||||||
Returns false if the new spawn couldn't be stored in the INI file. */
|
Returns false if the new spawn couldn't be stored in the INI file. */
|
||||||
bool SetSpawn(double a_X, double a_Y, double a_Z);
|
bool SetSpawn(int a_X, int a_Y, int a_Z);
|
||||||
|
|
||||||
double GetSpawnX(void) const { return m_SpawnX; }
|
int GetSpawnX(void) const { return m_SpawnX; }
|
||||||
double GetSpawnY(void) const { return m_SpawnY; }
|
int GetSpawnY(void) const { return m_SpawnY; }
|
||||||
double GetSpawnZ(void) const { return m_SpawnZ; }
|
int GetSpawnZ(void) const { return m_SpawnZ; }
|
||||||
|
|
||||||
/** Wakes up the simulators for the specified block */
|
/** Wakes up the simulators for the specified block */
|
||||||
virtual void WakeUpSimulators(Vector3i a_Block) override;
|
virtual void WakeUpSimulators(Vector3i a_Block) override;
|
||||||
|
@ -955,9 +955,9 @@ private:
|
||||||
eDimension m_Dimension;
|
eDimension m_Dimension;
|
||||||
|
|
||||||
bool m_IsSpawnExplicitlySet;
|
bool m_IsSpawnExplicitlySet;
|
||||||
double m_SpawnX;
|
int m_SpawnX;
|
||||||
double m_SpawnY;
|
int m_SpawnY;
|
||||||
double m_SpawnZ;
|
int m_SpawnZ;
|
||||||
|
|
||||||
// Variables defining the minimum and maximum size for a nether portal
|
// Variables defining the minimum and maximum size for a nether portal
|
||||||
int m_MinNetherPortalWidth;
|
int m_MinNetherPortalWidth;
|
||||||
|
@ -1125,7 +1125,7 @@ private:
|
||||||
|
|
||||||
/** Can the specified coordinates be used as a spawn point?
|
/** Can the specified coordinates be used as a spawn point?
|
||||||
Returns true if spawn position is valid and sets a_Y to the valid spawn height */
|
Returns true if spawn position is valid and sets a_Y to the valid spawn height */
|
||||||
bool CanSpawnAt(double a_X, double & a_Y, double a_Z);
|
bool CanSpawnAt(int a_X, int & a_Y, int a_Z);
|
||||||
|
|
||||||
/** Check if player starting point is acceptable */
|
/** Check if player starting point is acceptable */
|
||||||
bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ);
|
bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ);
|
||||||
|
|
|
@ -105,9 +105,9 @@ cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) :
|
||||||
Writer.AddByte("thundering", a_World->IsWeatherStorm() ? 1 : 0);
|
Writer.AddByte("thundering", a_World->IsWeatherStorm() ? 1 : 0);
|
||||||
Writer.AddInt("GameType", static_cast<int>(a_World->GetGameMode()));
|
Writer.AddInt("GameType", static_cast<int>(a_World->GetGameMode()));
|
||||||
Writer.AddInt("generatorVersion", 1);
|
Writer.AddInt("generatorVersion", 1);
|
||||||
Writer.AddInt("SpawnX", FloorC(a_World->GetSpawnX()));
|
Writer.AddInt("SpawnX", a_World->GetSpawnX());
|
||||||
Writer.AddInt("SpawnY", FloorC(a_World->GetSpawnY()));
|
Writer.AddInt("SpawnY", a_World->GetSpawnY());
|
||||||
Writer.AddInt("SpawnZ", FloorC(a_World->GetSpawnZ()));
|
Writer.AddInt("SpawnZ", a_World->GetSpawnZ());
|
||||||
Writer.AddInt("version", 19133);
|
Writer.AddInt("version", 19133);
|
||||||
Writer.AddLong("DayTime", a_World->GetWorldDate().count());
|
Writer.AddLong("DayTime", a_World->GetWorldDate().count());
|
||||||
Writer.AddLong("Time", a_World->GetWorldAge().count());
|
Writer.AddLong("Time", a_World->GetWorldAge().count());
|
||||||
|
|
Loading…
Reference in New Issue