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"
|
2014-12-13 09:06:55 -05:00
|
|
|
#include "../UI/EnderChestWindow.h"
|
2013-12-06 19:18:58 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-01 17:12:44 -05:00
|
|
|
bool cEnderChestEntity::UsedBy(cPlayer * a_Player)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2015-07-06 12:39:02 -04:00
|
|
|
// TODO: cats are an obstruction
|
|
|
|
if ((GetPosY() < cChunkDef::Height - 1) && !cBlockInfo::IsTransparent(GetWorld()->GetBlock(GetPosX(), GetPosY() + 1, GetPosZ())))
|
|
|
|
{
|
|
|
|
// Obstruction, don't open
|
2015-12-01 17:12:44 -05:00
|
|
|
return false;
|
2015-07-06 12:39:02 -04: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
|
|
|
}
|
2015-07-06 12:39:02 -04: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
|
|
|
}
|
2015-12-01 17:12:44 -05:00
|
|
|
return true;
|
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;
|
2015-10-19 10:03:55 -04:00
|
|
|
for (auto & Node : a_Value)
|
2013-12-06 19:18:58 -05:00
|
|
|
{
|
2014-06-29 06:36:38 -04:00
|
|
|
cItem Item;
|
2015-10-19 10:03:55 -04:00
|
|
|
Item.FromJson(Node);
|
2014-06-29 06:36:38 -04:00
|
|
|
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
|
|
|
}
|