From 06942871dde1388284a4fe222040720de3923b03 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 5 Aug 2014 21:48:23 +0100 Subject: Refactored Redstone simulator not to depend on TNTEntity or DropSpenserENtity Directly --- src/BlockEntities/DropSpenserEntity.h | 7 ++++--- src/BlockEntities/RedstonePoweredEntity.h | 9 +++++++++ 2 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 src/BlockEntities/RedstonePoweredEntity.h (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index 9f58d0b07..dabe9a27b 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -11,7 +11,7 @@ #pragma once #include "BlockEntityWithItems.h" - +#include "RedstonePoweredEntity.h" @@ -30,7 +30,8 @@ class cServer; // tolua_begin class cDropSpenserEntity : - public cBlockEntityWithItems + public cBlockEntityWithItems, + public cRedstonePoweredEntity { typedef cBlockEntityWithItems super; @@ -65,7 +66,7 @@ public: void Activate(void); /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate - void SetRedstonePower(bool a_IsPowered); + virtual void SetRedstonePower(bool a_IsPowered) override; // tolua_end diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h new file mode 100644 index 000000000..aebba771f --- /dev/null +++ b/src/BlockEntities/RedstonePoweredEntity.h @@ -0,0 +1,9 @@ + + +// Interface class representing a blockEntity that responds to redstone +class cRedstonePoweredEntity +{ +public: +/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate + virtual void SetRedstonePower(bool a_IsPowered) = 0; +}; -- cgit v1.2.3 From 9272bd627c732771b81e6dcf6b8465404917a9d6 Mon Sep 17 00:00:00 2001 From: Tycho Date: Tue, 5 Aug 2014 22:54:36 +0100 Subject: Removed dependecy of redstone simulator on NoteBlock --- src/BlockEntities/NoteEntity.h | 10 +++++++++- src/BlockEntities/RedstonePoweredEntity.h | 4 ++++ 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index e8497da3e..f9db6cbe6 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -2,6 +2,7 @@ #pragma once #include "BlockEntity.h" +#include "RedstonePoweredEntity.h" namespace Json @@ -29,7 +30,8 @@ enum ENUM_NOTE_INSTRUMENTS // tolua_begin class cNoteEntity : - public cBlockEntity + public cBlockEntity, + public cRedstonePoweredEntity { typedef cBlockEntity super; public: @@ -38,6 +40,7 @@ public: /// 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() {} bool LoadFromJson(const Json::Value & a_Value); virtual void SaveToJson(Json::Value & a_Value) override; @@ -53,6 +56,11 @@ public: virtual void UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override {} + + virtual void SetRedstonePower(bool a_Value) + { + if (a_Value) MakeSound(); + } static const char * GetClassStatic(void) { return "cNoteEntity"; } diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h index aebba771f..7d6904442 100644 --- a/src/BlockEntities/RedstonePoweredEntity.h +++ b/src/BlockEntities/RedstonePoweredEntity.h @@ -1,9 +1,13 @@ +#pragma once // Interface class representing a blockEntity that responds to redstone class cRedstonePoweredEntity { public: + + virtual ~cRedstonePoweredEntity() {}; + /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate virtual void SetRedstonePower(bool a_IsPowered) = 0; }; -- cgit v1.2.3 From a0ba7426c6bc2059d5db6d248ef8e582e40ce4b3 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 6 Aug 2014 13:17:05 +0100 Subject: Fixed multiple inhertance being output by tolua --- src/BlockEntities/DropSpenserEntity.h | 10 ++++++---- src/BlockEntities/NoteEntity.h | 6 ++++-- 2 files changed, 10 insertions(+), 6 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index dabe9a27b..be56447aa 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -30,8 +30,10 @@ class cServer; // tolua_begin class cDropSpenserEntity : - public cBlockEntityWithItems, - public cRedstonePoweredEntity + public cBlockEntityWithItems + // tolua_end + , public cRedstonePoweredEntity + // tolua_begin { typedef cBlockEntityWithItems super; @@ -65,10 +67,10 @@ public: /// Sets the dropspenser to dropspense an item in the next tick void Activate(void); + // tolua_end + /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate virtual void SetRedstonePower(bool a_IsPowered) override; - - // tolua_end protected: bool m_ShouldDropSpense; ///< If true, the dropspenser will dropspense an item in the next tick diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index f9db6cbe6..dd201e0a9 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -30,8 +30,10 @@ enum ENUM_NOTE_INSTRUMENTS // tolua_begin class cNoteEntity : - public cBlockEntity, - public cRedstonePoweredEntity + public cBlockEntity + // tolua_end + , public cRedstonePoweredEntity + // tolua_begin { typedef cBlockEntity super; public: -- cgit v1.2.3 From 6acddd0cad25078ae2c67e7a0eb353e9d4d100e2 Mon Sep 17 00:00:00 2001 From: Tycho Date: Wed, 6 Aug 2014 13:19:22 +0100 Subject: Fixed style issues --- src/BlockEntities/NoteEntity.h | 5 ++++- src/BlockEntities/RedstonePoweredEntity.h | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index dd201e0a9..f538de060 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -61,7 +61,10 @@ public: virtual void SetRedstonePower(bool a_Value) { - if (a_Value) MakeSound(); + if (a_Value) + { + MakeSound(); + } } static const char * GetClassStatic(void) { return "cNoteEntity"; } diff --git a/src/BlockEntities/RedstonePoweredEntity.h b/src/BlockEntities/RedstonePoweredEntity.h index 7d6904442..f11df4fc4 100644 --- a/src/BlockEntities/RedstonePoweredEntity.h +++ b/src/BlockEntities/RedstonePoweredEntity.h @@ -8,6 +8,6 @@ public: virtual ~cRedstonePoweredEntity() {}; -/// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate + /// Sets the internal redstone power flag to "on" or "off", depending on the parameter. Calls Activate() if appropriate virtual void SetRedstonePower(bool a_IsPowered) = 0; }; -- cgit v1.2.3 From 5623a045f598a068a7bae77cc3acad62f6160452 Mon Sep 17 00:00:00 2001 From: Tycho Date: Sun, 10 Aug 2014 22:06:56 +0100 Subject: Fixed potential null dereference Fixes CID 70466 --- src/BlockEntities/HopperEntity.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/BlockEntities') diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 48d3b8dcc..88e7b8e1b 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -549,13 +549,13 @@ bool cHopperEntity::MoveItemsFromSlot(cBlockEntityWithItems & a_Entity, int a_Sl bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_BlockY, int a_BlockZ) { // Try the chest directly connected to the hopper: - cChestEntity * Chest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); - if (Chest == NULL) + cChestEntity * ConnectedChest = (cChestEntity *)a_Chunk.GetBlockEntity(a_BlockX, a_BlockY, a_BlockZ); + if (ConnectedChest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d}", __FUNCTION__, a_BlockX, a_BlockY, a_BlockZ); return false; } - if (MoveItemsToGrid(*Chest)) + if (MoveItemsToGrid(*ConnectedChest)) { // Chest block directly connected was not full return true; @@ -586,13 +586,13 @@ bool cHopperEntity::MoveItemsToChest(cChunk & a_Chunk, int a_BlockX, int a_Block } BLOCKTYPE Block = Neighbor->GetBlock(x, a_BlockY, z); - if (Block != Chest->GetBlockType()) + if (Block != ConnectedChest->GetBlockType()) { // Not the same kind of chest continue; } - Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); + cChestEntity * Chest = (cChestEntity *)Neighbor->GetBlockEntity(a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z); if (Chest == NULL) { LOGWARNING("%s: A chest entity was not found where expected, at {%d, %d, %d} (%d, %d)", __FUNCTION__, a_BlockX + Coords[i].x, a_BlockY, a_BlockZ + Coords[i].z, x, z); -- cgit v1.2.3