diff options
author | Gargaj <gargaj@conspiracy.hu> | 2015-12-01 23:12:44 +0100 |
---|---|---|
committer | Gargaj <gargaj@conspiracy.hu> | 2015-12-13 13:27:38 +0100 |
commit | f9008a4860dc9af9ca2e2ceb643064745269dcec (patch) | |
tree | cf8f3e6ed33c7dc5e98baa6a530683749ae40e51 /src/BlockEntities | |
parent | Merge pull request #2737 from Gargaj/snowgolem (diff) | |
download | cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar.gz cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar.bz2 cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar.lz cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar.xz cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.tar.zst cuberite-f9008a4860dc9af9ca2e2ceb643064745269dcec.zip |
Diffstat (limited to 'src/BlockEntities')
29 files changed, 52 insertions, 33 deletions
diff --git a/src/BlockEntities/BeaconEntity.cpp b/src/BlockEntities/BeaconEntity.cpp index a0de281ba..6eb42384d 100644 --- a/src/BlockEntities/BeaconEntity.cpp +++ b/src/BlockEntities/BeaconEntity.cpp @@ -282,7 +282,7 @@ bool cBeaconEntity::Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) -void cBeaconEntity::UsedBy(cPlayer * a_Player) +bool cBeaconEntity::UsedBy(cPlayer * a_Player) { cWindow * Window = GetWindow(); if (Window == nullptr) @@ -299,6 +299,7 @@ void cBeaconEntity::UsedBy(cPlayer * a_Player) a_Player->OpenWindow(Window); } } + return true; } diff --git a/src/BlockEntities/BeaconEntity.h b/src/BlockEntities/BeaconEntity.h index 4f723c617..6ec00fd1a 100644 --- a/src/BlockEntities/BeaconEntity.h +++ b/src/BlockEntities/BeaconEntity.h @@ -31,7 +31,7 @@ public: // cBlockEntity overrides: virtual void SendTo(cClientHandle & a_Client) override; virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; /** Modify the beacon level. (It is needed to load the beacon corectly) */ void SetBeaconLevel(char a_Level) { m_BeaconLevel = a_Level; } diff --git a/src/BlockEntities/BlockEntity.h b/src/BlockEntities/BlockEntity.h index f1c470ec3..183210e25 100644 --- a/src/BlockEntities/BlockEntity.h +++ b/src/BlockEntities/BlockEntity.h @@ -102,8 +102,9 @@ public: // tolua_end - /** Called when a player uses this entity; should open the UI window */ - virtual void UsedBy( cPlayer * a_Player) = 0; + /** 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() */ diff --git a/src/BlockEntities/BrewingstandEntity.cpp b/src/BlockEntities/BrewingstandEntity.cpp index 38403a59c..3c42bee0e 100644 --- a/src/BlockEntities/BrewingstandEntity.cpp +++ b/src/BlockEntities/BrewingstandEntity.cpp @@ -51,7 +51,7 @@ cBrewingstandEntity::~cBrewingstandEntity() -void cBrewingstandEntity::UsedBy(cPlayer * a_Player) +bool cBrewingstandEntity::UsedBy(cPlayer * a_Player) { cWindow * Window = GetWindow(); if (Window == nullptr) @@ -76,6 +76,7 @@ void cBrewingstandEntity::UsedBy(cPlayer * a_Player) { BroadcastProgress(0, 0); } + return true; } diff --git a/src/BlockEntities/BrewingstandEntity.h b/src/BlockEntities/BrewingstandEntity.h index a895c4bde..89f836e71 100644 --- a/src/BlockEntities/BrewingstandEntity.h +++ b/src/BlockEntities/BrewingstandEntity.h @@ -44,7 +44,7 @@ public: // cBlockEntity overrides: virtual void SendTo(cClientHandle & a_Client) override; virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void Destroy() override { m_IsDestroyed = true; diff --git a/src/BlockEntities/ChestEntity.cpp b/src/BlockEntities/ChestEntity.cpp index 21baac977..bd6c19a2a 100644 --- a/src/BlockEntities/ChestEntity.cpp +++ b/src/BlockEntities/ChestEntity.cpp @@ -45,7 +45,7 @@ void cChestEntity::SendTo(cClientHandle & a_Client) -void cChestEntity::UsedBy(cPlayer * a_Player) +bool cChestEntity::UsedBy(cPlayer * a_Player) { // If the window is not created, open it anew: cWindow * Window = GetWindow(); @@ -71,6 +71,7 @@ void cChestEntity::UsedBy(cPlayer * a_Player) int ChunkX, ChunkZ; cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); m_World->MarkChunkDirty(ChunkX, ChunkZ, true); + return true; } diff --git a/src/BlockEntities/ChestEntity.h b/src/BlockEntities/ChestEntity.h index 6eb72fc77..72e1c20e8 100644 --- a/src/BlockEntities/ChestEntity.h +++ b/src/BlockEntities/ChestEntity.h @@ -37,7 +37,7 @@ public: // cBlockEntity overrides: virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; /** Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. */ diff --git a/src/BlockEntities/CommandBlockEntity.cpp b/src/BlockEntities/CommandBlockEntity.cpp index 13c2637dc..2709201f4 100644 --- a/src/BlockEntities/CommandBlockEntity.cpp +++ b/src/BlockEntities/CommandBlockEntity.cpp @@ -29,10 +29,11 @@ cCommandBlockEntity::cCommandBlockEntity(int a_X, int a_Y, int a_Z, cWorld * a_W -void cCommandBlockEntity::UsedBy(cPlayer * a_Player) +bool cCommandBlockEntity::UsedBy(cPlayer * a_Player) { // Nothing to do UNUSED(a_Player); + return true; } diff --git a/src/BlockEntities/CommandBlockEntity.h b/src/BlockEntities/CommandBlockEntity.h index 959a40681..0f93ff916 100644 --- a/src/BlockEntities/CommandBlockEntity.h +++ b/src/BlockEntities/CommandBlockEntity.h @@ -35,7 +35,7 @@ public: virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; void SetLastOutput(const AString & a_LastOut); diff --git a/src/BlockEntities/DropSpenserEntity.cpp b/src/BlockEntities/DropSpenserEntity.cpp index 211bf8662..6a8b5311e 100644 --- a/src/BlockEntities/DropSpenserEntity.cpp +++ b/src/BlockEntities/DropSpenserEntity.cpp @@ -154,7 +154,7 @@ void cDropSpenserEntity::SendTo(cClientHandle & a_Client) -void cDropSpenserEntity::UsedBy(cPlayer * a_Player) +bool cDropSpenserEntity::UsedBy(cPlayer * a_Player) { cWindow * Window = GetWindow(); if (Window == nullptr) @@ -170,6 +170,7 @@ void cDropSpenserEntity::UsedBy(cPlayer * a_Player) a_Player->OpenWindow(Window); } } + return true; } diff --git a/src/BlockEntities/DropSpenserEntity.h b/src/BlockEntities/DropSpenserEntity.h index 5cdb59b28..9e73269fb 100644 --- a/src/BlockEntities/DropSpenserEntity.h +++ b/src/BlockEntities/DropSpenserEntity.h @@ -49,7 +49,7 @@ public: // cBlockEntity overrides: virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; // tolua_begin diff --git a/src/BlockEntities/EnderChestEntity.cpp b/src/BlockEntities/EnderChestEntity.cpp index 8783c1610..74ca8d8ad 100644 --- a/src/BlockEntities/EnderChestEntity.cpp +++ b/src/BlockEntities/EnderChestEntity.cpp @@ -33,13 +33,13 @@ cEnderChestEntity::~cEnderChestEntity() -void cEnderChestEntity::UsedBy(cPlayer * a_Player) +bool cEnderChestEntity::UsedBy(cPlayer * a_Player) { // TODO: cats are an obstruction if ((GetPosY() < cChunkDef::Height - 1) && !cBlockInfo::IsTransparent(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ()))) { // Obstruction, don't open - return; + return false; } // If the window is not created, open it anew: cWindow * Window = GetWindow(); @@ -57,6 +57,7 @@ void cEnderChestEntity::UsedBy(cPlayer * a_Player) a_Player->OpenWindow(Window); } } + return true; } diff --git a/src/BlockEntities/EnderChestEntity.h b/src/BlockEntities/EnderChestEntity.h index af59cf170..ba207aaa8 100644 --- a/src/BlockEntities/EnderChestEntity.h +++ b/src/BlockEntities/EnderChestEntity.h @@ -24,7 +24,7 @@ public: virtual ~cEnderChestEntity(); // cBlockEntity overrides: - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override { UNUSED(a_Client); } static void LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid); diff --git a/src/BlockEntities/FlowerPotEntity.cpp b/src/BlockEntities/FlowerPotEntity.cpp index 64b7edd02..30c7c0745 100644 --- a/src/BlockEntities/FlowerPotEntity.cpp +++ b/src/BlockEntities/FlowerPotEntity.cpp @@ -22,11 +22,11 @@ cFlowerPotEntity::cFlowerPotEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWo // It don't do anything when 'used' -void cFlowerPotEntity::UsedBy(cPlayer * a_Player) +bool cFlowerPotEntity::UsedBy(cPlayer * a_Player) { if (IsItemInPot()) { - return; + return false; } cItem SelectedItem = a_Player->GetInventory().GetEquippedItem(); @@ -39,6 +39,7 @@ void cFlowerPotEntity::UsedBy(cPlayer * a_Player) } m_World->BroadcastBlockEntity(m_PosX, m_PosY, m_PosZ, a_Player->GetClientHandle()); } + return true; } diff --git a/src/BlockEntities/FlowerPotEntity.h b/src/BlockEntities/FlowerPotEntity.h index a4246bb7d..c7aa02c15 100644 --- a/src/BlockEntities/FlowerPotEntity.h +++ b/src/BlockEntities/FlowerPotEntity.h @@ -46,7 +46,8 @@ public: // tolua_end - virtual void UsedBy(cPlayer * a_Player) override; + /** Called when the player is using the entity; returns true if it was a successful use, return false if it should be treated as a normal block */ + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; static bool IsFlower(short m_ItemType, short m_ItemData); diff --git a/src/BlockEntities/FurnaceEntity.cpp b/src/BlockEntities/FurnaceEntity.cpp index d1588160d..7aeede620 100644 --- a/src/BlockEntities/FurnaceEntity.cpp +++ b/src/BlockEntities/FurnaceEntity.cpp @@ -56,7 +56,7 @@ cFurnaceEntity::~cFurnaceEntity() -void cFurnaceEntity::UsedBy(cPlayer * a_Player) +bool cFurnaceEntity::UsedBy(cPlayer * a_Player) { cWindow * Window = GetWindow(); if (Window == nullptr) @@ -74,6 +74,7 @@ void cFurnaceEntity::UsedBy(cPlayer * a_Player) } UpdateProgressBars(true); + return true; } diff --git a/src/BlockEntities/FurnaceEntity.h b/src/BlockEntities/FurnaceEntity.h index 8734d763c..52d81353c 100644 --- a/src/BlockEntities/FurnaceEntity.h +++ b/src/BlockEntities/FurnaceEntity.h @@ -43,7 +43,7 @@ public: // cBlockEntity overrides: virtual void SendTo(cClientHandle & a_Client) override; virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void Destroy() override { m_IsDestroyed = true; diff --git a/src/BlockEntities/HopperEntity.cpp b/src/BlockEntities/HopperEntity.cpp index 33ca974d5..b57f0a638 100644 --- a/src/BlockEntities/HopperEntity.cpp +++ b/src/BlockEntities/HopperEntity.cpp @@ -80,7 +80,7 @@ void cHopperEntity::SendTo(cClientHandle & a_Client) -void cHopperEntity::UsedBy(cPlayer * a_Player) +bool cHopperEntity::UsedBy(cPlayer * a_Player) { // If the window is not created, open it anew: cWindow * Window = GetWindow(); @@ -106,6 +106,7 @@ void cHopperEntity::UsedBy(cPlayer * a_Player) int ChunkX, ChunkZ; cChunkDef::BlockToChunk(m_PosX, m_PosZ, ChunkX, ChunkZ); m_World->MarkChunkDirty(ChunkX, ChunkZ); + return true; } diff --git a/src/BlockEntities/HopperEntity.h b/src/BlockEntities/HopperEntity.h index ba0fe28f3..59645ebb7 100644 --- a/src/BlockEntities/HopperEntity.h +++ b/src/BlockEntities/HopperEntity.h @@ -49,7 +49,7 @@ protected: // cBlockEntity overrides: virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; /** Opens a new chest window for this chest. Scans for neighbors to open a double chest window, if appropriate. */ void OpenNewWindow(void); diff --git a/src/BlockEntities/JukeboxEntity.cpp b/src/BlockEntities/JukeboxEntity.cpp index 1f3f4f324..467a3a28a 100644 --- a/src/BlockEntities/JukeboxEntity.cpp +++ b/src/BlockEntities/JukeboxEntity.cpp @@ -28,11 +28,12 @@ cJukeboxEntity::~cJukeboxEntity() -void cJukeboxEntity::UsedBy(cPlayer * a_Player) +bool cJukeboxEntity::UsedBy(cPlayer * a_Player) { if (IsPlayingRecord()) { EjectRecord(); + return true; } else { @@ -40,8 +41,10 @@ void cJukeboxEntity::UsedBy(cPlayer * a_Player) if (PlayRecord(HeldItem.m_ItemType)) { a_Player->GetInventory().RemoveOneEquippedItem(); + return true; } } + return false; } diff --git a/src/BlockEntities/JukeboxEntity.h b/src/BlockEntities/JukeboxEntity.h index 000f7d87e..3724922ae 100644 --- a/src/BlockEntities/JukeboxEntity.h +++ b/src/BlockEntities/JukeboxEntity.h @@ -44,7 +44,7 @@ public: // tolua_end - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override {} private: diff --git a/src/BlockEntities/MobHeadEntity.cpp b/src/BlockEntities/MobHeadEntity.cpp index 328ade23a..3275bf7f2 100644 --- a/src/BlockEntities/MobHeadEntity.cpp +++ b/src/BlockEntities/MobHeadEntity.cpp @@ -23,9 +23,10 @@ cMobHeadEntity::cMobHeadEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld -void cMobHeadEntity::UsedBy(cPlayer * a_Player) +bool cMobHeadEntity::UsedBy(cPlayer * a_Player) { UNUSED(a_Player); + return true; } diff --git a/src/BlockEntities/MobHeadEntity.h b/src/BlockEntities/MobHeadEntity.h index b6760b40a..f25cb3a16 100644 --- a/src/BlockEntities/MobHeadEntity.h +++ b/src/BlockEntities/MobHeadEntity.h @@ -53,7 +53,7 @@ public: // tolua_end - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; private: diff --git a/src/BlockEntities/MobSpawnerEntity.cpp b/src/BlockEntities/MobSpawnerEntity.cpp index 4418dca15..7f1b88c9b 100644 --- a/src/BlockEntities/MobSpawnerEntity.cpp +++ b/src/BlockEntities/MobSpawnerEntity.cpp @@ -33,14 +33,14 @@ void cMobSpawnerEntity::SendTo(cClientHandle & a_Client) -void cMobSpawnerEntity::UsedBy(cPlayer * a_Player) +bool cMobSpawnerEntity::UsedBy(cPlayer * a_Player) { if (a_Player->GetEquippedItem().m_ItemType == E_ITEM_SPAWN_EGG) { eMonsterType MonsterType = cItemSpawnEggHandler::ItemDamageToMonsterType(a_Player->GetEquippedItem().m_ItemDamage); if (MonsterType == eMonsterType::mtInvalidType) { - return; + return false; } m_Entity = MonsterType; @@ -50,7 +50,9 @@ void cMobSpawnerEntity::UsedBy(cPlayer * a_Player) a_Player->GetInventory().RemoveOneEquippedItem(); } LOGD("Changed monster spawner at {%d, %d, %d} to type %s.", GetPosX(), GetPosY(), GetPosZ(), cMonster::MobTypeToString(MonsterType).c_str()); + return true; } + return false; } diff --git a/src/BlockEntities/MobSpawnerEntity.h b/src/BlockEntities/MobSpawnerEntity.h index b572e6657..e3bb8c634 100644 --- a/src/BlockEntities/MobSpawnerEntity.h +++ b/src/BlockEntities/MobSpawnerEntity.h @@ -28,7 +28,7 @@ public: cMobSpawnerEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World); virtual void SendTo(cClientHandle & a_Client) override; - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual bool Tick(std::chrono::milliseconds a_Dt, cChunk & a_Chunk) override; // tolua_begin diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp index 53685233b..0b110b14e 100644 --- a/src/BlockEntities/NoteEntity.cpp +++ b/src/BlockEntities/NoteEntity.cpp @@ -19,11 +19,12 @@ cNoteEntity::cNoteEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_Wo -void cNoteEntity::UsedBy(cPlayer * a_Player) +bool cNoteEntity::UsedBy(cPlayer * a_Player) { UNUSED(a_Player); IncrementPitch(); MakeSound(); + return true; } diff --git a/src/BlockEntities/NoteEntity.h b/src/BlockEntities/NoteEntity.h index eb2e23fa2..3a70ffec5 100644 --- a/src/BlockEntities/NoteEntity.h +++ b/src/BlockEntities/NoteEntity.h @@ -49,7 +49,7 @@ public: // tolua_end - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle &) override {} virtual void SetRedstonePower(bool a_Value) override diff --git a/src/BlockEntities/SignEntity.cpp b/src/BlockEntities/SignEntity.cpp index 9a2695b3f..64f42e425 100644 --- a/src/BlockEntities/SignEntity.cpp +++ b/src/BlockEntities/SignEntity.cpp @@ -22,9 +22,10 @@ cSignEntity::cSignEntity(BLOCKTYPE a_BlockType, int a_X, int a_Y, int a_Z, cWorl -void cSignEntity::UsedBy(cPlayer * a_Player) +bool cSignEntity::UsedBy(cPlayer * a_Player) { UNUSED(a_Player); + return true; } diff --git a/src/BlockEntities/SignEntity.h b/src/BlockEntities/SignEntity.h index 373f5e294..50b9d7330 100644 --- a/src/BlockEntities/SignEntity.h +++ b/src/BlockEntities/SignEntity.h @@ -43,7 +43,7 @@ public: // tolua_end - virtual void UsedBy(cPlayer * a_Player) override; + virtual bool UsedBy(cPlayer * a_Player) override; virtual void SendTo(cClientHandle & a_Client) override; private: |