1
0

Merge remote-tracking branch 'origin/master' into EntitiesInBox

This commit is contained in:
madmaxoft 2014-09-04 14:02:18 +02:00
commit 3297a39c27
32 changed files with 377 additions and 263 deletions

@ -1 +1 @@
Subproject commit 27b9d111818af3b05bcf4153bb6e380fe1dd6816 Subproject commit 203c2fb68bbf871eaf4ca98756a113d74d620dea

View File

@ -668,6 +668,24 @@ void cIniFile::Clear(void)
bool cIniFile::HasValue(const AString & a_KeyName, const AString & a_ValueName)
{
// Find the key:
int keyID = FindKey(a_KeyName);
if (keyID == noID)
{
return false;
}
// Find the value:
int valueID = FindValue(keyID, a_ValueName);
return (valueID != noID);
}
void cIniFile::AddHeaderComment(const AString & comment) void cIniFile::AddHeaderComment(const AString & comment)
{ {
comments.push_back(comment); comments.push_back(comment);

View File

@ -53,7 +53,9 @@ private:
/// Removes the UTF-8 BOMs (Byte order makers), if present. /// Removes the UTF-8 BOMs (Byte order makers), if present.
void RemoveBom(AString & a_line) const; void RemoveBom(AString & a_line) const;
public: public:
enum errors enum errors
{ {
noID = -1, noID = -1,
@ -79,6 +81,9 @@ public:
/// Deletes all stored ini data (but doesn't touch the file) /// Deletes all stored ini data (but doesn't touch the file)
void Clear(void); void Clear(void);
/** Returns true iff the specified value exists. */
bool HasValue(const AString & a_KeyName, const AString & a_ValueName);
/// Returns index of specified key, or noID if not found /// Returns index of specified key, or noID if not found
int FindKey(const AString & keyname) const; int FindKey(const AString & keyname) const;

View File

@ -36,7 +36,9 @@ extern "C" {
#define TEMPLATE_BIND(p) #define TEMPLATE_BIND(p)
#endif #endif
#define TOLUA_TEMPLATE_BIND(p) #ifndef TOLUA_TEMPLATE_BIND
#define TOLUA_TEMPLATE_BIND(p)
#endif
#define TOLUA_PROTECTED_DESTRUCTOR #define TOLUA_PROTECTED_DESTRUCTOR
#define TOLUA_PROPERTY_TYPE(p) #define TOLUA_PROPERTY_TYPE(p)

View File

@ -107,7 +107,7 @@ void cLuaChunkStay::AddChunkCoord(cLuaState & L, int a_Index)
} }
} // for itr - m_Chunks[] } // for itr - m_Chunks[]
m_Chunks.push_back(cChunkCoords(ChunkX, ZERO_CHUNK_Y, ChunkZ)); m_Chunks.push_back(cChunkCoords(ChunkX, ChunkZ));
} }

View File

@ -362,6 +362,8 @@ enum ENUM_ITEM_ID
E_ITEM_LEAD = 420, E_ITEM_LEAD = 420,
E_ITEM_NAME_TAG = 421, E_ITEM_NAME_TAG = 421,
E_ITEM_MINECART_WITH_COMMAND_BLOCK = 422, E_ITEM_MINECART_WITH_COMMAND_BLOCK = 422,
E_ITEM_RAW_MUTTON = 423,
E_ITEM_MUTTON = 424,
// Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++ // Keep these two as the last values of the consecutive list, without a number - they will get their correct number assigned automagically by C++
// IsValidItem() depends on this! // IsValidItem() depends on this!

View File

@ -66,7 +66,7 @@ sSetBlock::sSetBlock( int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_Bloc
// cChunk: // cChunk:
cChunk::cChunk( cChunk::cChunk(
int a_ChunkX, int a_ChunkY, int a_ChunkZ, int a_ChunkX, int a_ChunkZ,
cChunkMap * a_ChunkMap, cWorld * a_World, cChunkMap * a_ChunkMap, cWorld * a_World,
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP,
cAllocationPool<cChunkData::sChunkSection> & a_Pool cAllocationPool<cChunkData::sChunkSection> & a_Pool
@ -78,7 +78,6 @@ cChunk::cChunk(
m_HasLoadFailed(false), m_HasLoadFailed(false),
m_StayCount(0), m_StayCount(0),
m_PosX(a_ChunkX), m_PosX(a_ChunkX),
m_PosY(a_ChunkY),
m_PosZ(a_ChunkZ), m_PosZ(a_ChunkZ),
m_World(a_World), m_World(a_World),
m_ChunkMap(a_ChunkMap), m_ChunkMap(a_ChunkMap),
@ -654,7 +653,7 @@ void cChunk::MoveEntityToNewChunk(cEntity * a_Entity)
cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width); cChunk * Neighbor = GetNeighborChunk(a_Entity->GetChunkX() * cChunkDef::Width, a_Entity->GetChunkZ() * cChunkDef::Width);
if (Neighbor == NULL) if (Neighbor == NULL)
{ {
Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); Neighbor = m_ChunkMap->GetChunkNoLoad(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if (Neighbor == NULL) if (Neighbor == NULL)
{ {
// TODO: What to do with this? // TODO: What to do with this?
@ -2628,7 +2627,7 @@ cChunk * cChunk::GetRelNeighborChunk(int a_RelX, int a_RelZ)
int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ; int BlockZ = m_PosZ * cChunkDef::Width + a_RelZ;
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ); BlockToChunk(BlockX, BlockZ, ChunkX, ChunkZ);
return m_ChunkMap->GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); return m_ChunkMap->GetChunkNoLoad(ChunkX, ChunkZ);
} }
// Walk the neighbors: // Walk the neighbors:

View File

@ -67,7 +67,7 @@ class cChunk :
{ {
public: public:
cChunk( cChunk(
int a_ChunkX, int a_ChunkY, int a_ChunkZ, // Chunk coords int a_ChunkX, int a_ChunkZ, // Chunk coords
cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects cChunkMap * a_ChunkMap, cWorld * a_World, // Parent objects
cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks cChunk * a_NeighborXM, cChunk * a_NeighborXP, cChunk * a_NeighborZM, cChunk * a_NeighborZP, // Neighbor chunks
cAllocationPool<cChunkData::sChunkSection> & a_Pool cAllocationPool<cChunkData::sChunkSection> & a_Pool

View File

@ -16,11 +16,6 @@
/** This is really only a placeholder to be used in places where we need to "make up" a chunk's Y coord.
It will help us when the new chunk format comes out and we need to patch everything up for compatibility.
*/
#define ZERO_CHUNK_Y 0
// Used to smoothly convert to new axis ordering. One will be removed when deemed stable. // Used to smoothly convert to new axis ordering. One will be removed when deemed stable.
#define AXIS_ORDER_YZX 1 // Original (1.1-) #define AXIS_ORDER_YZX 1 // Original (1.1-)
#define AXIS_ORDER_XZY 2 // New (1.2+) #define AXIS_ORDER_XZY 2 // New (1.2+)
@ -377,14 +372,13 @@ class cChunkCoords
{ {
public: public:
int m_ChunkX; int m_ChunkX;
int m_ChunkY;
int m_ChunkZ; int m_ChunkZ;
cChunkCoords(int a_ChunkX, int a_ChunkY, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ) {} cChunkCoords(int a_ChunkX, int a_ChunkZ) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ) {}
bool operator == (const cChunkCoords & a_Other) const bool operator == (const cChunkCoords & a_Other) const
{ {
return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkY == a_Other.m_ChunkY) && (m_ChunkZ == a_Other.m_ChunkZ)); return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ));
} }
} ; } ;
@ -395,6 +389,27 @@ typedef std::vector<cChunkCoords> cChunkCoordsVector;
class cChunkCoordsWithBool
{
public:
int m_ChunkX;
int m_ChunkZ;
bool m_ForceGenerate;
cChunkCoordsWithBool(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_ForceGenerate(a_ForceGenerate){}
bool operator == (const cChunkCoordsWithBool & a_Other) const
{
return ((m_ChunkX == a_Other.m_ChunkX) && (m_ChunkZ == a_Other.m_ChunkZ) && (m_ForceGenerate == a_Other.m_ForceGenerate));
}
};
typedef std::list<cChunkCoordsWithBool> cChunkCoordsWithBoolList;
/// Interface class used as a callback for operations that involve chunk coords /// Interface class used as a callback for operations that involve chunk coords
class cChunkCoordCallback class cChunkCoordCallback
{ {

View File

@ -143,7 +143,7 @@ cChunkMap::cChunkLayer * cChunkMap::GetLayerForChunk(int a_ChunkX, int a_ChunkZ)
cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkZ)
{ {
// No need to lock m_CSLayers, since it's already locked by the operation that called us // No need to lock m_CSLayers, since it's already locked by the operation that called us
ASSERT(m_CSLayers.IsLockedByCurrentThread()); ASSERT(m_CSLayers.IsLockedByCurrentThread());
@ -155,14 +155,14 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return NULL; return NULL;
} }
cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return NULL; return NULL;
} }
if (!(Chunk->IsValid())) if (!(Chunk->IsValid()))
{ {
m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, true); m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ, true);
} }
return Chunk; return Chunk;
} }
@ -171,7 +171,7 @@ cChunkPtr cChunkMap::GetChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ) cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkZ)
{ {
// No need to lock m_CSLayers, since it's already locked by the operation that called us // No need to lock m_CSLayers, since it's already locked by the operation that called us
cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ); cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ);
@ -181,14 +181,14 @@ cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return NULL; return NULL;
} }
cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); cChunkPtr Chunk = Layer->GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return NULL; return NULL;
} }
if (!(Chunk->IsValid())) if (!(Chunk->IsValid()))
{ {
m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ, false); m_World->GetStorage().QueueLoadChunk(a_ChunkX, a_ChunkZ, false);
} }
return Chunk; return Chunk;
@ -198,7 +198,7 @@ cChunkPtr cChunkMap::GetChunkNoGen( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ) cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkZ)
{ {
// No need to lock m_CSLayers, since it's already locked by the operation that called us // No need to lock m_CSLayers, since it's already locked by the operation that called us
cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ); cChunkLayer * Layer = GetLayerForChunk( a_ChunkX, a_ChunkZ);
@ -208,7 +208,7 @@ cChunkPtr cChunkMap::GetChunkNoLoad( int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return NULL; return NULL;
} }
return Layer->GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); return Layer->GetChunk(a_ChunkX, a_ChunkZ);
} }
@ -222,7 +222,7 @@ bool cChunkMap::LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -244,7 +244,7 @@ bool cChunkMap::LockedGetBlockType(int a_BlockX, int a_BlockY, int a_BlockZ, BLO
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -265,7 +265,7 @@ bool cChunkMap::LockedGetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIB
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -284,7 +284,7 @@ bool cChunkMap::LockedSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTY
// We already have m_CSLayers locked since this can be called only from within the tick thread // We already have m_CSLayers locked since this can be called only from within the tick thread
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -303,7 +303,7 @@ bool cChunkMap::LockedFastSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLO
// We already have m_CSLayers locked since this can be called only from within the tick thread // We already have m_CSLayers locked since this can be called only from within the tick thread
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -336,7 +336,7 @@ cChunk * cChunkMap::FindChunk(int a_ChunkX, int a_ChunkZ)
void cChunkMap::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle) void cChunkMap::BroadcastAttachEntity(const cEntity & a_Entity, const cEntity * a_Vehicle)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -356,7 +356,7 @@ void cChunkMap::BroadcastBlockAction(int a_BlockX, int a_BlockY, int a_BlockZ, c
x = a_BlockX; x = a_BlockX;
z = a_BlockZ; z = a_BlockZ;
cChunkDef::BlockToChunk(x, z, ChunkX, ChunkZ); cChunkDef::BlockToChunk(x, z, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -375,7 +375,7 @@ void cChunkMap::BroadcastBlockBreakAnimation(int a_entityID, int a_blockX, int a
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_blockX, a_blockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_blockX, a_blockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -393,7 +393,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -408,7 +408,7 @@ void cChunkMap::BroadcastBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, c
void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude) void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSerializer & a_Serializer, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, 0, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -424,7 +424,7 @@ void cChunkMap::BroadcastChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataSeriali
void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude) void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer & a_Player, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -440,7 +440,7 @@ void cChunkMap::BroadcastCollectEntity(const cEntity & a_Entity, const cPlayer &
void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -456,7 +456,7 @@ void cChunkMap::BroadcastDestroyEntity(const cEntity & a_Entity, const cClientHa
void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID, int a_Amplifier, short a_Duration, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -472,7 +472,7 @@ void cChunkMap::BroadcastEntityEffect(const cEntity & a_Entity, int a_EffectID,
void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotNum, const cItem & a_Item, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -488,7 +488,7 @@ void cChunkMap::BroadcastEntityEquipment(const cEntity & a_Entity, short a_SlotN
void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -504,7 +504,7 @@ void cChunkMap::BroadcastEntityHeadLook(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -520,7 +520,7 @@ void cChunkMap::BroadcastEntityLook(const cEntity & a_Entity, const cClientHandl
void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -536,7 +536,7 @@ void cChunkMap::BroadcastEntityMetadata(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -552,7 +552,7 @@ void cChunkMap::BroadcastEntityRelMove(const cEntity & a_Entity, char a_RelX, ch
void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX, char a_RelY, char a_RelZ, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -568,7 +568,7 @@ void cChunkMap::BroadcastEntityRelMoveLook(const cEntity & a_Entity, char a_RelX
void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -584,7 +584,7 @@ void cChunkMap::BroadcastEntityStatus(const cEntity & a_Entity, char a_Status, c
void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -600,7 +600,7 @@ void cChunkMap::BroadcastEntityVelocity(const cEntity & a_Entity, const cClientH
void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude) void cChunkMap::BroadcastEntityAnimation(const cEntity & a_Entity, char a_Animation, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -619,7 +619,7 @@ void cChunkMap::BroadcastParticleEffect(const AString & a_ParticleName, float a_
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk((int) a_SrcX, (int) a_SrcZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk((int) a_SrcX, (int) a_SrcZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -636,7 +636,7 @@ void cChunkMap::BroadcastRemoveEntityEffect(const cEntity & a_Entity, int a_Effe
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -655,7 +655,7 @@ void cChunkMap::BroadcastSoundEffect(const AString & a_SoundName, double a_X, do
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk((int)std::floor(a_X), (int)std::floor(a_Z), ChunkX, ChunkZ); cChunkDef::BlockToChunk((int)std::floor(a_X), (int)std::floor(a_Z), ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -674,7 +674,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_SrcX, a_SrcZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_SrcX, a_SrcZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -690,7 +690,7 @@ void cChunkMap::BroadcastSoundParticleEffect(int a_EffectID, int a_SrcX, int a_S
void cChunkMap::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude) void cChunkMap::BroadcastSpawnEntity(cEntity & a_Entity, const cClientHandle * a_Exclude)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), ZERO_CHUNK_Y, a_Entity.GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity.GetChunkX(), a_Entity.GetChunkZ());
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -708,7 +708,7 @@ void cChunkMap::BroadcastThunderbolt(int a_BlockX, int a_BlockY, int a_BlockZ, c
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -727,7 +727,7 @@ void cChunkMap::BroadcastUseBed(const cEntity & a_Entity, int a_BlockX, int a_Bl
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -745,7 +745,7 @@ void cChunkMap::SendBlockEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cClien
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -763,7 +763,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -778,7 +778,7 @@ void cChunkMap::UseBlockEntity(cPlayer * a_Player, int a_BlockX, int a_BlockY, i
bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback) bool cChunkMap::DoWithChunk(int a_ChunkX, int a_ChunkZ, cChunkCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -795,7 +795,7 @@ void cChunkMap::WakeUpSimulators(int a_BlockX, int a_BlockY, int a_BlockZ)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, 0, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -824,7 +824,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M
int MaxZ = std::min(a_MaxBlockZ, z * cChunkDef::Width + cChunkDef::Width - 1); int MaxZ = std::min(a_MaxBlockZ, z * cChunkDef::Width + cChunkDef::Width - 1);
for (int x = MinChunkX; x <= MaxChunkX; x++) for (int x = MinChunkX; x <= MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoGen(x, 0, z); cChunkPtr Chunk = GetChunkNoGen(x, z);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
continue; continue;
@ -852,7 +852,7 @@ void cChunkMap::WakeUpSimulatorsInArea(int a_MinBlockX, int a_MaxBlockX, int a_M
void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -867,7 +867,7 @@ void cChunkMap::MarkRedstoneDirty(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty) void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDirty)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -886,7 +886,7 @@ void cChunkMap::MarkChunkDirty(int a_ChunkX, int a_ChunkZ, bool a_MarkRedstoneDi
void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -901,7 +901,7 @@ void cChunkMap::MarkChunkSaving(int a_ChunkX, int a_ChunkZ)
void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkSaved (int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -919,7 +919,7 @@ void cChunkMap::SetChunkData(cSetChunkData & a_SetChunkData)
int ChunkZ = a_SetChunkData.GetChunkZ(); int ChunkZ = a_SetChunkData.GetChunkZ();
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -964,7 +964,7 @@ void cChunkMap::ChunkLighted(
) )
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -980,7 +980,7 @@ void cChunkMap::ChunkLighted(
bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback) bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -996,7 +996,7 @@ bool cChunkMap::GetChunkData(int a_ChunkX, int a_ChunkZ, cChunkDataCallback & a_
bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes) bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_BlockTypes)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -1012,7 +1012,7 @@ bool cChunkMap::GetChunkBlockTypes(int a_ChunkX, int a_ChunkZ, BLOCKTYPE * a_Blo
bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
return (Chunk != NULL) && Chunk->IsValid(); return (Chunk != NULL) && Chunk->IsValid();
} }
@ -1023,7 +1023,7 @@ bool cChunkMap::IsChunkValid(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ) bool cChunkMap::HasChunkAnyClients(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
return (Chunk != NULL) && Chunk->HasAnyClients(); return (Chunk != NULL) && Chunk->HasAnyClients();
} }
@ -1038,7 +1038,7 @@ int cChunkMap::GetHeight(int a_BlockX, int a_BlockZ)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ, BlockY = 0; int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return 0; return 0;
@ -1065,7 +1065,7 @@ bool cChunkMap::TryGetHeight(int a_BlockX, int a_BlockZ, int & a_Height)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ, BlockY = 0; int ChunkX, ChunkZ, BlockY = 0;
cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -1088,7 +1088,7 @@ void cChunkMap::FastSetBlocks(sSetBlockList & a_BlockList)
int ChunkX = a_BlockList.front().ChunkX; int ChunkX = a_BlockList.front().ChunkX;
int ChunkZ = a_BlockList.front().ChunkZ; int ChunkZ = a_BlockList.front().ChunkZ;
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
for (sSetBlockList::iterator itr = a_BlockList.begin(); itr != a_BlockList.end();) for (sSetBlockList::iterator itr = a_BlockList.begin(); itr != a_BlockList.end();)
@ -1135,7 +1135,7 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
int BlockX = (int)(a_Player->GetPosX()); // Truncating doesn't matter much; we're scanning entire chunks anyway int BlockX = (int)(a_Player->GetPosX()); // Truncating doesn't matter much; we're scanning entire chunks anyway
int BlockY = (int)(a_Player->GetPosY()); int BlockY = (int)(a_Player->GetPosY());
int BlockZ = (int)(a_Player->GetPosZ()); int BlockZ = (int)(a_Player->GetPosZ());
int ChunkX, ChunkZ, ChunkY = ZERO_CHUNK_Y; int ChunkX = 0, ChunkZ = 0;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
int OtherChunkX = ChunkX + ((BlockX > 8) ? 1 : -1); int OtherChunkX = ChunkX + ((BlockX > 8) ? 1 : -1);
int OtherChunkZ = ChunkZ + ((BlockZ > 8) ? 1 : -1); int OtherChunkZ = ChunkZ + ((BlockZ > 8) ? 1 : -1);
@ -1144,13 +1144,13 @@ void cChunkMap::CollectPickupsByPlayer(cPlayer * a_Player)
// The only time the chunks are not valid is when the player is downloading the initial world and they should not call this at that moment // The only time the chunks are not valid is when the player is downloading the initial world and they should not call this at that moment
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer(a_Player); GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer(a_Player);
// Check the neighboring chunks as well: // Check the neighboring chunks as well:
GetChunkNoLoad(OtherChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player); GetChunkNoLoad(OtherChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
GetChunkNoLoad(OtherChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player); GetChunkNoLoad(OtherChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
GetChunkNoLoad(ChunkX, ChunkY, ChunkZ)->CollectPickupsByPlayer (a_Player); GetChunkNoLoad(ChunkX, ChunkZ)->CollectPickupsByPlayer (a_Player);
GetChunkNoLoad(ChunkX, ChunkY, OtherChunkZ)->CollectPickupsByPlayer(a_Player); GetChunkNoLoad(ChunkX, OtherChunkZ)->CollectPickupsByPlayer(a_Player);
} }
@ -1177,7 +1177,7 @@ BLOCKTYPE cChunkMap::GetBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
return Chunk->GetBlock(a_BlockX, a_BlockY, a_BlockZ); return Chunk->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
@ -1206,7 +1206,7 @@ NIBBLETYPE cChunkMap::GetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
return Chunk->GetMeta(a_BlockX, a_BlockY, a_BlockZ); return Chunk->GetMeta(a_BlockX, a_BlockY, a_BlockZ);
@ -1224,7 +1224,7 @@ NIBBLETYPE cChunkMap::GetBlockSkyLight(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
return Chunk->GetSkyLight(a_BlockX, a_BlockY, a_BlockZ); return Chunk->GetSkyLight(a_BlockX, a_BlockY, a_BlockZ);
@ -1242,7 +1242,7 @@ NIBBLETYPE cChunkMap::GetBlockBlockLight(int a_BlockX, int a_BlockY, int a_Block
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
return Chunk->GetBlockLight(a_BlockX, a_BlockY, a_BlockZ); return Chunk->GetBlockLight(a_BlockX, a_BlockY, a_BlockZ);
@ -1261,7 +1261,7 @@ void cChunkMap::SetBlockMeta(int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYP
// a_BlockXYZ now contains relative coords! // a_BlockXYZ now contains relative coords!
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta); Chunk->SetMeta(a_BlockX, a_BlockY, a_BlockZ, a_BlockMeta);
@ -1284,7 +1284,7 @@ void cChunkMap::SetBlock(cWorldInterface & a_WorldInterface, int a_BlockX, int a
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_SendToClients); Chunk->SetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_SendToClients);
@ -1303,7 +1303,7 @@ void cChunkMap::QueueSetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYP
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType); Chunk->QueueSetBlock(X, Y, Z, a_BlockType, a_BlockMeta, a_Tick, a_PreviousBlockType);
@ -1320,7 +1320,7 @@ bool cChunkMap::GetBlockTypeMeta(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->GetBlockTypeMeta(X, Y, Z, a_BlockType, a_BlockMeta); Chunk->GetBlockTypeMeta(X, Y, Z, a_BlockType, a_BlockMeta);
@ -1339,7 +1339,7 @@ bool cChunkMap::GetBlockInfo(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE
cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative( X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk( ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->GetBlockInfo(X, Y, Z, a_BlockType, a_Meta, a_SkyLight, a_BlockLight); Chunk->GetBlockInfo(X, Y, Z, a_BlockType, a_Meta, a_SkyLight, a_BlockLight);
@ -1357,7 +1357,7 @@ void cChunkMap::ReplaceBlocks(const sSetBlockVector & a_Blocks, BLOCKTYPE a_Filt
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
continue; continue;
@ -1378,7 +1378,7 @@ void cChunkMap::ReplaceTreeBlocks(const sSetBlockVector & a_Blocks)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) for (sSetBlockVector::const_iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
continue; continue;
@ -1413,7 +1413,7 @@ EMCSBiome cChunkMap::GetBiomeAt (int a_BlockX, int a_BlockZ)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
return Chunk->GetBiomeAt(X, Z); return Chunk->GetBiomeAt(X, Z);
@ -1434,7 +1434,7 @@ bool cChunkMap::SetBiomeAt(int a_BlockX, int a_BlockZ, EMCSBiome a_Biome)
cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(X, Y, Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->SetBiomeAt(X, Z, a_Biome); Chunk->SetBiomeAt(X, Z, a_Biome);
@ -1467,7 +1467,7 @@ bool cChunkMap::SetAreaBiome(int a_MinX, int a_MaxX, int a_MinZ, int a_MaxZ, EMC
{ {
int MinRelZ = (z == MinChunkZ) ? MinZ : 0; int MinRelZ = (z == MinChunkZ) ? MinZ : 0;
int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1; int MaxRelZ = (z == MaxChunkZ) ? MaxZ : cChunkDef::Width - 1;
cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk != NULL) && Chunk->IsValid()) if ((Chunk != NULL) && Chunk->IsValid())
{ {
Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome); Chunk->SetAreaBiome(MinRelX, MaxRelX, MinRelZ, MaxRelZ, a_Biome);
@ -1491,7 +1491,7 @@ bool cChunkMap::GetBlocks(sSetBlockVector & a_Blocks, bool a_ContinueOnFailure)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr) for (sSetBlockVector::iterator itr = a_Blocks.begin(); itr != a_Blocks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->ChunkX, ZERO_CHUNK_Y, itr->ChunkZ); cChunkPtr Chunk = GetChunk(itr->ChunkX, itr->ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
if (!a_ContinueOnFailure) if (!a_ContinueOnFailure)
@ -1519,7 +1519,7 @@ bool cChunkMap::DigBlock(int a_X, int a_Y, int a_Z)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr DestChunk = GetChunk( ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr DestChunk = GetChunk( ChunkX, ChunkZ);
if ((DestChunk == NULL) || !DestChunk->IsValid()) if ((DestChunk == NULL) || !DestChunk->IsValid())
{ {
return false; return false;
@ -1542,7 +1542,7 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player)
cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_X, a_Y, a_Z, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunk(ChunkX, ChunkZ);
if ((Chunk != NULL) && (Chunk->IsValid())) if ((Chunk != NULL) && (Chunk->IsValid()))
{ {
Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player->GetClientHandle()); Chunk->SendBlockTo(a_X, a_Y, a_Z, a_Player->GetClientHandle());
@ -1556,12 +1556,12 @@ void cChunkMap::SendBlockTo(int a_X, int a_Y, int a_Z, cPlayer * a_Player)
void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback) void cChunkMap::CompareChunkClients(int a_ChunkX1, int a_ChunkZ1, int a_ChunkX2, int a_ChunkZ2, cClientDiffCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, ZERO_CHUNK_Y, a_ChunkZ1); cChunkPtr Chunk1 = GetChunkNoGen(a_ChunkX1, a_ChunkZ1);
if (Chunk1 == NULL) if (Chunk1 == NULL)
{ {
return; return;
} }
cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, ZERO_CHUNK_Y, a_ChunkZ2); cChunkPtr Chunk2 = GetChunkNoGen(a_ChunkX2, a_ChunkZ2);
if (Chunk2 == NULL) if (Chunk2 == NULL)
{ {
return; return;
@ -1623,7 +1623,7 @@ void cChunkMap::CompareChunkClients(cChunk * a_Chunk1, cChunk * a_Chunk2, cClien
bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunk(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return false; return false;
@ -1638,7 +1638,7 @@ bool cChunkMap::AddChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Cli
void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) void cChunkMap::RemoveChunkClient(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -1667,7 +1667,7 @@ void cChunkMap::RemoveClientFromChunks(cClientHandle * a_Client)
void cChunkMap::AddEntity(cEntity * a_Entity) void cChunkMap::AddEntity(cEntity * a_Entity)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if ( if (
(Chunk == NULL) || // Chunk not present at all (Chunk == NULL) || // Chunk not present at all
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953) (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
@ -1688,7 +1688,7 @@ void cChunkMap::AddEntity(cEntity * a_Entity)
void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity) void cChunkMap::AddEntityIfNotPresent(cEntity * a_Entity)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
if ( if (
(Chunk == NULL) || // Chunk not present at all (Chunk == NULL) || // Chunk not present at all
(!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953) (!Chunk->IsValid() && !a_Entity->IsPlayer()) // Chunk present, but no valid data; players need to spawn in such chunks (#953)
@ -1729,7 +1729,7 @@ bool cChunkMap::HasEntity(int a_UniqueID)
void cChunkMap::RemoveEntity(cEntity * a_Entity) void cChunkMap::RemoveEntity(cEntity * a_Entity)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), ZERO_CHUNK_Y, a_Entity->GetChunkZ()); cChunkPtr Chunk = GetChunkNoGen(a_Entity->GetChunkX(), a_Entity->GetChunkZ());
// Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190) // Even if a chunk is not valid, it may still contain entities such as players; make sure to remove them (#1190)
if (Chunk == NULL) if (Chunk == NULL)
@ -1763,7 +1763,7 @@ bool cChunkMap::ForEachEntity(cEntityCallback & a_Callback)
bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback) bool cChunkMap::ForEachEntityInChunk(int a_ChunkX, int a_ChunkZ, cEntityCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2021,7 +2021,7 @@ bool cChunkMap::DoWithEntityByID(int a_UniqueID, cEntityCallback & a_Callback)
bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback) bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEntityCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2036,7 +2036,7 @@ bool cChunkMap::ForEachBlockEntityInChunk(int a_ChunkX, int a_ChunkZ, cBlockEnti
bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback) bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2051,7 +2051,7 @@ bool cChunkMap::ForEachChestInChunk(int a_ChunkX, int a_ChunkZ, cChestCallback &
bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback) bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2066,7 +2066,7 @@ bool cChunkMap::ForEachDispenserInChunk(int a_ChunkX, int a_ChunkZ, cDispenserCa
bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback) bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2081,7 +2081,7 @@ bool cChunkMap::ForEachDropperInChunk(int a_ChunkX, int a_ChunkZ, cDropperCallba
bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback) bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpenserCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2096,7 +2096,7 @@ bool cChunkMap::ForEachDropSpenserInChunk(int a_ChunkX, int a_ChunkZ, cDropSpens
bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback) bool cChunkMap::ForEachFurnaceInChunk(int a_ChunkX, int a_ChunkZ, cFurnaceCallback & a_Callback)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2114,7 +2114,7 @@ bool cChunkMap::DoWithBlockEntityAt(int a_BlockX, int a_BlockY, int a_BlockZ, cB
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2132,7 +2132,7 @@ bool cChunkMap::DoWithBeaconAt(int a_BlockX, int a_BlockY, int a_BlockZ, cBeacon
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2150,7 +2150,7 @@ bool cChunkMap::DoWithChestAt(int a_BlockX, int a_BlockY, int a_BlockZ, cChestCa
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2168,7 +2168,7 @@ bool cChunkMap::DoWithDispenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDis
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2186,7 +2186,7 @@ bool cChunkMap::DoWithDropperAt(int a_BlockX, int a_BlockY, int a_BlockZ, cDropp
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2204,7 +2204,7 @@ bool cChunkMap::DoWithDropSpenserAt(int a_BlockX, int a_BlockY, int a_BlockZ, cD
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2222,7 +2222,7 @@ bool cChunkMap::DoWithFurnaceAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFurna
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2239,7 +2239,7 @@ bool cChunkMap::DoWithNoteBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, cNot
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2256,7 +2256,7 @@ bool cChunkMap::DoWithCommandBlockAt(int a_BlockX, int a_BlockY, int a_BlockZ, c
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2274,7 +2274,7 @@ bool cChunkMap::DoWithMobHeadAt(int a_BlockX, int a_BlockY, int a_BlockZ, cMobHe
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2292,7 +2292,7 @@ bool cChunkMap::DoWithFlowerPotAt(int a_BlockX, int a_BlockY, int a_BlockZ, cFlo
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2310,7 +2310,7 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &
int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ; int BlockX = a_BlockX, BlockY = a_BlockY, BlockZ = a_BlockZ;
cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(BlockX, BlockY, BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2322,10 +2322,10 @@ bool cChunkMap::GetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, AString &
void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
GetChunk(a_ChunkX, a_ChunkY, a_ChunkZ); GetChunk(a_ChunkX, a_ChunkZ);
} }
@ -2333,11 +2333,11 @@ void cChunkMap::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
/// Loads the chunk synchronously, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) /// Loads the chunk synchronously, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before)
bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkZ)
{ {
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkY, a_ChunkZ); cChunkPtr Chunk = GetChunkNoGen(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
// Internal error // Internal error
@ -2354,7 +2354,7 @@ bool cChunkMap::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return false; return false;
} }
} }
return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ); return m_World->GetStorage().LoadChunk(a_ChunkX, a_ChunkZ);
} }
@ -2366,7 +2366,7 @@ void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks)
{ {
for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr) for (cChunkCoordsList::const_iterator itr = a_Chunks.begin(); itr != a_Chunks.end(); ++itr)
{ {
LoadChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); LoadChunk(itr->m_ChunkX, itr->m_ChunkZ);
} // for itr - a_Chunks[] } // for itr - a_Chunks[]
} }
@ -2374,10 +2374,10 @@ void cChunkMap::LoadChunks(const cChunkCoordsList & a_Chunks)
void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cChunkMap::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkY, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
return; return;
@ -2394,7 +2394,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ); cChunkDef::BlockToChunk(a_BlockX, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoGen(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoGen(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return false; return false;
@ -2409,7 +2409,7 @@ bool cChunkMap::SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const ASt
void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ) void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
// Not present // Not present
@ -2425,7 +2425,7 @@ void cChunkMap::MarkChunkRegenerating(int a_ChunkX, int a_ChunkZ)
bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ) bool cChunkMap::IsChunkLighted(int a_ChunkX, int a_ChunkZ)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
// Not present // Not present
@ -2446,7 +2446,7 @@ bool cChunkMap::ForEachChunkInRect(int a_MinChunkX, int a_MaxChunkX, int a_MinCh
{ {
for (int x = a_MinChunkX; x <= a_MaxChunkX; x++) for (int x = a_MinChunkX; x <= a_MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk == NULL) || (!Chunk->IsValid())) if ((Chunk == NULL) || (!Chunk->IsValid()))
{ {
// Not present / not valid // Not present / not valid
@ -2488,7 +2488,7 @@ bool cChunkMap::WriteBlockArea(cBlockArea & a_Area, int a_MinBlockX, int a_MinBl
{ {
for (int x = MinChunkX; x <= MaxChunkX; x++) for (int x = MinChunkX; x <= MaxChunkX; x++)
{ {
cChunkPtr Chunk = GetChunkNoLoad(x, ZERO_CHUNK_Y, z); cChunkPtr Chunk = GetChunkNoLoad(x, z);
if ((Chunk == NULL) || (!Chunk->IsValid())) if ((Chunk == NULL) || (!Chunk->IsValid()))
{ {
// Not present / not valid // Not present / not valid
@ -2529,7 +2529,7 @@ void cChunkMap::GrowMelonPumpkin(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCK
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_Rand); Chunk->GrowMelonPumpkin(a_BlockX, a_BlockY, a_BlockZ, a_BlockType, a_Rand);
@ -2546,7 +2546,7 @@ void cChunkMap::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Nu
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow); Chunk->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
@ -2563,7 +2563,7 @@ void cChunkMap::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBl
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow); Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
@ -2580,7 +2580,7 @@ void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ); Chunk->SetNextBlockTick(a_BlockX, a_BlockY, a_BlockZ);
@ -2635,7 +2635,7 @@ void cChunkMap::TickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
int ChunkX, ChunkZ; int ChunkX, ChunkZ;
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ); cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if ((Chunk == NULL) || !Chunk->IsValid()) if ((Chunk == NULL) || !Chunk->IsValid())
{ {
return; return;
@ -2704,7 +2704,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
// a_BlockXYZ now contains relative coords! // a_BlockXYZ now contains relative coords!
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->QueueTickBlock(a_BlockX, a_BlockY, a_BlockZ); Chunk->QueueTickBlock(a_BlockX, a_BlockY, a_BlockZ);
@ -2718,7 +2718,7 @@ void cChunkMap::QueueTickBlock(int a_BlockX, int a_BlockY, int a_BlockZ)
void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked) void cChunkMap::SetChunkAlwaysTicked(int a_ChunkX, int a_ChunkZ, bool a_AlwaysTicked)
{ {
cCSLock Lock(m_CSLayers); cCSLock Lock(m_CSLayers);
cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(a_ChunkX, a_ChunkZ);
if (Chunk != NULL) if (Chunk != NULL)
{ {
Chunk->SetAlwaysTicked(a_AlwaysTicked); Chunk->SetAlwaysTicked(a_AlwaysTicked);
@ -2763,7 +2763,7 @@ cChunkMap::cChunkLayer::~cChunkLayer()
cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ) cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkZ)
{ {
// Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check // Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check
@ -2783,7 +2783,7 @@ cChunkPtr cChunkMap::cChunkLayer::GetChunk( int a_ChunkX, int a_ChunkY, int a_Ch
cChunk * neixp = (LocalX < LAYER_SIZE - 1) ? m_Chunks[Index + 1] : m_Parent->FindChunk(a_ChunkX + 1, a_ChunkZ); cChunk * neixp = (LocalX < LAYER_SIZE - 1) ? m_Chunks[Index + 1] : m_Parent->FindChunk(a_ChunkX + 1, a_ChunkZ);
cChunk * neizm = (LocalZ > 0) ? m_Chunks[Index - LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ - 1); cChunk * neizm = (LocalZ > 0) ? m_Chunks[Index - LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ - 1);
cChunk * neizp = (LocalZ < LAYER_SIZE - 1) ? m_Chunks[Index + LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ + 1); cChunk * neizp = (LocalZ < LAYER_SIZE - 1) ? m_Chunks[Index + LAYER_SIZE] : m_Parent->FindChunk(a_ChunkX, a_ChunkZ + 1);
m_Chunks[Index] = new cChunk(a_ChunkX, 0, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool); m_Chunks[Index] = new cChunk(a_ChunkX, a_ChunkZ, m_Parent, m_Parent->GetWorld(), neixm, neixp, neizm, neizp, m_Pool);
} }
return m_Chunks[Index]; return m_Chunks[Index];
} }
@ -2983,7 +2983,7 @@ void cChunkMap::cChunkLayer::Save(void)
{ {
if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->IsDirty()) if ((m_Chunks[i] != NULL) && m_Chunks[i]->IsValid() && m_Chunks[i]->IsDirty())
{ {
World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosY(), m_Chunks[i]->GetPosZ()); World->GetStorage().QueueSaveChunk(m_Chunks[i]->GetPosX(), m_Chunks[i]->GetPosZ());
} }
} // for i - m_Chunks[] } // for i - m_Chunks[]
} }
@ -3056,7 +3056,7 @@ void cChunkMap::AddChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks(); const cChunkCoordsVector & WantedChunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr) for (cChunkCoordsVector::const_iterator itr = WantedChunks.begin(); itr != WantedChunks.end(); ++itr)
{ {
cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); cChunkPtr Chunk = GetChunk(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
continue; continue;
@ -3105,7 +3105,7 @@ void cChunkMap::DelChunkStay(cChunkStay & a_ChunkStay)
const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks(); const cChunkCoordsVector & Chunks = a_ChunkStay.GetChunks();
for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr) for (cChunkCoordsVector::const_iterator itr = Chunks.begin(), end = Chunks.end(); itr != end; ++itr)
{ {
cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkY, itr->m_ChunkZ); cChunkPtr Chunk = GetChunkNoLoad(itr->m_ChunkX, itr->m_ChunkZ);
if (Chunk == NULL) if (Chunk == NULL)
{ {
continue; continue;

View File

@ -276,16 +276,16 @@ public:
bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible bool GetSignLines (int a_BlockX, int a_BlockY, int a_BlockZ, AString & a_Line1, AString & a_Line2, AString & a_Line3, AString & a_Line4); // Lua-accessible
/** Touches the chunk, causing it to be loaded or generated */ /** Touches the chunk, causing it to be loaded or generated */
void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void TouchChunk(int a_ChunkX, int a_ChunkZ);
/** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */ /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */
bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); bool LoadChunk(int a_ChunkX, int a_ChunkZ);
/** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */ /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */
void LoadChunks(const cChunkCoordsList & a_Chunks); void LoadChunks(const cChunkCoordsList & a_Chunks);
/** Marks the chunk as failed-to-load */ /** Marks the chunk as failed-to-load */
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
/** Sets the sign text. Returns true if sign text changed. */ /** Sets the sign text. Returns true if sign text changed. */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4); bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4);
@ -369,7 +369,7 @@ private:
~cChunkLayer(); ~cChunkLayer();
/** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */ /** Always returns an assigned chunkptr, but the chunk needn't be valid (loaded / generated) - callers must check */
cChunkPtr GetChunk( int a_ChunkX, int a_ChunkY, int a_ChunkZ); cChunkPtr GetChunk( int a_ChunkX, int a_ChunkZ);
/** Returns the specified chunk, or NULL if not created yet */ /** Returns the specified chunk, or NULL if not created yet */
cChunk * FindChunk(int a_ChunkX, int a_ChunkZ); cChunk * FindChunk(int a_ChunkX, int a_ChunkZ);
@ -462,9 +462,9 @@ private:
std::auto_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool; std::auto_ptr<cAllocationPool<cChunkData::sChunkSection> > m_Pool;
cChunkPtr GetChunk (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid cChunkPtr GetChunk (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading / generating if not valid
cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate cChunkPtr GetChunkNoGen (int a_ChunkX, int a_ChunkZ); // Also queues the chunk for loading if not valid; doesn't generate
cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); // Doesn't load, doesn't generate cChunkPtr GetChunkNoLoad(int a_ChunkX, int a_ChunkZ); // Doesn't load, doesn't generate
/** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */ /** Gets a block in any chunk while in the cChunk's Tick() method; returns true if successful, false if chunk not loaded (doesn't queue load) */
bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta); bool LockedGetBlock(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta);

View File

@ -81,7 +81,7 @@ void cChunkSender::ChunkReady(int a_ChunkX, int a_ChunkZ)
// This is probably never gonna be called twice for the same chunk, and if it is, we don't mind, so we don't check // This is probably never gonna be called twice for the same chunk, and if it is, we don't mind, so we don't check
{ {
cCSLock Lock(m_CS); cCSLock Lock(m_CS);
m_ChunksReady.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); m_ChunksReady.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
} }
m_evtQueue.Set(); m_evtQueue.Set();
} }
@ -95,12 +95,12 @@ void cChunkSender::QueueSendChunkTo(int a_ChunkX, int a_ChunkZ, cClientHandle *
ASSERT(a_Client != NULL); ASSERT(a_Client != NULL);
{ {
cCSLock Lock(m_CS); cCSLock Lock(m_CS);
if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client)) != m_SendChunks.end()) if (std::find(m_SendChunks.begin(), m_SendChunks.end(), sSendChunk(a_ChunkX, a_ChunkZ, a_Client)) != m_SendChunks.end())
{ {
// Already queued, bail out // Already queued, bail out
return; return;
} }
m_SendChunks.push_back(sSendChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ, a_Client)); m_SendChunks.push_back(sSendChunk(a_ChunkX, a_ChunkZ, a_Client));
} }
m_evtQueue.Set(); m_evtQueue.Set();
} }
@ -160,7 +160,7 @@ void cChunkSender::Execute(void)
m_ChunksReady.pop_front(); m_ChunksReady.pop_front();
Lock.Unlock(); Lock.Unlock();
SendChunk(Coords.m_ChunkX, Coords.m_ChunkY, Coords.m_ChunkZ, NULL); SendChunk(Coords.m_ChunkX, Coords.m_ChunkZ, NULL);
} }
else else
{ {
@ -169,7 +169,7 @@ void cChunkSender::Execute(void)
m_SendChunks.pop_front(); m_SendChunks.pop_front();
Lock.Unlock(); Lock.Unlock();
SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkY, Chunk.m_ChunkZ, Chunk.m_Client); SendChunk(Chunk.m_ChunkX, Chunk.m_ChunkZ, Chunk.m_Client);
} }
Lock.Lock(); Lock.Lock();
int RemoveCount = m_RemoveCount; int RemoveCount = m_RemoveCount;
@ -186,14 +186,14 @@ void cChunkSender::Execute(void)
void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) void cChunkSender::SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client)
{ {
ASSERT(m_World != NULL); ASSERT(m_World != NULL);
// Ask the client if it still wants the chunk: // Ask the client if it still wants the chunk:
if (a_Client != NULL) if (a_Client != NULL)
{ {
if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkY, a_ChunkZ)) if (!a_Client->WantsSendChunk(a_ChunkX, a_ChunkZ))
{ {
return; return;
} }

View File

@ -95,13 +95,11 @@ protected:
struct sSendChunk struct sSendChunk
{ {
int m_ChunkX; int m_ChunkX;
int m_ChunkY;
int m_ChunkZ; int m_ChunkZ;
cClientHandle * m_Client; cClientHandle * m_Client;
sSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client) : sSendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client) :
m_ChunkX(a_ChunkX), m_ChunkX(a_ChunkX),
m_ChunkY(a_ChunkY),
m_ChunkZ(a_ChunkZ), m_ChunkZ(a_ChunkZ),
m_Client(a_Client) m_Client(a_Client)
{ {
@ -111,7 +109,6 @@ protected:
{ {
return ( return (
(a_Other.m_ChunkX == m_ChunkX) && (a_Other.m_ChunkX == m_ChunkX) &&
(a_Other.m_ChunkY == m_ChunkY) &&
(a_Other.m_ChunkZ == m_ChunkZ) && (a_Other.m_ChunkZ == m_ChunkZ) &&
(a_Other.m_Client == m_Client) (a_Other.m_Client == m_Client)
); );
@ -162,7 +159,7 @@ protected:
virtual void BlockEntity (cBlockEntity * a_Entity) override; virtual void BlockEntity (cBlockEntity * a_Entity) override;
/// Sends the specified chunk to a_Client, or to all chunk clients if a_Client == NULL /// Sends the specified chunk to a_Client, or to all chunk clients if a_Client == NULL
void SendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, cClientHandle * a_Client); void SendChunk(int a_ChunkX, int a_ChunkZ, cClientHandle * a_Client);
} ; } ;

View File

@ -51,7 +51,7 @@ void cChunkStay::Add(int a_ChunkX, int a_ChunkZ)
return; return;
} }
} // for itr - Chunks[] } // for itr - Chunks[]
m_Chunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); m_Chunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
} }

View File

@ -472,13 +472,13 @@ void cClientHandle::StreamChunks(void)
// For each distance touch chunks in a hollow square centered around current position: // For each distance touch chunks in a hollow square centered around current position:
for (int i = -d; i <= d; ++i) for (int i = -d; i <= d; ++i)
{ {
World->TouchChunk(ChunkPosX + d, ZERO_CHUNK_Y, ChunkPosZ + i); World->TouchChunk(ChunkPosX + d, ChunkPosZ + i);
World->TouchChunk(ChunkPosX - d, ZERO_CHUNK_Y, ChunkPosZ + i); World->TouchChunk(ChunkPosX - d, ChunkPosZ + i);
} // for i } // for i
for (int i = -d + 1; i < d; ++i) for (int i = -d + 1; i < d; ++i)
{ {
World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ + d); World->TouchChunk(ChunkPosX + i, ChunkPosZ + d);
World->TouchChunk(ChunkPosX + i, ZERO_CHUNK_Y, ChunkPosZ - d); World->TouchChunk(ChunkPosX + i, ChunkPosZ - d);
} // for i } // for i
} // for d } // for d
} }
@ -501,8 +501,8 @@ void cClientHandle::StreamChunk(int a_ChunkX, int a_ChunkZ)
{ {
{ {
cCSLock Lock(m_CSChunkLists); cCSLock Lock(m_CSChunkLists);
m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); m_LoadedChunks.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
} }
World->SendChunkTo(a_ChunkX, a_ChunkZ, this); World->SendChunkTo(a_ChunkX, a_ChunkZ, this);
} }
@ -2734,7 +2734,7 @@ bool cClientHandle::HasPluginChannel(const AString & a_PluginChannel)
bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkZ)
{ {
if (m_State >= csDestroying) if (m_State >= csDestroying)
{ {
@ -2742,7 +2742,7 @@ bool cClientHandle::WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
} }
cCSLock Lock(m_CSChunkLists); cCSLock Lock(m_CSChunkLists);
return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)) != m_ChunksToSend.end()); return (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) != m_ChunksToSend.end());
} }
@ -2758,9 +2758,9 @@ void cClientHandle::AddWantedChunk(int a_ChunkX, int a_ChunkZ)
LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this); LOGD("Adding chunk [%d, %d] to wanted chunks for client %p", a_ChunkX, a_ChunkZ, this);
cCSLock Lock(m_CSChunkLists); cCSLock Lock(m_CSChunkLists);
if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)) == m_ChunksToSend.end()) if (std::find(m_ChunksToSend.begin(), m_ChunksToSend.end(), cChunkCoords(a_ChunkX, a_ChunkZ)) == m_ChunksToSend.end())
{ {
m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ)); m_ChunksToSend.push_back(cChunkCoords(a_ChunkX, a_ChunkZ));
} }
} }

View File

@ -209,7 +209,7 @@ public:
// tolua_end // tolua_end
/** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */ /** Returns true if the client wants the chunk specified to be sent (in m_ChunksToSend) */
bool WantsSendChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); bool WantsSendChunk(int a_ChunkX, int a_ChunkZ);
/** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */ /** Adds the chunk specified to the list of chunks wanted for sending (m_ChunksToSend) */
void AddWantedChunk(int a_ChunkX, int a_ChunkZ); void AddWantedChunk(int a_ChunkX, int a_ChunkZ);

View File

@ -387,7 +387,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
case cMonster::mtGhast: case cMonster::mtGhast:
case cMonster::mtZombiePigman: case cMonster::mtZombiePigman:
case cMonster::mtMagmaCube: case cMonster::mtMagmaCube:
{ {
break; break;
}; };
default: StartBurning(BurnTicks * 20); default: StartBurning(BurnTicks * 20);
@ -417,7 +417,7 @@ bool cEntity::DoTakeDamage(TakeDamageInfo & a_TDI)
} }
if (!Player->IsOnGround()) if (!Player->IsOnGround())
{ {
if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack)) if ((a_TDI.DamageType == dtAttack) || (a_TDI.DamageType == dtArrowAttack))
{ {
a_TDI.FinalDamage += 2; a_TDI.FinalDamage += 2;

View File

@ -34,14 +34,14 @@ cEntityEffect::eType cEntityEffect::GetPotionEffectType(short a_ItemDamage)
case 0x08: return cEntityEffect::effWeakness; case 0x08: return cEntityEffect::effWeakness;
case 0x09: return cEntityEffect::effStrength; case 0x09: return cEntityEffect::effStrength;
case 0x0a: return cEntityEffect::effSlowness; case 0x0a: return cEntityEffect::effSlowness;
case 0x0b: return cEntityEffect::effJumpBoost;
case 0x0c: return cEntityEffect::effInstantDamage; case 0x0c: return cEntityEffect::effInstantDamage;
case 0x0d: return cEntityEffect::effWaterBreathing; case 0x0d: return cEntityEffect::effWaterBreathing;
case 0x0e: return cEntityEffect::effInvisibility; case 0x0e: return cEntityEffect::effInvisibility;
// No effect potions // No effect potions
case 0x00: case 0x00:
case 0x07: case 0x07:
case 0x0b: // Will be potion of leaping in 1.8
case 0x0f: case 0x0f:
{ {
break; break;

View File

@ -52,10 +52,21 @@ bool cChunkGenerator::Start(cPluginInterface & a_PluginInterface, cChunkSink & a
m_PluginInterface = &a_PluginInterface; m_PluginInterface = &a_PluginInterface;
m_ChunkSink = &a_ChunkSink; m_ChunkSink = &a_ChunkSink;
MTRand rnd; // Get the seed; create a new one and log it if not found in the INI file:
m_Seed = a_IniFile.GetValueSetI("Seed", "Seed", (int)rnd.randInt()); if (a_IniFile.HasValue("Seed", "Seed"))
{
m_Seed = a_IniFile.GetValueI("Seed", "Seed");
}
else
{
MTRand rnd;
m_Seed = rnd.randInt();
LOGINFO("Chosen a new random seed for world: %d", m_Seed);
a_IniFile.SetValueI("Seed", "Seed", m_Seed);
}
// Get the generator engine based on the INI file settings:
AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable"); AString GeneratorName = a_IniFile.GetValueSet("Generator", "Generator", "Composable");
if (NoCaseCompare(GeneratorName, "Noise3D") == 0) if (NoCaseCompare(GeneratorName, "Noise3D") == 0)
{ {
m_Generator = new cNoise3DGenerator(*this); m_Generator = new cNoise3DGenerator(*this);
@ -99,15 +110,15 @@ void cChunkGenerator::Stop(void)
void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate)
{ {
{ {
cCSLock Lock(m_CS); cCSLock Lock(m_CS);
// Check if it is already in the queue: // Check if it is already in the queue:
for (cChunkCoordsList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr) for (cChunkCoordsWithBoolList::iterator itr = m_Queue.begin(); itr != m_Queue.end(); ++itr)
{ {
if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkY == a_ChunkY) && (itr->m_ChunkZ == a_ChunkZ)) if ((itr->m_ChunkX == a_ChunkX) && (itr->m_ChunkZ == a_ChunkZ))
{ {
// Already in the queue, bail out // Already in the queue, bail out
return; return;
@ -119,7 +130,7 @@ void cChunkGenerator::QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_Chunk
{ {
LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size()); LOGWARN("WARNING: Adding chunk [%i, %i] to generation queue; Queue is too big! (" SIZE_T_FMT ")", a_ChunkX, a_ChunkZ, m_Queue.size());
} }
m_Queue.push_back(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); m_Queue.push_back(cChunkCoordsWithBool(a_ChunkX, a_ChunkZ, a_ForceGenerate));
} }
m_Event.Set(); m_Event.Set();
@ -229,9 +240,9 @@ void cChunkGenerator::Execute(void)
continue; continue;
} }
cChunkCoords coords = m_Queue.front(); // Get next coord from queue cChunkCoordsWithBool coords = m_Queue.front(); // Get next coord from queue
m_Queue.erase( m_Queue.begin()); // Remove coordinate from queue
bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT); bool SkipEnabled = (m_Queue.size() > QUEUE_SKIP_LIMIT);
m_Queue.erase(m_Queue.begin()); // Remove coordinate from queue
Lock.Unlock(); // Unlock ASAP Lock.Unlock(); // Unlock ASAP
m_evtRemoved.Set(); m_evtRemoved.Set();
@ -245,8 +256,7 @@ void cChunkGenerator::Execute(void)
LastReportTick = clock(); LastReportTick = clock();
} }
// Hack for regenerating chunks: if Y != 0, the chunk is considered invalid, even if it has its data set if (!coords.m_ForceGenerate && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ))
if ((coords.m_ChunkY == 0) && m_ChunkSink->IsChunkValid(coords.m_ChunkX, coords.m_ChunkZ))
{ {
LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ); LOGD("Chunk [%d, %d] already generated, skipping generation", coords.m_ChunkX, coords.m_ChunkZ);
// Already generated, ignore request // Already generated, ignore request
@ -259,8 +269,8 @@ void cChunkGenerator::Execute(void)
continue; continue;
} }
LOGD("Generating chunk [%d, %d, %d]", coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); LOGD("Generating chunk [%d, %d]", coords.m_ChunkX, coords.m_ChunkZ);
DoGenerate(coords.m_ChunkX, coords.m_ChunkY, coords.m_ChunkZ); DoGenerate(coords.m_ChunkX, coords.m_ChunkZ);
NumChunksGenerated++; NumChunksGenerated++;
} // while (!bStop) } // while (!bStop)
@ -269,7 +279,7 @@ void cChunkGenerator::Execute(void)
void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cChunkGenerator::DoGenerate(int a_ChunkX, int a_ChunkZ)
{ {
ASSERT(m_PluginInterface != NULL); ASSERT(m_PluginInterface != NULL);
ASSERT(m_ChunkSink != NULL); ASSERT(m_ChunkSink != NULL);

View File

@ -116,7 +116,7 @@ public:
void Stop(void); void Stop(void);
/// Queues the chunk for generation; removes duplicate requests /// Queues the chunk for generation; removes duplicate requests
void QueueGenerateChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void QueueGenerateChunk(int a_ChunkX, int a_ChunkZ, bool a_ForceGenerate);
/// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading. /// Generates the biomes for the specified chunk (directly, not in a separate thread). Used by the world loader if biomes failed loading.
void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap); void GenerateBiomes(int a_ChunkX, int a_ChunkZ, cChunkDef::BiomeMap & a_BiomeMap);
@ -137,10 +137,10 @@ private:
int m_Seed; int m_Seed;
cCriticalSection m_CS; cCriticalSection m_CS;
cChunkCoordsList m_Queue; cChunkCoordsWithBoolList m_Queue;
cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate cEvent m_Event; ///< Set when an item is added to the queue or the thread should terminate
cEvent m_evtRemoved; ///< Set when an item is removed from the queue cEvent m_evtRemoved; ///< Set when an item is removed from the queue
cGenerator * m_Generator; ///< The actual generator engine used to generate chunks cGenerator * m_Generator; ///< The actual generator engine used to generate chunks
@ -154,7 +154,7 @@ private:
// cIsThread override: // cIsThread override:
virtual void Execute(void) override; virtual void Execute(void) override;
void DoGenerate(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void DoGenerate(int a_ChunkX, int a_ChunkZ);
}; };

View File

@ -29,7 +29,7 @@ public:
switch (m_ItemType) switch (m_ItemType)
{ {
// Please keep alpha-sorted. // Please keep alpha-sorted.
case E_ITEM_BAKED_POTATO: return FoodInfo(6, 7.2); case E_ITEM_BAKED_POTATO: return FoodInfo(5, 7.2);
case E_ITEM_BREAD: return FoodInfo(5, 6); case E_ITEM_BREAD: return FoodInfo(5, 6);
// Carrots handled in ItemSeeds // Carrots handled in ItemSeeds
case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2); case E_ITEM_COOKED_CHICKEN: return FoodInfo(6, 7.2);
@ -43,14 +43,16 @@ public:
case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2); case E_ITEM_POISONOUS_POTATO: return FoodInfo(2, 1.2);
// Potatoes handled in ItemSeeds // Potatoes handled in ItemSeeds
case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8); case E_ITEM_PUMPKIN_PIE: return FoodInfo(8, 4.8);
case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8); case E_ITEM_RAW_BEEF: return FoodInfo(3, 1.8);
case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2); case E_ITEM_RAW_CHICKEN: return FoodInfo(2, 1.2);
case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2); case E_ITEM_RAW_FISH: return FoodInfo(2, 1.2);
case E_ITEM_RAW_MUTTON: return FoodInfo(2, 1.2);
case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8); case E_ITEM_RAW_PORKCHOP: return FoodInfo(3, 1.8);
case E_ITEM_RED_APPLE: return FoodInfo(4, 2.4);
case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8); case E_ITEM_ROTTEN_FLESH: return FoodInfo(4, 0.8);
case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2); case E_ITEM_SPIDER_EYE: return FoodInfo(2, 3.2);
case E_ITEM_STEAK: return FoodInfo(8, 12.8); case E_ITEM_STEAK: return FoodInfo(8, 12.8);
case E_ITEM_MUTTON: return FoodInfo(6, 9.6);
} }
LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType); LOGWARNING("%s: Unknown food item (%d), returning zero nutrition", __FUNCTION__, m_ItemType);
return FoodInfo(0, 0.f); return FoodInfo(0, 0.f);

View File

@ -207,7 +207,7 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
} }
// Food (please keep alpha-sorted): // Food (please keep alpha-sorted):
// (carrots and potatoes handled in SeedHandler as both seed and food // (carrots and potatoes handled separately in SeedHandler as they're both seed and food)
case E_ITEM_BAKED_POTATO: case E_ITEM_BAKED_POTATO:
case E_ITEM_BREAD: case E_ITEM_BREAD:
case E_ITEM_COOKED_CHICKEN: case E_ITEM_COOKED_CHICKEN:
@ -217,13 +217,15 @@ cItemHandler *cItemHandler::CreateItemHandler(int a_ItemType)
case E_ITEM_GOLDEN_CARROT: case E_ITEM_GOLDEN_CARROT:
case E_ITEM_MELON_SLICE: case E_ITEM_MELON_SLICE:
case E_ITEM_MUSHROOM_SOUP: case E_ITEM_MUSHROOM_SOUP:
case E_ITEM_MUTTON:
case E_ITEM_POISONOUS_POTATO: case E_ITEM_POISONOUS_POTATO:
case E_ITEM_PUMPKIN_PIE: case E_ITEM_PUMPKIN_PIE:
case E_ITEM_RED_APPLE:
case E_ITEM_RAW_BEEF: case E_ITEM_RAW_BEEF:
case E_ITEM_RAW_CHICKEN: case E_ITEM_RAW_CHICKEN:
case E_ITEM_RAW_FISH: case E_ITEM_RAW_FISH:
case E_ITEM_RAW_MUTTON:
case E_ITEM_RAW_PORKCHOP: case E_ITEM_RAW_PORKCHOP:
case E_ITEM_RED_APPLE:
case E_ITEM_ROTTEN_FLESH: case E_ITEM_ROTTEN_FLESH:
case E_ITEM_SPIDER_EYE: case E_ITEM_SPIDER_EYE:
case E_ITEM_STEAK: case E_ITEM_STEAK:

View File

@ -37,7 +37,7 @@ public:
{ {
switch (m_ItemType) switch (m_ItemType)
{ {
case E_ITEM_CARROT: return FoodInfo(4, 4.8); case E_ITEM_CARROT: return FoodInfo(3, 4.8);
case E_ITEM_POTATO: return FoodInfo(1, 0.6); case E_ITEM_POTATO: return FoodInfo(1, 0.6);
default: return FoodInfo(0, 0); default: return FoodInfo(0, 0);
} }

View File

@ -39,6 +39,13 @@ void cSheep::GetDrops(cItems & a_Drops, cEntity * a_Killer)
{ {
a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor)); a_Drops.push_back(cItem(E_BLOCK_WOOL, 1, m_WoolColor));
} }
int LootingLevel = 0;
if (a_Killer != NULL)
{
LootingLevel = a_Killer->GetEquippedWeapon().m_Enchantments.GetLevel(cEnchantments::enchLooting);
}
AddRandomDropItem(a_Drops, 1, 3 + LootingLevel, IsOnFire() ? E_ITEM_MUTTON : E_ITEM_RAW_MUTTON);
} }

View File

@ -180,3 +180,65 @@ extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString &
extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed)
{
a_Uncompressed.reserve(a_Length);
char Buffer[64 KiB];
z_stream strm;
memset(&strm, 0, sizeof(strm));
strm.next_in = (Bytef *)a_Data;
strm.avail_in = (uInt)a_Length;
strm.next_out = (Bytef *)Buffer;
strm.avail_out = sizeof(Buffer);
int res = inflateInit(&strm); // Force GZIP decoding
if (res != Z_OK)
{
LOG("%s: inflation initialization failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
return res;
}
for (;;)
{
res = inflate(&strm, Z_NO_FLUSH);
switch (res)
{
case Z_OK:
{
// Some data has been uncompressed. Consume the buffer and continue uncompressing
a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out);
strm.next_out = (Bytef *)Buffer;
strm.avail_out = sizeof(Buffer);
if (strm.avail_in == 0)
{
// All data has been uncompressed
inflateEnd(&strm);
return Z_OK;
}
break;
}
case Z_STREAM_END:
{
// Finished uncompressing. Consume the rest of the buffer and return
a_Uncompressed.append(Buffer, sizeof(Buffer) - strm.avail_out);
inflateEnd(&strm);
return Z_OK;
}
default:
{
// An error has occurred, log it and return the error value
LOG("%s: inflation failed: %d (\"%s\").", __FUNCTION__, res, strm.msg);
inflateEnd(&strm);
return res;
}
} // switch (res)
} // while (true)
}

View File

@ -21,5 +21,7 @@ extern int CompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_
/// Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib /// Uncompresses a_Data into a_Uncompressed using GZIP; returns Z_OK for success or Z_XXX error constants same as zlib
extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed); extern int UncompressStringGZIP(const char * a_Data, size_t a_Length, AString & a_Uncompressed);
/** Uncompresses a_Data into a_Uncompressed using Inflate; returns Z_OK for success or Z_XXX error constants same as zlib */
extern int InflateString(const char * a_Data, size_t a_Length, AString & a_Uncompressed);

View File

@ -442,7 +442,7 @@ void cWorld::InitializeSpawn(void)
{ {
for (int z = 0; z < ViewDist; z++) for (int z = 0; z < ViewDist; z++)
{ {
m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, ZERO_CHUNK_Y, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader m_ChunkMap->TouchChunk(x + ChunkX-(ViewDist - 1) / 2, z + ChunkZ-(ViewDist - 1) / 2); // Queue the chunk in the generator / loader
} }
} }
@ -2424,7 +2424,7 @@ void cWorld::SetChunkData(cSetChunkData & a_SetChunkData)
// Save the chunk right after generating, so that we don't have to generate it again on next run // Save the chunk right after generating, so that we don't have to generate it again on next run
if (a_SetChunkData.ShouldMarkDirty()) if (a_SetChunkData.ShouldMarkDirty())
{ {
m_Storage.QueueSaveChunk(ChunkX, 0, ChunkZ); m_Storage.QueueSaveChunk(ChunkX, ChunkZ);
} }
} }
@ -2778,18 +2778,18 @@ void cWorld::RemoveClientFromChunkSender(cClientHandle * a_Client)
void cWorld::TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorld::TouchChunk(int a_ChunkX, int a_ChunkZ)
{ {
m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkY, a_ChunkZ); m_ChunkMap->TouchChunk(a_ChunkX, a_ChunkZ);
} }
bool cWorld::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) bool cWorld::LoadChunk(int a_ChunkX, int a_ChunkZ)
{ {
return m_ChunkMap->LoadChunk(a_ChunkX, a_ChunkY, a_ChunkZ); return m_ChunkMap->LoadChunk(a_ChunkX, a_ChunkZ);
} }
@ -2805,9 +2805,9 @@ void cWorld::LoadChunks(const cChunkCoordsList & a_Chunks)
void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorld::ChunkLoadFailed(int a_ChunkX, int a_ChunkZ)
{ {
m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ); m_ChunkMap->ChunkLoadFailed(a_ChunkX, a_ChunkZ);
} }
@ -2912,8 +2912,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ)
{ {
m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ); m_ChunkMap->MarkChunkRegenerating(a_ChunkX, a_ChunkZ);
// Trick: use Y=1 to force the chunk generation even though the chunk data is already present m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, true);
m_Generator.QueueGenerateChunk(a_ChunkX, 1, a_ChunkZ);
} }
@ -2922,7 +2921,7 @@ void cWorld::RegenerateChunk(int a_ChunkX, int a_ChunkZ)
void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ) void cWorld::GenerateChunk(int a_ChunkX, int a_ChunkZ)
{ {
m_Generator.QueueGenerateChunk(a_ChunkX, ZERO_CHUNK_Y, a_ChunkZ); m_Generator.QueueGenerateChunk(a_ChunkX, a_ChunkZ, false);
} }

View File

@ -356,16 +356,16 @@ public:
void RemoveClientFromChunkSender(cClientHandle * a_Client); void RemoveClientFromChunkSender(cClientHandle * a_Client);
/** Touches the chunk, causing it to be loaded or generated */ /** Touches the chunk, causing it to be loaded or generated */
void TouchChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void TouchChunk(int a_ChunkX, int a_ChunkZ);
/** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */ /** Loads the chunk, if not already loaded. Doesn't generate. Returns true if chunk valid (even if already loaded before) */
bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); bool LoadChunk(int a_ChunkX, int a_ChunkZ);
/** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */ /** Loads the chunks specified. Doesn't report failure, other than chunks being !IsValid() */
void LoadChunks(const cChunkCoordsList & a_Chunks); void LoadChunks(const cChunkCoordsList & a_Chunks);
/** Marks the chunk as failed-to-load: */ /** Marks the chunk as failed-to-load: */
void ChunkLoadFailed(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void ChunkLoadFailed(int a_ChunkX, int a_ChunkZ);
/** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as UpdateSign() */ /** Sets the sign text, asking plugins for permission first. a_Player is the player who this change belongs to, may be NULL. Returns true if sign text changed. Same as UpdateSign() */
bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp bool SetSignLines(int a_BlockX, int a_BlockY, int a_BlockZ, const AString & a_Line1, const AString & a_Line2, const AString & a_Line3, const AString & a_Line4, cPlayer * a_Player = NULL); // Exported in ManualBindings.cpp
@ -385,7 +385,7 @@ public:
/** Regenerate the given chunk: */ /** Regenerate the given chunk: */
void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export void RegenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
/** Generates the given chunk, if not already generated */ /** Generates the given chunk */
void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export void GenerateChunk(int a_ChunkX, int a_ChunkZ); // tolua_export
/** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */ /** Queues a chunk for lighting; a_Callback is called after the chunk is lighted */

View File

@ -66,9 +66,6 @@ Since only the header is actually in the memory, this number can be high, but st
*/ */
#define MAX_MCA_FILES 32 #define MAX_MCA_FILES 32
/// The maximum size of an inflated chunk; raw chunk data is 192 KiB, allow 64 KiB more of entities
#define CHUNK_INFLATE_MAX 256 KiB
#define LOAD_FAILED(CHX, CHZ) \ #define LOAD_FAILED(CHX, CHZ) \
{ \ { \
const int RegionX = FAST_FLOOR_DIV(CHX, 32); \ const int RegionX = FAST_FLOOR_DIV(CHX, 32); \
@ -260,27 +257,18 @@ cWSSAnvil::cMCAFile * cWSSAnvil::LoadMCAFile(const cChunkCoords & a_Chunk)
bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data) bool cWSSAnvil::LoadChunkFromData(const cChunkCoords & a_Chunk, const AString & a_Data)
{ {
// Decompress the data: // Uncompress the data:
char Uncompressed[CHUNK_INFLATE_MAX]; AString Uncompressed;
z_stream strm; int res = InflateString(a_Data.data(), a_Data.size(), Uncompressed);
strm.zalloc = (alloc_func)NULL; if (res != Z_OK)
strm.zfree = (free_func)NULL;
strm.opaque = NULL;
inflateInit(&strm);
strm.next_out = (Bytef *)Uncompressed;
strm.avail_out = sizeof(Uncompressed);
strm.next_in = (Bytef *)a_Data.data();
strm.avail_in = (uInt)a_Data.size();
int res = inflate(&strm, Z_FINISH);
inflateEnd(&strm);
if (res != Z_STREAM_END)
{ {
LOGWARNING("Uncompressing chunk [%d, %d] failed: %d", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, res);
LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ); LOAD_FAILED(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false; return false;
} }
// Parse the NBT data: // Parse the NBT data:
cParsedNBT NBT(Uncompressed, strm.total_out); cParsedNBT NBT(Uncompressed.data(), Uncompressed.size());
if (!NBT.IsValid()) if (!NBT.IsValid())
{ {
// NBT Parsing failed // NBT Parsing failed
@ -2917,7 +2905,13 @@ bool cWSSAnvil::cMCAFile::SetChunkData(const cChunkCoords & a_Chunk, const AStri
// Store the header: // Store the header:
ChunkSize = ((u_long)a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size *up* to nearest 4KB sector, make it a sector number ChunkSize = ((u_long)a_Data.size() + MCA_CHUNK_HEADER_LENGTH + 4095) / 4096; // Round data size *up* to nearest 4KB sector, make it a sector number
ASSERT(ChunkSize < 256); if (ChunkSize > 255)
{
LOGWARNING("Cannot save chunk [%d, %d], the data is too large (%u KiB, maximum is 1024 KiB). Remove some entities and retry.",
a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, (unsigned)(ChunkSize * 4)
);
return false;
}
m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize); m_Header[LocalX + 32 * LocalZ] = htonl((ChunkSector << 8) | ChunkSize);
if (m_File.Seek(0) < 0) if (m_File.Seek(0) < 0)
{ {

View File

@ -980,7 +980,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer)) if (!a_World->GetChunkData(a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ, Serializer))
{ {
// Chunk not valid // Chunk not valid
LOG("cWSSCompact: Trying to save chunk [%d, %d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); LOG("cWSSCompact: Trying to save chunk [%d, %d] that has no data, ignoring request.", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false; return false;
} }
@ -999,7 +999,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor); int errorcode = CompressString(Data.data(), Data.size(), CompressedData, m_CompressionFactor);
if (errorcode != Z_OK) if (errorcode != Z_OK)
{ {
LOGERROR("Error %i compressing data for chunk [%d, %d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); LOGERROR("Error %i compressing data for chunk [%d, %d]", errorcode, a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false; return false;
} }
@ -1010,7 +1010,7 @@ bool cWSSCompact::cPAKFile::SaveChunkToData(const cChunkCoords & a_Chunk, cWorld
sChunkHeader * Header = new sChunkHeader; sChunkHeader * Header = new sChunkHeader;
if (Header == NULL) if (Header == NULL)
{ {
LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkY, a_Chunk.m_ChunkZ); LOGWARNING("Cannot create a new chunk header to save chunk [%d, %d]", a_Chunk.m_ChunkX, a_Chunk.m_ChunkZ);
return false; return false;
} }
Header->m_CompressedSize = (int)CompressedData.size(); Header->m_CompressedSize = (int)CompressedData.size();

View File

@ -141,9 +141,9 @@ size_t cWorldStorage::GetSaveQueueLength(void)
void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate)
{ {
m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, a_Generate)); m_LoadQueue.EnqueueItem(sChunkLoad(a_ChunkX, a_ChunkZ, a_Generate));
m_Event.Set(); m_Event.Set();
} }
@ -151,9 +151,9 @@ void cWorldStorage::QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, boo
void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkZ)
{ {
m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkY, a_ChunkZ)); m_SaveQueue.EnqueueItemIfNotPresent(cChunkCoords(a_ChunkX, a_ChunkZ));
m_Event.Set(); m_Event.Set();
} }
@ -161,9 +161,9 @@ void cWorldStorage::QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ) void cWorldStorage::UnqueueLoad(int a_ChunkX, int a_ChunkZ)
{ {
m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkY, a_ChunkZ, true)); m_LoadQueue.Remove(sChunkLoad(a_ChunkX, a_ChunkZ, true));
} }
@ -242,19 +242,19 @@ void cWorldStorage::Execute(void)
bool cWorldStorage::LoadOneChunk(void) bool cWorldStorage::LoadOneChunk(void)
{ {
sChunkLoad ToLoad(0, 0, 0, false); sChunkLoad ToLoad(0, 0, false);
bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad); bool ShouldLoad = m_LoadQueue.TryDequeueItem(ToLoad);
if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ)) if (ShouldLoad && !LoadChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ))
{ {
if (ToLoad.m_Generate) if (ToLoad.m_Generate)
{ {
// The chunk couldn't be loaded, generate it: // The chunk couldn't be loaded, generate it:
m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ); m_World->GetGenerator().QueueGenerateChunk(ToLoad.m_ChunkX, ToLoad.m_ChunkZ, false);
} }
else else
{ {
// TODO: Notify the world that the load has failed: // TODO: Notify the world that the load has failed:
// m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkY, ToLoad.m_ChunkZ); // m_World->ChunkLoadFailed(ToLoad.m_ChunkX, ToLoad.m_ChunkZ);
} }
} }
return ShouldLoad; return ShouldLoad;
@ -266,7 +266,7 @@ bool cWorldStorage::LoadOneChunk(void)
bool cWorldStorage::SaveOneChunk(void) bool cWorldStorage::SaveOneChunk(void)
{ {
cChunkCoords ToSave(0, 0, 0); cChunkCoords ToSave(0, 0);
bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave); bool ShouldSave = m_SaveQueue.TryDequeueItem(ToSave);
if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ)) if (ShouldSave && m_World->IsChunkValid(ToSave.m_ChunkX, ToSave.m_ChunkZ))
{ {
@ -283,7 +283,7 @@ bool cWorldStorage::SaveOneChunk(void)
bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ) bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkZ)
{ {
if (m_World->IsChunkValid(a_ChunkX, a_ChunkZ)) if (m_World->IsChunkValid(a_ChunkX, a_ChunkZ))
{ {
@ -291,7 +291,7 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
return true; return true;
} }
cChunkCoords Coords(a_ChunkX, a_ChunkY, a_ChunkZ); cChunkCoords Coords(a_ChunkX, a_ChunkZ);
// First try the schema that is used for saving // First try the schema that is used for saving
if (m_SaveSchema->LoadChunk(Coords)) if (m_SaveSchema->LoadChunk(Coords))
@ -309,7 +309,7 @@ bool cWorldStorage::LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ)
} }
// Notify the chunk owner that the chunk failed to load (sets cChunk::m_HasLoadFailed to true): // Notify the chunk owner that the chunk failed to load (sets cChunk::m_HasLoadFailed to true):
m_World->ChunkLoadFailed(a_ChunkX, a_ChunkY, a_ChunkZ); m_World->ChunkLoadFailed(a_ChunkX, a_ChunkZ);
return false; return false;
} }

View File

@ -64,13 +64,13 @@ public:
cWorldStorage(void); cWorldStorage(void);
~cWorldStorage(); ~cWorldStorage();
void QueueLoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true void QueueLoadChunk(int a_ChunkX, int a_ChunkZ, bool a_Generate); // Queues the chunk for loading; if not loaded, the chunk will be generated if a_Generate is true
void QueueSaveChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void QueueSaveChunk(int a_ChunkX, int a_ChunkZ);
/// Loads the chunk specified; returns true on success, false on failure /// Loads the chunk specified; returns true on success, false on failure
bool LoadChunk(int a_ChunkX, int a_ChunkY, int a_ChunkZ); bool LoadChunk(int a_ChunkX, int a_ChunkZ);
void UnqueueLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ); void UnqueueLoad(int a_ChunkX, int a_ChunkZ);
void UnqueueSave(const cChunkCoords & a_Chunk); void UnqueueSave(const cChunkCoords & a_Chunk);
bool Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor); // Hide the cIsThread's Start() method, we need to provide args bool Start(cWorld * a_World, const AString & a_StorageSchemaName, int a_StorageCompressionFactor); // Hide the cIsThread's Start() method, we need to provide args
@ -87,17 +87,15 @@ protected:
struct sChunkLoad struct sChunkLoad
{ {
int m_ChunkX; int m_ChunkX;
int m_ChunkY;
int m_ChunkZ; int m_ChunkZ;
bool m_Generate; // If true, the chunk will be generated if it cannot be loaded bool m_Generate; // If true, the chunk will be generated if it cannot be loaded
sChunkLoad(int a_ChunkX, int a_ChunkY, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkY(a_ChunkY), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {} sChunkLoad(int a_ChunkX, int a_ChunkZ, bool a_Generate) : m_ChunkX(a_ChunkX), m_ChunkZ(a_ChunkZ), m_Generate(a_Generate) {}
bool operator ==(const sChunkLoad other) const bool operator ==(const sChunkLoad other) const
{ {
return ( return (
(this->m_ChunkX == other.m_ChunkX) && (this->m_ChunkX == other.m_ChunkX) &&
(this->m_ChunkY == other.m_ChunkY) &&
(this->m_ChunkZ == other.m_ChunkZ) (this->m_ChunkZ == other.m_ChunkZ)
); );
} }