summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/BlockEntity.h
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2019-09-29 14:59:24 +0200
committerGitHub <noreply@github.com>2019-09-29 14:59:24 +0200
commit365cbc6e1cea96741e26c9ce912b003f8fd2c62c (patch)
treef23682c47928597791c53f3a300b03494ffde417 /src/BlockEntities/BlockEntity.h
parentCactus can now grow and will be dropped if there is no place to grow. (diff)
downloadcuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar.gz
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar.bz2
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar.lz
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar.xz
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.tar.zst
cuberite-365cbc6e1cea96741e26c9ce912b003f8fd2c62c.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/BlockEntity.h66
1 files changed, 34 insertions, 32 deletions
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index 5b7184775..cb377422e 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -9,19 +9,19 @@
#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 \
+ virtual const char * GetClass() const override \
{ \
return #classname; \
} \
- static const char * GetClassStatic(void) \
+ static const char * GetClassStatic() \
{ \
return #classname; \
} \
- virtual const char * GetParentClass(void) const override \
+ virtual const char * GetParentClass() const override \
{ \
- return Super::GetClass(); \
+ return super::GetClass(); \
}
@@ -40,12 +40,10 @@ class cWorld;
class cBlockEntity
{
protected:
- 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)),
+ cBlockEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World) :
+ m_Pos(a_Pos),
+ m_RelX(a_Pos.x - cChunkDef::Width * FAST_FLOOR_DIV(a_Pos.x, cChunkDef::Width)),
+ m_RelZ(a_Pos.z - cChunkDef::Width * FAST_FLOOR_DIV(a_Pos.z, cChunkDef::Width)),
m_BlockType(a_BlockType),
m_BlockMeta(a_BlockMeta),
m_World(a_World)
@@ -57,7 +55,7 @@ public:
virtual ~cBlockEntity() {} // force a virtual destructor in all descendants
- virtual void Destroy(void) {}
+ virtual void Destroy() {}
void SetWorld(cWorld * a_World)
{
@@ -66,27 +64,27 @@ public:
/** Updates the internally stored position.
Note that this should not ever be used for world-contained block entities, it is meant only for when BEs in a cBlockArea are manipulated.
- Asserts when the block entity is assigned to a world. */
- void SetPos(int a_NewBlockX, int a_NewBlockY, int a_NewBlockZ);
+ Asserts that the block entity is not assigned to a world. */
+ void SetPos(Vector3i a_NewPos);
/** Returns true if the specified blocktype is supposed to have an associated block entity. */
static bool IsBlockEntityBlockType(BLOCKTYPE a_BlockType);
- /** Creates a new block entity for the specified block type
+ /** Creates a new block entity for the specified block type at the specified absolute pos.
If a_World is valid, then the entity is created bound to that world
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);
+ static cBlockEntity * CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, 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);
+ cBlockEntity * Clone(Vector3i a_Pos);
/** 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
+ static const char * GetClassStatic() // Needed for ManualBindings's ForEach templates
{
return "cBlockEntity";
}
@@ -94,29 +92,31 @@ public:
/** Returns true if the object is the specified class, or its descendant. */
virtual bool IsA(const char * a_ClassName) const { return (strcmp(a_ClassName, "cBlockEntity") == 0); }
- /** Returns the name of the tompost class (the most descendant). Used for Lua bindings to push the correct object type. */
- virtual const char * GetClass(void) const { return GetClassStatic(); }
+ /** Returns the name of the topmost class (the most descendant). Used for Lua bindings to push the correct object type. */
+ virtual const char * GetClass() const { return GetClassStatic(); }
/** Returns the name of the parent class, or empty string if no parent class. */
- virtual const char * GetParentClass(void) const { return ""; }
+ virtual const char * GetParentClass() const { return ""; }
// tolua_begin
// Position, in absolute block coordinates:
- Vector3i GetPos(void) const { return Vector3i{m_PosX, m_PosY, m_PosZ}; }
- int GetPosX(void) const { return m_PosX; }
- int GetPosY(void) const { return m_PosY; }
- int GetPosZ(void) const { return m_PosZ; }
+ Vector3i GetPos() const { return m_Pos; }
+ int GetPosX() const { return m_Pos.x; }
+ int GetPosY() const { return m_Pos.y; }
+ int GetPosZ() const { return m_Pos.z; }
- BLOCKTYPE GetBlockType(void) const { return m_BlockType; }
+ Vector3i GetRelPos() const { return Vector3i(m_RelX, m_Pos.y, m_RelZ); }
- cWorld * GetWorld(void) const { return m_World; }
+ BLOCKTYPE GetBlockType() const { return m_BlockType; }
- int GetChunkX(void) const { return FAST_FLOOR_DIV(m_PosX, cChunkDef::Width); }
- int GetChunkZ(void) const { return FAST_FLOOR_DIV(m_PosZ, cChunkDef::Width); }
+ cWorld * GetWorld() const { return m_World; }
- int GetRelX(void) const { return m_RelX; }
- int GetRelZ(void) const { return m_RelZ; }
+ int GetChunkX() const { return FAST_FLOOR_DIV(m_Pos.x, cChunkDef::Width); }
+ int GetChunkZ() const { return FAST_FLOOR_DIV(m_Pos.y, cChunkDef::Width); }
+
+ int GetRelX() const { return m_RelX; }
+ int GetRelZ() const { return m_RelZ; }
// tolua_end
@@ -135,9 +135,11 @@ public:
return false;
}
+
protected:
+
/** Position in absolute block coordinates */
- int m_PosX, m_PosY, m_PosZ;
+ Vector3i m_Pos;
/** Position relative to the chunk, used to speed up ticking */
int m_RelX, m_RelZ;