summaryrefslogtreecommitdiffstats
path: root/src/BlockEntities
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2014-10-19 12:46:25 +0200
committerMattes D <github@xoft.cz>2014-10-19 12:46:25 +0200
commitb0a59927fb7531f6c909e6f581035568c79b625c (patch)
tree9837f6962a6744c6da9fb614c20ec7f46825a7c4 /src/BlockEntities
parentLuaState: Pushing a cEntity pushes the correct class name. (diff)
downloadcuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar.gz
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar.bz2
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar.lz
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar.xz
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.tar.zst
cuberite-b0a59927fb7531f6c909e6f581035568c79b625c.zip
Diffstat (limited to 'src/BlockEntities')
-rw-r--r--src/BlockEntities/BeaconEntity.h2
-rw-r--r--src/BlockEntities/BlockEntity.h31
-rw-r--r--src/BlockEntities/BlockEntityWithItems.h4
-rw-r--r--src/BlockEntities/ChestEntity.h4
-rw-r--r--src/BlockEntities/CommandBlockEntity.h2
-rw-r--r--src/BlockEntities/DispenserEntity.h4
-rw-r--r--src/BlockEntities/DropSpenserEntity.h4
-rw-r--r--src/BlockEntities/DropperEntity.h4
-rw-r--r--src/BlockEntities/EnderChestEntity.h4
-rw-r--r--src/BlockEntities/FlowerPotEntity.h4
-rw-r--r--src/BlockEntities/FurnaceEntity.h4
-rw-r--r--src/BlockEntities/HopperEntity.h4
-rw-r--r--src/BlockEntities/JukeboxEntity.h4
-rw-r--r--src/BlockEntities/MobHeadEntity.h4
-rw-r--r--src/BlockEntities/NoteEntity.h4
-rw-r--r--src/BlockEntities/SignEntity.h4
16 files changed, 62 insertions, 25 deletions
diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h
index 8c2dad254..d1db3a68f 100644
--- a/src/BlockEntities/BeaconEntity.h
+++ b/src/BlockEntities/BeaconEntity.h
@@ -32,6 +32,8 @@ class cBeaconEntity :
public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cBeaconEntity);
+
cBeaconEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
// cBlockEntity overrides:
diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h
index 54ab40f3e..b04d20340 100644
--- a/src/BlockEntities/BlockEntity.h
+++ b/src/BlockEntities/BlockEntity.h
@@ -5,6 +5,28 @@
+/** Place this macro in the declaration of each cBlockEntity descendant. */
+#define BLOCKENTITY_PROTODEF(classname) \
+ virtual bool IsA(const char * a_ClassName) const override \
+ { \
+ return ((strcmp(a_ClassName, #classname) == 0) || super::IsA(a_ClassName)); \
+ } \
+ virtual const char * GetClass(void) const override \
+ { \
+ return #classname; \
+ } \
+ static const char * GetClassStatic(void) \
+ { \
+ return #classname; \
+ } \
+ virtual const char * GetParentClass(void) const override \
+ { \
+ return super::GetClass(); \
+ }
+
+
+
+
namespace Json
{
@@ -55,6 +77,15 @@ public:
{
return "cBlockEntity";
}
+
+ /** 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 parent class, or empty string if no parent class. */
+ virtual const char * GetParentClass(void) const { return ""; }
// tolua_begin
diff --git a/src/BlockEntities/BlockEntityWithItems.h b/src/BlockEntities/BlockEntityWithItems.h
index 00173cbcb..cb7bc2fb4 100644
--- a/src/BlockEntities/BlockEntityWithItems.h
+++ b/src/BlockEntities/BlockEntityWithItems.h
@@ -25,10 +25,12 @@ class cBlockEntityWithItems :
public cBlockEntityWindowOwner
{
typedef cBlockEntity super;
-
+
public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cBlockEntityWithItems);
+
cBlockEntityWithItems(
BLOCKTYPE a_BlockType, // Type of the block that the entity represents
int a_BlockX, int a_BlockY, int a_BlockZ, // Position of the block entity
diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h
index af5d851a8..09fffb923 100644
--- a/src/BlockEntities/ChestEntity.h
+++ b/src/BlockEntities/ChestEntity.h
@@ -33,13 +33,13 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cChestEntity);
+
/** Constructor used for normal operation */
cChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World, BLOCKTYPE a_Type);
virtual ~cChestEntity();
- static const char * GetClassStatic(void) { return "cChestEntity"; }
-
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual void UsedBy(cPlayer * a_Player) override;
diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h
index 939f38610..217390293 100644
--- a/src/BlockEntities/CommandBlockEntity.h
+++ b/src/BlockEntities/CommandBlockEntity.h
@@ -36,6 +36,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cCommandBlockEntity);
+
/// Creates a new empty command block entity
cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
diff --git a/src/BlockEntities/DispenserEntity.h b/src/BlockEntities/DispenserEntity.h
index b33d08342..5ba87b716 100644
--- a/src/BlockEntities/DispenserEntity.h
+++ b/src/BlockEntities/DispenserEntity.h
@@ -17,11 +17,11 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cDispenserEntity);
+
/** Constructor used for normal operation */
cDispenserEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
- static const char * GetClassStatic(void) { return "cDispenserEntity"; }
-
// tolua_begin
/** Spawns a projectile of the given kind in front of the dispenser with the specified speed. */
diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h
index 23f0ae89a..f77a28c28 100644
--- a/src/BlockEntities/DropSpenserEntity.h
+++ b/src/BlockEntities/DropSpenserEntity.h
@@ -45,11 +45,11 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cDropSpenserEntity);
+
cDropSpenserEntity(BLOCKTYPE a_BlockType, int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cDropSpenserEntity();
- static const char * GetClassStatic(void) { return "cDropSpenserEntity"; }
-
// cBlockEntity overrides:
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
virtual void SendTo(cClientHandle & a_Client) override;
diff --git a/src/BlockEntities/DropperEntity.h b/src/BlockEntities/DropperEntity.h
index 8e07bc6f8..91adf660f 100644
--- a/src/BlockEntities/DropperEntity.h
+++ b/src/BlockEntities/DropperEntity.h
@@ -25,11 +25,11 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cDropperEntity);
+
/// Constructor used for normal operation
cDropperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
- static const char * GetClassStatic(void) { return "cDropperEntity"; }
-
protected:
// cDropSpenserEntity overrides:
virtual void DropSpenseFromSlot(cChunk & a_Chunk, int a_SlotNum) override;
diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h
index 2719eb5e4..17abd880a 100644
--- a/src/BlockEntities/EnderChestEntity.h
+++ b/src/BlockEntities/EnderChestEntity.h
@@ -18,11 +18,11 @@ class cEnderChestEntity :
public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cEnderChestEntity);
+
cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cEnderChestEntity();
- static const char * GetClassStatic(void) { return "cEnderChestEntity"; }
-
// cBlockEntity overrides:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); }
diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h
index b68d3b118..5b86621f5 100644
--- a/src/BlockEntities/FlowerPotEntity.h
+++ b/src/BlockEntities/FlowerPotEntity.h
@@ -36,6 +36,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cFlowerPotEntity);
+
/** Creates a new flowerpot entity at the specified block coords. a_World may be NULL */
cFlowerPotEntity(int a_BlocX, int a_BlockY, int a_BlockZ, cWorld * a_World);
@@ -59,8 +61,6 @@ public:
static bool IsFlower(short m_ItemType, short m_ItemData);
- static const char * GetClassStatic(void) { return "cFlowerPotEntity"; }
-
private:
cItem m_Item;
diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h
index 14dadbec8..8e48810ba 100644
--- a/src/BlockEntities/FurnaceEntity.h
+++ b/src/BlockEntities/FurnaceEntity.h
@@ -38,13 +38,13 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cFurnaceEntity);
+
/** Constructor used for normal operation */
cFurnaceEntity(int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, cWorld * a_World);
virtual ~cFurnaceEntity();
- static const char * GetClassStatic() { return "cFurnaceEntity"; }
-
// cBlockEntity overrides:
virtual void SendTo(cClientHandle & a_Client) override;
virtual bool Tick(float a_Dt, cChunk & a_Chunk) override;
diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h
index 5d06581c2..7070bbad3 100644
--- a/src/BlockEntities/HopperEntity.h
+++ b/src/BlockEntities/HopperEntity.h
@@ -31,6 +31,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cHopperEntity);
+
/// Constructor used for normal operation
cHopperEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
@@ -40,8 +42,6 @@ public:
*/
bool GetOutputBlockPos(NIBBLETYPE a_BlockMeta, int & a_OutputX, int & a_OutputY, int & a_OutputZ);
- static const char * GetClassStatic(void) { return "cHopperEntity"; }
-
protected:
Int64 m_LastMoveItemsInTick;
diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h
index 49d2faa89..7a69d6499 100644
--- a/src/BlockEntities/JukeboxEntity.h
+++ b/src/BlockEntities/JukeboxEntity.h
@@ -26,6 +26,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cJukeboxEntity);
+
cJukeboxEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
virtual ~cJukeboxEntity();
@@ -51,8 +53,6 @@ public:
// tolua_end
- static const char * GetClassStatic(void) { return "cJukeboxEntity"; }
-
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle &) override {}
diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h
index fcdeaa8a6..7f69bc5ad 100644
--- a/src/BlockEntities/MobHeadEntity.h
+++ b/src/BlockEntities/MobHeadEntity.h
@@ -34,6 +34,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cMobHeadEntity);
+
/** Creates a new mob head entity at the specified block coords. a_World may be NULL */
cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World);
@@ -62,8 +64,6 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
- static const char * GetClassStatic(void) { return "cMobHeadEntity"; }
-
private:
eMobHeadType m_Type;
diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h
index d1ffa126a..74dbde046 100644
--- a/src/BlockEntities/NoteEntity.h
+++ b/src/BlockEntities/NoteEntity.h
@@ -40,6 +40,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cNoteEntity);
+
/// Creates a new note entity. a_World may be NULL
cNoteEntity(int a_X, int a_Y, int a_Z, cWorld * a_World);
virtual ~cNoteEntity() {}
@@ -64,8 +66,6 @@ public:
}
}
- static const char * GetClassStatic(void) { return "cNoteEntity"; }
-
private:
char m_Pitch;
} ; // tolua_export
diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h
index 53c43b758..be13c7a32 100644
--- a/src/BlockEntities/SignEntity.h
+++ b/src/BlockEntities/SignEntity.h
@@ -34,6 +34,8 @@ public:
// tolua_end
+ BLOCKENTITY_PROTODEF(cSignEntity);
+
/// Creates a new empty sign entity at the specified block coords and block type (wall or standing). a_World may be NULL
cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorld * a_World);
@@ -53,8 +55,6 @@ public:
virtual void UsedBy(cPlayer * a_Player) override;
virtual void SendTo(cClientHandle & a_Client) override;
- static const char * GetClassStatic(void) { return "cSignEntity"; }
-
private:
AString m_Line[4];