2013-12-06 19:18:58 -05:00
|
|
|
|
|
|
|
#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
|
|
|
|
|
|
|
|
#include "EnderChestEntity.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
#include "../Entities/Player.h"
|
|
|
|
#include "../UI/Window.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cEnderChestEntity::cEnderChestEntity(int a_BlockX, int a_BlockY, int a_BlockZ, cWorld * a_World) :
|
2014-09-27 14:19:28 -04:00
|
|
|
super(E_BLOCK_ENDER_CHEST, a_BlockX, a_BlockY, a_BlockZ, a_World),
|
|
|
|
cBlockEntityWindowOwner(this)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cEnderChestEntity::~cEnderChestEntity()
|
|
|
|
{
|
|
|
|
cWindow * Window = GetWindow();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Window != nullptr)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
|
|
|
Window->OwnerDestroyed();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 06:36:38 -04:00
|
|
|
void cEnderChestEntity::UsedBy(cPlayer * a_Player)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
// If the window is not created, open it anew:
|
|
|
|
cWindow * Window = GetWindow();
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Window == nullptr)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
OpenNewWindow();
|
|
|
|
Window = GetWindow();
|
2013-12-06 19:18:58 -05:00
|
|
|
}
|
2014-06-29 06:36:38 -04:00
|
|
|
|
|
|
|
// Open the window for the player:
|
2014-10-20 16:55:07 -04:00
|
|
|
if (Window != nullptr)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
if (a_Player->GetWindow() != Window)
|
|
|
|
{
|
|
|
|
a_Player->OpenWindow(Window);
|
|
|
|
}
|
2013-12-06 19:18:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 06:36:38 -04:00
|
|
|
void cEnderChestEntity::OpenNewWindow()
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
OpenWindow(new cEnderChestWindow(this));
|
2013-12-06 19:18:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 06:36:38 -04:00
|
|
|
void cEnderChestEntity::LoadFromJson(const Json::Value & a_Value, cItemGrid & a_Grid)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
int SlotIdx = 0;
|
|
|
|
for (Json::Value::iterator itr = a_Value.begin(); itr != a_Value.end(); ++itr)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
cItem Item;
|
|
|
|
Item.FromJson(*itr);
|
|
|
|
a_Grid.SetSlot(SlotIdx, Item);
|
|
|
|
SlotIdx++;
|
2013-12-06 19:18:58 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-29 06:36:38 -04:00
|
|
|
void cEnderChestEntity::SaveToJson(Json::Value & a_Value, const cItemGrid & a_Grid)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
for (int i = 0; i < a_Grid.GetNumSlots(); i++)
|
|
|
|
{
|
|
|
|
Json::Value Slot;
|
|
|
|
a_Grid.GetSlot(i).GetJson(Slot);
|
|
|
|
a_Value.append(Slot);
|
|
|
|
}
|
2013-12-06 19:18:58 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|