cLuaState: cBlockEntity descendants are pushed with proper class type.
This commit is contained in:
parent
ebd31ff132
commit
b0a59927fb
@ -522,7 +522,7 @@ void cLuaState::Push(cBlockEntity * a_BlockEntity)
|
||||
{
|
||||
ASSERT(IsValid());
|
||||
|
||||
tolua_pushusertype(m_LuaState, a_BlockEntity, "cBlockEntity");
|
||||
tolua_pushusertype(m_LuaState, a_BlockEntity, (a_BlockEntity == nullptr) ? "cBlockEntity" : a_BlockEntity->GetClass());
|
||||
m_NumCurrentFunctionArgs += 1;
|
||||
}
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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. */
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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); }
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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 {}
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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];
|
||||
|
Loading…
Reference in New Issue
Block a user