2014-02-14 10:38:22 -05:00
|
|
|
|
|
|
|
// ItemEmptyMap.h
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../Entities/Entity.h"
|
|
|
|
#include "../Item.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class cItemEmptyMapHandler :
|
|
|
|
public cItemHandler
|
|
|
|
{
|
|
|
|
typedef cItemHandler super;
|
2014-02-15 13:06:47 -05:00
|
|
|
|
|
|
|
static const unsigned int DEFAULT_SCALE = 0;
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-02-14 10:38:22 -05:00
|
|
|
public:
|
|
|
|
cItemEmptyMapHandler() :
|
|
|
|
super(E_ITEM_EMPTY_MAP)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
virtual bool OnItemUse(
|
|
|
|
cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
|
|
|
|
int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
|
|
|
|
) override
|
2014-02-14 10:38:22 -05:00
|
|
|
{
|
|
|
|
UNUSED(a_Item);
|
|
|
|
UNUSED(a_BlockX);
|
|
|
|
UNUSED(a_BlockZ);
|
2015-04-14 04:49:01 -04:00
|
|
|
UNUSED(a_BlockFace);
|
2014-02-14 10:38:22 -05:00
|
|
|
|
|
|
|
// The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it.
|
|
|
|
|
2014-02-27 03:06:25 -05:00
|
|
|
const int RegionWidth = cChunkDef::Width * 8;
|
2014-02-14 10:38:22 -05:00
|
|
|
|
2015-06-30 10:50:15 -04:00
|
|
|
int CenterX = FloorC(a_Player->GetPosX() / RegionWidth) * RegionWidth + (RegionWidth / 2);
|
|
|
|
int CenterZ = FloorC(a_Player->GetPosZ() / RegionWidth) * RegionWidth + (RegionWidth / 2);
|
2014-02-14 10:38:22 -05:00
|
|
|
|
2014-02-23 08:03:40 -05:00
|
|
|
cMap * NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE);
|
2014-02-17 09:27:12 -05:00
|
|
|
|
|
|
|
// Remove empty map from inventory
|
|
|
|
if (!a_Player->GetInventory().RemoveOneEquippedItem())
|
|
|
|
{
|
|
|
|
ASSERT(!"Inventory mismatch");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-10-20 16:55:07 -04:00
|
|
|
if (NewMap == nullptr)
|
2014-02-17 09:27:12 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2015-07-29 11:04:03 -04:00
|
|
|
a_Player->GetInventory().AddItem(cItem(E_ITEM_MAP, 1, static_cast<short>(NewMap->GetID() & 0x7fff)));
|
2014-02-14 10:38:22 -05:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ;
|
2015-04-14 04:49:01 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|