summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities/BlockEntity.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/BlockEntities/BlockEntity.h')
-rw-r--r--src/BlockEntities/BlockEntity.h79
1 files changed, 34 insertions, 45 deletions
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index 3355cdf44..3e9cf38e7 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -24,41 +24,14 @@ using cBlockEntities = std::unordered_map<size_t, OwnedBlockEntity>;
class cBlockEntity
{
protected:
- 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)
- {
- }
+
+ cBlockEntity(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World);
public:
// tolua_end
- virtual ~cBlockEntity() {} // force a virtual destructor in all descendants
-
- virtual void Destroy() {}
-
- void SetWorld(cWorld * a_World)
- {
- m_World = a_World;
- }
-
- /** 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 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 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 OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr);
+ virtual ~cBlockEntity() = default; // force a virtual destructor in all descendants
/** 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. */
@@ -73,6 +46,37 @@ public:
Super::CopyFrom(a_Src) to copy the common ones. */
virtual void CopyFrom(const cBlockEntity & a_Src);
+ /** 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 OwnedBlockEntity CreateByBlockType(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, Vector3i a_Pos, cWorld * a_World = nullptr);
+
+ virtual void Destroy();
+
+ /** Returns true if the specified blocktype is supposed to have an associated block entity. */
+ static bool IsBlockEntityBlockType(BLOCKTYPE a_BlockType);
+
+ /** Called when the block entity is removed from a world. */
+ virtual void OnRemoveFromWorld();
+
+ /** Sends the packet defining the block entity to the client specified.
+ To send to all eligible clients, use cWorld::BroadcastBlockEntity() */
+ virtual void SendTo(cClientHandle & a_Client) = 0;
+
+ /** 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 that the block entity is not assigned to a world. */
+ void SetPos(Vector3i a_NewPos);
+
+ void SetWorld(cWorld * a_World);
+
+ /** Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. */
+ virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk);
+
+ /** Called when a player uses this entity; should open the UI window.
+ returns true if the use was successful, return false to use the block as a "normal" block */
+ virtual bool UsedBy(cPlayer * a_Player) = 0;
+
// tolua_begin
// Position, in absolute block coordinates:
@@ -95,21 +99,6 @@ public:
// tolua_end
- /** Called when a player uses this entity; should open the UI window.
- returns true if the use was successful, return false to use the block as a "normal" block */
- virtual bool UsedBy( cPlayer * a_Player) = 0;
-
- /** Sends the packet defining the block entity to the client specified.
- To send to all eligible clients, use cWorld::BroadcastBlockEntity() */
- virtual void SendTo(cClientHandle & a_Client) = 0;
-
- /** Ticks the entity; returns true if the chunk should be marked as dirty as a result of this ticking. By default does nothing. */
- virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk)
- {
- UNUSED(a_Dt);
- return false;
- }
-
protected: