summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Blocks/BlockBed.cpp24
-rw-r--r--src/Blocks/BlockBed.h25
-rw-r--r--src/Blocks/BlockDirt.h6
-rw-r--r--src/ChunkMap.cpp5
-rw-r--r--src/ClientHandle.cpp29
-rw-r--r--src/Entities/Player.h14
-rw-r--r--src/FastRandom.cpp34
-rw-r--r--src/FastRandom.h6
-rw-r--r--src/Map.cpp4
-rw-r--r--src/MobSpawner.cpp9
-rw-r--r--src/Mobs/AggressiveMonster.cpp5
-rw-r--r--src/Mobs/Blaze.cpp2
-rw-r--r--src/Mobs/Ghast.cpp2
-rw-r--r--src/Mobs/Skeleton.cpp3
-rw-r--r--src/Protocol/Protocol18x.cpp4
-rw-r--r--src/World.cpp70
-rw-r--r--src/World.h3
17 files changed, 134 insertions, 111 deletions
diff --git a/src/Blocks/BlockBed.cpp b/src/Blocks/BlockBed.cpp
index 57b9855d0..e56f4bfe0 100644
--- a/src/Blocks/BlockBed.cpp
+++ b/src/Blocks/BlockBed.cpp
@@ -1,14 +1,9 @@
#include "Globals.h"
#include "BlockBed.h"
-
-
-
#include "BroadcastInterface.h"
-#include "ChunkInterface.h"
#include "Entities/../World.h"
#include "Entities/Player.h"
-#include "WorldInterface.h"
@@ -64,21 +59,22 @@ class cPlayerBedStateUnsetter :
public cPlayerListCallback
{
public:
- cPlayerBedStateUnsetter(Vector3i a_Position, cWorldInterface & a_WorldInterface) :
- m_Position(a_Position), m_WorldInterface(a_WorldInterface)
+ cPlayerBedStateUnsetter(Vector3i a_Position, cChunkInterface & a_ChunkInterface) :
+ m_Position(a_Position),
+ m_ChunkInterface(a_ChunkInterface)
{
}
virtual bool Item(cPlayer * a_Player) override
{
+ cBlockBedHandler::SetBedOccupationState(m_ChunkInterface, a_Player->GetLastBedPos(), false);
a_Player->SetIsInBed(false);
- m_WorldInterface.GetBroadcastManager().BroadcastEntityAnimation(*a_Player, 2);
return false;
}
private:
Vector3i m_Position;
- cWorldInterface & m_WorldInterface;
+ cChunkInterface & m_ChunkInterface;
};
@@ -97,7 +93,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
if (a_WorldInterface.GetTimeOfDay() > 13000)
{
NIBBLETYPE Meta = a_ChunkInterface.GetBlockMeta(a_BlockX, a_BlockY, a_BlockZ);
- if (Meta & 0x4)
+ if ((Meta & 0x4) == 0x4)
{
a_Player->SendMessageFailure("This bed is occupied");
}
@@ -105,7 +101,7 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
{
Vector3i PillowDirection(0, 0, 0);
- if (Meta & 0x8)
+ if ((Meta & 0x8) == 0x8)
{
// Is pillow
a_WorldInterface.GetBroadcastManager().BroadcastUseBed(*a_Player, a_BlockX, a_BlockY, a_BlockZ);
@@ -122,15 +118,15 @@ void cBlockBedHandler::OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface
}
}
- a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta | 0x4); // Where 0x4 = occupied bit
- a_Player->SetIsInBed(true);
a_Player->SetBedPos(Vector3i(a_BlockX, a_BlockY, a_BlockZ));
+ SetBedOccupationState(a_ChunkInterface, a_Player->GetLastBedPos(), true);
+ a_Player->SetIsInBed(true);
a_Player->SendMessageSuccess("Home position set successfully");
cTimeFastForwardTester Tester;
if (a_WorldInterface.ForEachPlayer(Tester))
{
- cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_WorldInterface);
+ cPlayerBedStateUnsetter Unsetter(Vector3i(a_BlockX + PillowDirection.x, a_BlockY, a_BlockZ + PillowDirection.z), a_ChunkInterface);
a_WorldInterface.ForEachPlayer(Unsetter);
a_WorldInterface.SetTimeOfDay(0);
a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, Meta & 0x0b); // Clear the "occupied" bit of the bed's block
diff --git a/src/Blocks/BlockBed.h b/src/Blocks/BlockBed.h
index 5b746110a..46f361686 100644
--- a/src/Blocks/BlockBed.h
+++ b/src/Blocks/BlockBed.h
@@ -4,9 +4,9 @@
#include "BlockHandler.h"
#include "MetaRotator.h"
#include "Item.h"
+#include "ChunkInterface.h"
-class cChunkInterface;
class cPlayer;
class cWorldInterface;
@@ -21,17 +21,14 @@ public:
: cMetaRotator<cBlockHandler, 0x3, 0x02, 0x03, 0x00, 0x01, true>(a_BlockType)
{
}
-
-
+
virtual void OnDestroyed(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, int a_BlockX, int a_BlockY, int a_BlockZ) override;
virtual void OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer * a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override;
-
virtual bool IsUseable(void) override
{
return true;
}
-
virtual void ConvertToPickups(cItems & a_Pickups, NIBBLETYPE a_BlockMeta) override
{
@@ -39,14 +36,12 @@ public:
a_Pickups.push_back(cItem(E_ITEM_BED, 1, 0));
}
-
virtual bool CanDirtGrowGrass(NIBBLETYPE a_Meta) override
{
return true;
}
-
// Bed specific helper functions
static NIBBLETYPE RotationToMetaData(double a_Rotation)
{
@@ -61,7 +56,6 @@ public:
return ((char)a_Rotation + 2) % 4;
}
-
static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData)
{
switch (a_MetaData)
@@ -73,6 +67,21 @@ public:
}
return Vector3i();
}
+
+ static void SetBedOccupationState(cChunkInterface & a_ChunkInterface, const Vector3i & a_BedPosition, bool a_IsOccupied)
+ {
+ auto Meta = a_ChunkInterface.GetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z);
+ if (a_IsOccupied)
+ {
+ Meta |= 0x04; // Where 0x4 = occupied bit
+ }
+ else
+ {
+ Meta &= 0x0b; // Clear the "occupied" bit of the bed's block
+ }
+
+ a_ChunkInterface.SetBlockMeta(a_BedPosition.x, a_BedPosition.y, a_BedPosition.z, Meta);
+ }
} ;
diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h
index 12bca92dd..cc0d845e4 100644
--- a/src/Blocks/BlockDirt.h
+++ b/src/Blocks/BlockDirt.h
@@ -69,9 +69,9 @@ public:
cFastRandom rand;
for (int i = 0; i < 2; i++) // Pick two blocks to grow to
{
- int OfsX = rand.NextInt(3, a_RelX) - 1; // [-1 .. 1]
- int OfsY = rand.NextInt(5, a_RelY) - 3; // [-3 .. 1]
- int OfsZ = rand.NextInt(3, a_RelZ) - 1; // [-1 .. 1]
+ int OfsX = rand.NextInt(3) - 1; // [-1 .. 1]
+ int OfsY = rand.NextInt(5) - 3; // [-3 .. 1]
+ int OfsZ = rand.NextInt(3) - 1; // [-1 .. 1]
BLOCKTYPE DestBlock;
NIBBLETYPE DestMeta;
diff --git a/src/ChunkMap.cpp b/src/ChunkMap.cpp
index 2dd04f801..b9d4ed55b 100644
--- a/src/ChunkMap.cpp
+++ b/src/ChunkMap.cpp
@@ -1322,10 +1322,7 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
void cChunkMap::SetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, bool a_SendToClients)
{
cChunkInterface ChunkInterface(this);
- if (a_BlockType == E_BLOCK_AIR)
- {
- BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, *m_World, a_BlockX, a_BlockY, a_BlockZ);
- }
+ BlockHandler(GetBlock(a_BlockX, a_BlockY, a_BlockZ))->OnDestroyed(ChunkInterface, *m_World, a_BlockX, a_BlockY, a_BlockZ);
int ChunkX, ChunkZ, X = a_BlockX, Y = a_BlockY, Z = a_BlockZ;
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp
index 4fbce2b67..ec10ac521 100644
--- a/src/ClientHandle.cpp
+++ b/src/ClientHandle.cpp
@@ -21,6 +21,7 @@
#include "Items/ItemHandler.h"
#include "Blocks/BlockHandler.h"
#include "Blocks/BlockSlab.h"
+#include "Blocks/BlockBed.h"
#include "Blocks/ChunkInterface.h"
#include "Root.h"
@@ -1501,30 +1502,6 @@ void cClientHandle::HandleAnimation(int a_Animation)
return;
}
- // Because the animation ID sent to servers by clients are different to those sent back, we need this
- switch (a_Animation)
- {
- case 0: // No animation - wiki.vg doesn't say that client has something specific for it, so I suppose it will just become -1
- case 1:
- case 2:
- case 3:
- {
- a_Animation--; // Offset by -1
- break;
- }
- case 5:
- case 6:
- case 7:
- {
- a_Animation -= 2; // Offset by -2
- break;
- }
- default: // Anything else is the same
- {
- break;
- }
- }
-
m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, a_Animation, this);
}
@@ -1766,7 +1743,9 @@ void cClientHandle::HandleEntityLeaveBed(int a_EntityID)
return;
}
- m_Player->GetWorld()->BroadcastEntityAnimation(*m_Player, 2);
+ cChunkInterface Interface(GetPlayer()->GetWorld()->GetChunkMap());
+ cBlockBedHandler::SetBedOccupationState(Interface, GetPlayer()->GetLastBedPos(), false);
+ GetPlayer()->SetIsInBed(false);
}
diff --git a/src/Entities/Player.h b/src/Entities/Player.h
index e02c66bd3..3dae58dc1 100644
--- a/src/Entities/Player.h
+++ b/src/Entities/Player.h
@@ -314,8 +314,18 @@ public:
// tolua_end
- /** Sets a player's in-bed state; we can't be sure plugins will keep this value updated, so no exporting */
- void SetIsInBed(bool a_Flag) { m_bIsInBed = a_Flag; }
+ /** Sets a player's in-bed state
+ We can't be sure plugins will keep this value updated, so no exporting
+ If value is false (not in bed), will update players of the fact that they have been ejected from the bed
+ */
+ void SetIsInBed(bool a_Flag)
+ {
+ m_bIsInBed = a_Flag;
+ if (!a_Flag)
+ {
+ GetWorld()->BroadcastEntityAnimation(*this, 2);
+ }
+ }
/** Starts eating the currently equipped item. Resets the eating timer and sends the proper animation packet */
void StartEating(void);
diff --git a/src/FastRandom.cpp b/src/FastRandom.cpp
index 515dc25ea..737b13535 100644
--- a/src/FastRandom.cpp
+++ b/src/FastRandom.cpp
@@ -6,6 +6,12 @@
#include "Globals.h"
#include "FastRandom.h"
+#ifdef _WIN32
+ #define thread_local __declspec(thread)
+#endif
+
+thread_local unsigned int m_Counter = 0;
+
@@ -86,7 +92,7 @@ public:
cFastRandom::cFastRandom(void) :
- m_LinearRand(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()))
+ m_LinearRand(m_Counter++)
{
}
@@ -105,18 +111,6 @@ int cFastRandom::NextInt(int a_Range)
-int cFastRandom::NextInt(int a_Range, int a_Salt)
-{
- m_LinearRand.seed(a_Salt);
- std::uniform_int_distribution<> distribution(0, a_Range - 1);
- return distribution(m_LinearRand);
-}
-
-
-
-
-
-
float cFastRandom::NextFloat(float a_Range)
{
std::uniform_real_distribution<float> distribution(0, a_Range);
@@ -128,18 +122,6 @@ float cFastRandom::NextFloat(float a_Range)
-float cFastRandom::NextFloat(float a_Range, int a_Salt)
-{
- m_LinearRand.seed(a_Salt);
- std::uniform_real_distribution<float> distribution(0, a_Range);
- return distribution(m_LinearRand);
-}
-
-
-
-
-
-
int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End)
{
std::uniform_int_distribution<> distribution(a_Begin, a_End);
@@ -154,7 +136,7 @@ int cFastRandom::GenerateRandomInteger(int a_Begin, int a_End)
// MTRand:
MTRand::MTRand() :
- m_MersenneRand(static_cast<unsigned>(std::chrono::system_clock::now().time_since_epoch().count()))
+ m_MersenneRand(m_Counter++)
{
}
diff --git a/src/FastRandom.h b/src/FastRandom.h
index 64a087c97..30395a293 100644
--- a/src/FastRandom.h
+++ b/src/FastRandom.h
@@ -36,16 +36,10 @@ public:
/** Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M */
int NextInt(int a_Range);
-
- /** Returns a random int in the range [0 .. a_Range - 1]; a_Range must be less than 1M; a_Salt is additional source of randomness */
- int NextInt(int a_Range, int a_Salt);
/** Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M */
float NextFloat(float a_Range);
- /** Returns a random float in the range [0 .. a_Range]; a_Range must be less than 1M; a_Salt is additional source of randomness */
- float NextFloat(float a_Range, int a_Salt);
-
/** Returns a random float between 0 and 1. */
float NextFloat(void) { return NextFloat(1); }
diff --git a/src/Map.cpp b/src/Map.cpp
index fbde00cf7..5e57cc8ec 100644
--- a/src/Map.cpp
+++ b/src/Map.cpp
@@ -66,10 +66,8 @@ void cMapDecorator::Update(void)
{
cFastRandom Random;
- Int64 WorldAge = m_Player->GetWorld()->GetWorldAge();
-
// TODO 2014-02-19 xdot: Refine
- m_Rot = Random.NextInt(16, (int) WorldAge);
+ m_Rot = Random.NextInt(16);
}
else
{
diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp
index 541135996..7a5238fd8 100644
--- a/src/MobSpawner.cpp
+++ b/src/MobSpawner.cpp
@@ -110,8 +110,7 @@ eMonsterType cMobSpawner::ChooseMobType(EMCSBiome a_Biome)
if (allowedMobsSize > 0)
{
std::set<eMonsterType>::iterator itr = allowedMobs.begin();
- static int Counter = 0;
- int iRandom = m_Random.NextInt((int)allowedMobsSize, Counter++);
+ int iRandom = m_Random.NextInt((int)allowedMobsSize);
for (int i = 0; i < iRandom; i++)
{
@@ -187,7 +186,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(BlockBelow == E_BLOCK_GRASS) || (BlockBelow == E_BLOCK_LEAVES) || (BlockBelow == E_BLOCK_NEW_LEAVES)
) &&
(a_RelY >= 62) &&
- (Random.NextInt(3, a_Biome) != 0)
+ (Random.NextInt(3) != 0)
);
}
@@ -248,7 +247,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(!cBlockInfo::IsTransparent(BlockBelow)) &&
(SkyLight <= 7) &&
(BlockLight <= 7) &&
- (Random.NextInt(2, a_Biome) == 0)
+ (Random.NextInt(2) == 0)
);
}
@@ -272,7 +271,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) &&
(!cBlockInfo::IsTransparent(BlockBelow)) &&
- (Random.NextInt(20, a_Biome) == 0)
+ (Random.NextInt(20) == 0)
);
}
diff --git a/src/Mobs/AggressiveMonster.cpp b/src/Mobs/AggressiveMonster.cpp
index 72317d66b..526b39e39 100644
--- a/src/Mobs/AggressiveMonster.cpp
+++ b/src/Mobs/AggressiveMonster.cpp
@@ -85,7 +85,7 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
if (ReachedFinalDestination() && !LineOfSight.Trace(GetPosition(), AttackDirection, (int)AttackDirection.Length()))
{
// Attack if reached destination, target isn't null, and have a clear line of sight to target (so won't attack through walls)
- Attack(a_Dt / 1000);
+ Attack(a_Dt);
}
}
@@ -95,8 +95,7 @@ void cAggressiveMonster::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
void cAggressiveMonster::Attack(std::chrono::milliseconds a_Dt)
{
- m_AttackInterval += a_Dt.count() * m_AttackRate;
-
+ m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
if ((m_Target == nullptr) || (m_AttackInterval < 3.0))
{
return;
diff --git a/src/Mobs/Blaze.cpp b/src/Mobs/Blaze.cpp
index 172ccd071..89eeb3709 100644
--- a/src/Mobs/Blaze.cpp
+++ b/src/Mobs/Blaze.cpp
@@ -32,7 +32,7 @@ void cBlaze::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cBlaze::Attack(std::chrono::milliseconds a_Dt)
{
- m_AttackInterval += a_Dt.count() * m_AttackRate;
+ m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
if ((m_Target != nullptr) && (m_AttackInterval > 3.0))
{
diff --git a/src/Mobs/Ghast.cpp b/src/Mobs/Ghast.cpp
index ea0295102..d17047ab7 100644
--- a/src/Mobs/Ghast.cpp
+++ b/src/Mobs/Ghast.cpp
@@ -34,7 +34,7 @@ void cGhast::GetDrops(cItems & a_Drops, cEntity * a_Killer)
void cGhast::Attack(std::chrono::milliseconds a_Dt)
{
- m_AttackInterval += a_Dt.count() * m_AttackRate;
+ m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
if ((m_Target != nullptr) && (m_AttackInterval > 3.0))
{
diff --git a/src/Mobs/Skeleton.cpp b/src/Mobs/Skeleton.cpp
index dd59d6454..331c8e8ad 100644
--- a/src/Mobs/Skeleton.cpp
+++ b/src/Mobs/Skeleton.cpp
@@ -69,8 +69,7 @@ void cSkeleton::MoveToPosition(const Vector3d & a_Position)
void cSkeleton::Attack(std::chrono::milliseconds a_Dt)
{
- m_AttackInterval += a_Dt.count() * m_AttackRate;
-
+ m_AttackInterval += (static_cast<float>(a_Dt.count()) / 1000) * m_AttackRate;
if ((m_Target != nullptr) && (m_AttackInterval > 3.0))
{
// Setting this higher gives us more wiggle room for attackrate
diff --git a/src/Protocol/Protocol18x.cpp b/src/Protocol/Protocol18x.cpp
index 52c369200..2d1a473d1 100644
--- a/src/Protocol/Protocol18x.cpp
+++ b/src/Protocol/Protocol18x.cpp
@@ -2097,9 +2097,7 @@ void cProtocol180::HandlePacketLoginStart(cByteBuffer & a_ByteBuffer)
void cProtocol180::HandlePacketAnimation(cByteBuffer & a_ByteBuffer)
{
- HANDLE_READ(a_ByteBuffer, ReadBEInt, int, EntityID);
- HANDLE_READ(a_ByteBuffer, ReadByte, Byte, Animation);
- m_Client->HandleAnimation(Animation);
+ m_Client->HandleAnimation(1); // Packet exists solely for arm-swing notification
}
diff --git a/src/World.cpp b/src/World.cpp
index 474f77b81..f3837eb02 100644
--- a/src/World.cpp
+++ b/src/World.cpp
@@ -667,18 +667,23 @@ void cWorld::Start(void)
void cWorld::GenerateRandomSpawn(void)
{
LOGD("Generating random spawnpoint...");
-
+ bool foundSpawnPoint = false;
// Look for a spawn point at most 100 chunks away from map center:
for (int i = 0; i < 100; i++)
{
EMCSBiome biome = GetBiomeAt((int)m_SpawnX, (int)m_SpawnZ);
+
if (
(biome != biOcean) && (biome != biFrozenOcean) && // The biome is acceptable (don't want a small ocean island)
!IsBlockWaterOrIce(GetBlock((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ)) // The terrain is acceptable (don't want to spawn inside a lake / river)
)
{
- // A good spawnpoint was found
- break;
+ if (CheckPlayerSpawnPoint((int)m_SpawnX, GetHeight((int)m_SpawnX, (int)m_SpawnZ), (int)m_SpawnZ))
+ {
+ // A good spawnpoint was found
+ foundSpawnPoint = true;
+ break;
+ }
}
// Try a neighboring chunk:
if ((GetTickRandomNumber(4) % 2) == 0) // Randomise whether to increment X or Z coords
@@ -692,8 +697,63 @@ void cWorld::GenerateRandomSpawn(void)
} // for i - 100*
m_SpawnY = (double)GetHeight((int)m_SpawnX, (int)m_SpawnZ) + 1.6f; // 1.6f to accomodate player height
+ if (foundSpawnPoint)
+ {
+ LOGINFO("Generated random spawnpoint position at {%i, %i, %i}", (int)m_SpawnX, (int)m_SpawnY, (int)m_SpawnZ);
+ }
+ else
+ {
+ LOGINFO("Did not find an acceptable spawnpoint. Generated a random spawnpoint position at {%i, %i, %i}", (int)m_SpawnX, (int)m_SpawnY, (int)m_SpawnZ);
+ } // Maybe widen the search instead?
+
+}
+
+
+
+
+
+bool cWorld::CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ)
+{
+ static const struct
+ {
+ int x, z;
+ } Coords[] =
+ {
+ { 0, 0 },
+ { -1, 0 },
+ { 1, 0 },
+ { 0, -1 },
+ { 0, 1 },
+ };
+
+ // Checking that spawnblock and surrounding blocks are air and not water/lava
+ for (size_t i = 0; i < ARRAYCOUNT(Coords); i++)
+ {
+ BLOCKTYPE BlockType = GetBlock(a_PosX + Coords[i].x, a_PosY, a_PosZ + Coords[i].x);
+
+ if (cBlockInfo::IsSolid(BlockType) || IsBlockLiquid(BlockType))
+ {
+ return false;
+ }
+ } // for i - Coords[]
+
+ // Check if block below is solid
+ BLOCKTYPE BlockType = GetBlock(a_PosX, a_PosY - 1, a_PosZ);
+ if (!cBlockInfo::IsSolid(BlockType))
+ {
+ return false;
+ }
- LOGINFO("Generated random spawnpoint position {%i, %i, %i}", (int)m_SpawnX, (int)m_SpawnY, (int)m_SpawnZ);
+ // Checking that all the blocks above the spawnpoint is air.
+ for (int i = a_PosY; i < cChunkDef::Height; i++)
+ {
+ BLOCKTYPE BlockType = GetBlock(a_PosX, i, a_PosZ);
+ if (cBlockInfo::IsSolid(BlockType))
+ {
+ return false;
+ }
+ }
+ return true;
}
@@ -3578,7 +3638,7 @@ void cWorld::cTaskUnloadUnusedChunks::Run(cWorld & a_World)
////////////////////////////////////////////////////////////////////////////////
-// cWorld::cTaskSendBlockTo
+// cWorld::cTaskSendBlockToAllPlayers
cWorld::cTaskSendBlockToAllPlayers::cTaskSendBlockToAllPlayers(std::vector<Vector3i> & a_SendQueue) :
m_SendQueue(a_SendQueue)
diff --git a/src/World.h b/src/World.h
index 3cac71a36..0decc8c6e 100644
--- a/src/World.h
+++ b/src/World.h
@@ -1077,6 +1077,9 @@ private:
/** <summary>Generates a random spawnpoint on solid land by walking chunks and finding their biomes</summary> */
void GenerateRandomSpawn(void);
+ /** Check if player starting point is acceptable **/
+ bool CheckPlayerSpawnPoint(int a_PosX, int a_PosY, int a_PosZ);
+
/** Chooses a reasonable transition from the current weather to a new weather **/
eWeather ChooseNewWeather(void);