diff options
author | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-12-07 01:18:58 +0100 |
---|---|---|
committer | Tiger Wang <ziwei.tiger@hotmail.co.uk> | 2013-12-07 01:18:58 +0100 |
commit | 347e80bdd88f894394373745859f405dc82c1819 (patch) | |
tree | 82bf1b2163cbf7c59bf3c0181583982f34912aca /src/UI | |
parent | Renamed animation function (diff) | |
download | cuberite-347e80bdd88f894394373745859f405dc82c1819.tar cuberite-347e80bdd88f894394373745859f405dc82c1819.tar.gz cuberite-347e80bdd88f894394373745859f405dc82c1819.tar.bz2 cuberite-347e80bdd88f894394373745859f405dc82c1819.tar.lz cuberite-347e80bdd88f894394373745859f405dc82c1819.tar.xz cuberite-347e80bdd88f894394373745859f405dc82c1819.tar.zst cuberite-347e80bdd88f894394373745859f405dc82c1819.zip |
Diffstat (limited to 'src/UI')
-rw-r--r-- | src/UI/SlotArea.cpp | 33 | ||||
-rw-r--r-- | src/UI/SlotArea.h | 18 | ||||
-rw-r--r-- | src/UI/Window.cpp | 38 | ||||
-rw-r--r-- | src/UI/Window.h | 17 |
4 files changed, 106 insertions, 0 deletions
diff --git a/src/UI/SlotArea.cpp b/src/UI/SlotArea.cpp index 7fd7cd996..e743f4bb3 100644 --- a/src/UI/SlotArea.cpp +++ b/src/UI/SlotArea.cpp @@ -8,6 +8,7 @@ #include "../Entities/Player.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/DropSpenserEntity.h" +#include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/FurnaceEntity.h" #include "../Items/ItemHandler.h" #include "Window.h" @@ -557,6 +558,38 @@ cCraftingRecipe & cSlotAreaCrafting::GetRecipeForPlayer(cPlayer & a_Player) /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cSlotAreaEnderChest: + +cSlotAreaEnderChest::cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow) : + cSlotArea(27, a_ParentWindow), + m_EnderChest(a_EnderChest) +{ +} + + + + + +const cItem * cSlotAreaEnderChest::GetSlot(int a_SlotNum, cPlayer & a_Player) const +{ + // a_SlotNum ranges from 0 to 26, use that to index the chest entity's inventory directly: + return &(m_EnderChest->GetSlot(a_SlotNum)); +} + + + + + +void cSlotAreaEnderChest::SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) +{ + m_EnderChest->SetSlot(a_SlotNum, a_Item); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cSlotAreaFurnace: cSlotAreaFurnace::cSlotAreaFurnace(cFurnaceEntity * a_Furnace, cWindow & a_ParentWindow) : diff --git a/src/UI/SlotArea.h b/src/UI/SlotArea.h index b1944d901..d31c87e0c 100644 --- a/src/UI/SlotArea.h +++ b/src/UI/SlotArea.h @@ -16,6 +16,7 @@ class cWindow; class cPlayer; class cChestEntity; class cDropSpenserEntity; +class cEnderChestEntity; class cFurnaceEntity; class cCraftingRecipe; @@ -286,6 +287,23 @@ protected: +class cSlotAreaEnderChest : + public cSlotArea +{ +public: + cSlotAreaEnderChest(cEnderChestEntity * a_EnderChest, cWindow & a_ParentWindow); + + virtual const cItem * GetSlot(int a_SlotNum, cPlayer & a_Player) const override; + virtual void SetSlot(int a_SlotNum, cPlayer & a_Player, const cItem & a_Item) override; + +protected: + cEnderChestEntity * m_EnderChest; +}; + + + + + class cSlotAreaFurnace : public cSlotArea, public cItemGrid::cListener diff --git a/src/UI/Window.cpp b/src/UI/Window.cpp index f5c62692f..5ca31fa3e 100644 --- a/src/UI/Window.cpp +++ b/src/UI/Window.cpp @@ -11,6 +11,7 @@ #include "../Items/ItemHandler.h" #include "../BlockEntities/ChestEntity.h" #include "../BlockEntities/DropSpenserEntity.h" +#include "../BlockEntities/EnderChestEntity.h" #include "../BlockEntities/HopperEntity.h" @@ -854,6 +855,43 @@ cDropSpenserWindow::cDropSpenserWindow(int a_BlockX, int a_BlockY, int a_BlockZ, /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// cEnderChestWindow: + +cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest) : + cWindow(wtChest, "Ender Chest"), + m_World(a_EnderChest->GetWorld()), + m_BlockX(a_EnderChest->GetPosX()), + m_BlockY(a_EnderChest->GetPosY()), + m_BlockZ(a_EnderChest->GetPosZ()) +{ + m_SlotAreas.push_back(new cSlotAreaEnderChest(a_EnderChest, *this)); + m_SlotAreas.push_back(new cSlotAreaInventory(*this)); + m_SlotAreas.push_back(new cSlotAreaHotBar(*this)); + + // Play the opening sound: + m_World->BroadcastSoundEffect("random.chestopen", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); + + // Send out the chest-open packet: + m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 1, E_BLOCK_ENDER_CHEST); +} + + + + + +cEnderChestWindow::~cEnderChestWindow() +{ + // Send out the chest-close packet: + m_World->BroadcastBlockAction(m_BlockX, m_BlockY, m_BlockZ, 1, 0, E_BLOCK_ENDER_CHEST); + + m_World->BroadcastSoundEffect("random.chestclosed", m_BlockX * 8, m_BlockY * 8, m_BlockZ * 8, 1, 1); +} + + + + + +/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // cHopperWindow: cHopperWindow::cHopperWindow(int a_BlockX, int a_BlockY, int a_BlockZ, cHopperEntity * a_Hopper) : diff --git a/src/UI/Window.h b/src/UI/Window.h index c44b900d7..030182888 100644 --- a/src/UI/Window.h +++ b/src/UI/Window.h @@ -20,6 +20,7 @@ class cWindowOwner; class cClientHandle; class cChestEntity; class cDropSpenserEntity; +class cEnderChestEntity; class cFurnaceEntity; class cHopperEntity; class cSlotArea; @@ -283,6 +284,22 @@ protected: +class cEnderChestWindow : + public cWindow +{ +public: + cEnderChestWindow(cEnderChestEntity * a_EnderChest); + ~cEnderChestWindow(); + +protected: + cWorld * m_World; + int m_BlockX, m_BlockY, m_BlockZ; // Position of the enderchest, for the window-close packet +}; + + + + + class cInventoryWindow : public cWindow { |