1
0
Fork 0
cuberite-2a/src/UI/EnderChestWindow.cpp

79 lines
1.6 KiB
C++
Raw Normal View History

2015-03-10 18:40:53 +00:00
// EnderChestWindow.cpp
// Representing the UI window for the enderchest block
#include "Globals.h"
#include "../World.h"
#include "EnderChestWindow.h"
#include "SlotArea.h"
cEnderChestWindow::cEnderChestWindow(cEnderChestEntity * a_EnderChest):
2015-03-10 18:40:53 +00:00
cWindow(wtChest, "Ender Chest"),
m_World(a_EnderChest->GetWorld()),
m_BlockPos(a_EnderChest->GetPos())
2015-03-10 18:40:53 +00:00
{
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:
2015-05-24 11:56:56 +00:00
m_World->BroadcastSoundEffect(
2017-02-15 05:05:24 +00:00
"block.enderchest.open",
m_BlockPos,
2015-05-28 11:29:26 +00:00
1,
1
);
2015-03-10 18:40:53 +00:00
// Send out the chest-open packet:
m_World->BroadcastBlockAction(m_BlockPos, 1, 1, E_BLOCK_ENDER_CHEST);
2015-03-10 18:40:53 +00:00
}
cEnderChestWindow::~cEnderChestWindow()
{
// Send out the chest-close packet:
m_World->BroadcastBlockAction(m_BlockPos, 1, 0, E_BLOCK_ENDER_CHEST);
2015-03-10 18:40:53 +00:00
// Play the closing sound
2015-05-24 11:56:56 +00:00
m_World->BroadcastSoundEffect(
2017-02-15 05:05:24 +00:00
"block.enderchest.close",
m_BlockPos,
2015-05-28 11:29:26 +00:00
1, 1
);
2015-03-10 18:40:53 +00:00
}
void cEnderChestWindow::DistributeStack(cItem & a_ItemStack, int a_Slot, cPlayer & a_Player, cSlotArea * a_ClickedArea, bool a_ShouldApply)
{
cSlotAreas AreasInOrder;
if (a_ClickedArea == m_SlotAreas[0])
{
// Chest Area
AreasInOrder.push_back(m_SlotAreas[2]); /* Hotbar */
AreasInOrder.push_back(m_SlotAreas[1]); /* Inventory */
2020-04-13 16:38:06 +00:00
Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, true);
2015-03-10 18:40:53 +00:00
}
else
{
// Hotbar or Inventory
AreasInOrder.push_back(m_SlotAreas[0]); /* Chest */
2020-04-13 16:38:06 +00:00
Super::DistributeStackToAreas(a_ItemStack, a_Player, AreasInOrder, a_ShouldApply, false);
2015-03-10 18:40:53 +00:00
}
}