BlockEntities: Support cloning self.

This commit is contained in:
Mattes D
2017-06-16 14:11:28 +02:00
committed by Lukas Pioch
parent 49e015b8de
commit 0dd1cd750b
41 changed files with 640 additions and 309 deletions
+19 -3
View File
@@ -9,7 +9,7 @@
#define BLOCKENTITY_PROTODEF(classname) \
virtual bool IsA(const char * a_ClassName) const override \
{ \
return ((a_ClassName != nullptr) && ((strcmp(a_ClassName, #classname) == 0) || super::IsA(a_ClassName))); \
return ((a_ClassName != nullptr) && ((strcmp(a_ClassName, #classname) == 0) || Super::IsA(a_ClassName))); \
} \
virtual const char * GetClass(void) const override \
{ \
@@ -21,7 +21,7 @@
} \
virtual const char * GetParentClass(void) const override \
{ \
return super::GetClass(); \
return Super::GetClass(); \
}
@@ -40,13 +40,14 @@ class cWorld;
class cBlockEntity
{
protected:
cBlockEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
cBlockEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
m_PosX(a_BlockX),
m_PosY(a_BlockY),
m_PosZ(a_BlockZ),
m_RelX(a_BlockX - cChunkDef::Width * FAST_FLOOR_DIV(a_BlockX, cChunkDef::Width)),
m_RelZ(a_BlockZ - cChunkDef::Width * FAST_FLOOR_DIV(a_BlockZ, cChunkDef::Width)),
m_BlockType(a_BlockType),
m_BlockMeta(a_BlockMeta),
m_World(a_World)
{
}
@@ -68,6 +69,15 @@ public:
Returns nullptr for unknown block types. */
static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World = nullptr);
/** Makes an exact copy of this block entity, except for its m_World (set to nullptr), and at a new position.
Uses CopyFrom() to copy the properties. */
cBlockEntity * Clone(int a_BlockX, int a_BlockY, int a_BlockZ);
/** Copies all properties of a_Src into this entity, except for its m_World and location.
Each non-abstract descendant should override to copy its specific properties, and call
Super::CopyFrom(a_Src) to copy the common ones. */
virtual void CopyFrom(const cBlockEntity & a_Src);
static const char * GetClassStatic(void) // Needed for ManualBindings's ForEach templates
{
return "cBlockEntity";
@@ -124,8 +134,14 @@ protected:
/** Position relative to the chunk, used to speed up ticking */
int m_RelX, m_RelZ;
/** The blocktype representing this particular instance in the world.
Mainly used for multi-block-type entities, such as furnaces / lit furnaces. */
BLOCKTYPE m_BlockType;
/** The block meta representing this particular instance in the world
Mainly used for directional entities, such as dispensers. */
NIBBLETYPE m_BlockMeta;
cWorld * m_World;
} ; // tolua_export