summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-10-03 18:43:22 +0200
committerGitHub <noreply@github.com>2021-10-03 18:43:22 +0200
commit1e4850a6c5faed2d7906fe9d19ac327efefe7922 (patch)
treed9ddba00b1dade19ce695ea7d38ffe13cac62067
parentProtocol 1.8: fix duplicated vector component in spawn packet (#5314) (diff)
downloadcuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar.gz
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar.bz2
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar.lz
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar.xz
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.tar.zst
cuberite-1e4850a6c5faed2d7906fe9d19ac327efefe7922.zip
-rw-r--r--src/Entities/Entity.cpp4
-rw-r--r--src/Entities/Player.cpp2
-rw-r--r--src/Protocol/Protocol_1_14.cpp2
-rw-r--r--src/Protocol/Protocol_1_8.cpp2
-rw-r--r--src/Protocol/Protocol_1_9.cpp2
-rw-r--r--src/World.cpp80
-rw-r--r--src/World.h16
-rw-r--r--src/WorldStorage/WSSAnvil.cpp6
8 files changed, 57 insertions, 57 deletions
diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp
index e275d03da..bf4b9372c 100644
--- a/src/Entities/Entity.cpp
+++ b/src/Entities/Entity.cpp
@@ -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)
{
- 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 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);
}
diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp
index b99c0227a..24b9c19af 100644
--- a/src/Entities/Player.cpp
+++ b/src/Entities/Player.cpp
@@ -965,7 +965,7 @@ void cPlayer::Respawn(void)
const auto & DefaultWorld = *cRoot::Get()->GetDefaultWorld();
// 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");
}
diff --git a/src/Protocol/Protocol_1_14.cpp b/src/Protocol/Protocol_1_14.cpp
index 161bf2f4d..0d0bc49a0 100644
--- a/src/Protocol/Protocol_1_14.cpp
+++ b/src/Protocol/Protocol_1_14.cpp
@@ -82,7 +82,7 @@ void cProtocol_1_14::SendLogin(const cPlayer & a_Player, const cWorld & a_World)
// Send the spawn position:
{
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:
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index 1260e3ef8..d29126e4e 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -844,7 +844,7 @@ void cProtocol_1_8_0::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the spawn position:
{
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:
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index e6f774bdf..3b09ada4c 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -2265,7 +2265,7 @@ void cProtocol_1_9_1::SendLogin(const cPlayer & a_Player, const cWorld & a_World
// Send the spawn position:
{
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:
diff --git a/src/World.cpp b/src/World.cpp
index f7647aba3..3b52bd9aa 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -270,9 +270,9 @@ cWorld::cWorld(
if (m_IsSpawnExplicitlySet)
{
LOGD("Spawnpoint explicitly set!");
- m_SpawnX = IniFile.GetValueF("SpawnPosition", "X", m_SpawnX);
- m_SpawnY = IniFile.GetValueF("SpawnPosition", "Y", m_SpawnY);
- m_SpawnZ = IniFile.GetValueF("SpawnPosition", "Z", m_SpawnZ);
+ m_SpawnX = IniFile.GetValueI("SpawnPosition", "X", m_SpawnX);
+ m_SpawnY = IniFile.GetValueI("SpawnPosition", "Y", m_SpawnY);
+ m_SpawnZ = IniFile.GetValueI("SpawnPosition", "Z", m_SpawnZ);
}
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.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;
- FLOGD("Spawn set at {0}", Vector3d{m_SpawnX, m_SpawnY, m_SpawnZ});
- return true;
- }
- else
- {
- LOGWARNING("Couldn't write new spawn settings to \"%s\".", m_IniFileName.c_str());
- }
- return false;
+ IniFile.ReadFile(m_IniFileName);
+ IniFile.SetValueI("SpawnPosition", "X", a_X);
+ IniFile.SetValueI("SpawnPosition", "Y", a_Y);
+ IniFile.SetValueI("SpawnPosition", "Z", a_Z);
+ if (IniFile.WriteFile(m_IniFileName))
+ {
+ m_SpawnX = a_X;
+ m_SpawnY = a_Y;
+ m_SpawnZ = a_Z;
+ FLOGD("Spawn set at {}", Vector3i{m_SpawnX, m_SpawnY, m_SpawnZ});
+ return true;
+ }
+ else
+ {
+ LOGWARNING("Couldn't write new spawn settings to \"%s\".", m_IniFileName.c_str());
+ }
+ return false;
}
@@ -674,7 +674,7 @@ void cWorld::InitializeSpawn(void)
IniFile.WriteFile(m_IniFileName);
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);
}
@@ -724,17 +724,17 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
}
// Check 0, 0 first.
- double SpawnY = 0.0;
+ int SpawnY = 0;
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;
}
// 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[] =
{
Vector3i(0, 0, HalfChunk),
@@ -757,27 +757,27 @@ void cWorld::GenerateRandomSpawn(int a_MaxSpawnRadius)
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;
- 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);
- 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;
}
}
}
- m_SpawnY = GetHeight(static_cast<int>(m_SpawnX), static_cast<int>(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});
+ m_SpawnY = GetHeight(m_SpawnX, 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.
// 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);
// 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 LowestSpawnPoint = static_cast<int>(HighestSpawnPoint / 2.0f);
+ static const int HighestSpawnPoint = GetHeight(a_X, a_Z) + 2;
+ static const int LowestSpawnPoint = HighestSpawnPoint / 2;
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
if (HeadBlock != E_BLOCK_AIR)
@@ -806,7 +806,7 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
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
if (BodyBlock != E_BLOCK_AIR)
@@ -814,7 +814,7 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
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
if (FloorBlock == E_BLOCK_AIR)
@@ -834,12 +834,12 @@ bool cWorld::CanSpawnAt(double a_X, double & a_Y, double a_Z)
continue;
}
- if (!CheckPlayerSpawnPoint(static_cast<int>(a_X), PotentialY - 1, static_cast<int>(a_Z)))
+ if (!CheckPlayerSpawnPoint(a_X, PotentialY - 1, a_Z))
{
continue;
}
- a_Y = PotentialY - 1.0;
+ a_Y = PotentialY - 1;
return true;
}
diff --git a/src/World.h b/src/World.h
index 71e23c463..eab6422f4 100644
--- a/src/World.h
+++ b/src/World.h
@@ -573,11 +573,11 @@ public:
/** Set default spawn at the given coordinates.
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; }
- double GetSpawnY(void) const { return m_SpawnY; }
- double GetSpawnZ(void) const { return m_SpawnZ; }
+ int GetSpawnX(void) const { return m_SpawnX; }
+ int GetSpawnY(void) const { return m_SpawnY; }
+ int GetSpawnZ(void) const { return m_SpawnZ; }
/** Wakes up the simulators for the specified block */
virtual void WakeUpSimulators(Vector3i a_Block) override;
@@ -955,9 +955,9 @@ private:
eDimension m_Dimension;
bool m_IsSpawnExplicitlySet;
- double m_SpawnX;
- double m_SpawnY;
- double m_SpawnZ;
+ int m_SpawnX;
+ int m_SpawnY;
+ int m_SpawnZ;
// Variables defining the minimum and maximum size for a nether portal
int m_MinNetherPortalWidth;
@@ -1125,7 +1125,7 @@ private:
/** 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 */
- 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 */
bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ);
diff --git a/src/WorldStorage/WSSAnvil.cpp b/src/WorldStorage/WSSAnvil.cpp
index d901c061a..dbbd03daf 100644
--- a/src/WorldStorage/WSSAnvil.cpp
+++ b/src/WorldStorage/WSSAnvil.cpp
@@ -105,9 +105,9 @@ cWSSAnvil::cWSSAnvil(cWorld * a_World, int a_CompressionFactor) :
Writer.AddByte("thundering", a_World->IsWeatherStorm() ? 1 : 0);
Writer.AddInt("GameType", static_cast<int>(a_World->GetGameMode()));
Writer.AddInt("generatorVersion", 1);
- Writer.AddInt("SpawnX", FloorC(a_World->GetSpawnX()));
- Writer.AddInt("SpawnY", FloorC(a_World->GetSpawnY()));
- Writer.AddInt("SpawnZ", FloorC(a_World->GetSpawnZ()));
+ Writer.AddInt("SpawnX", a_World->GetSpawnX());
+ Writer.AddInt("SpawnY", a_World->GetSpawnY());
+ Writer.AddInt("SpawnZ", a_World->GetSpawnZ());
Writer.AddInt("version", 19133);
Writer.AddLong("DayTime", a_World->GetWorldDate().count());
Writer.AddLong("Time", a_World->GetWorldAge().count());