2014-02-14 10:38:22 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "../Item.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-13 12:38:06 -04:00
|
|
|
class cItemEmptyMapHandler:
|
2014-02-14 10:38:22 -05:00
|
|
|
public cItemHandler
|
|
|
|
{
|
2020-04-13 12:38:06 -04:00
|
|
|
using Super = cItemHandler;
|
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:
|
2020-04-13 12:38:06 -04:00
|
|
|
|
|
|
|
cItemEmptyMapHandler():
|
|
|
|
Super(E_ITEM_EMPTY_MAP)
|
2014-02-14 10:38:22 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
|
|
|
|
|
2015-04-14 04:49:01 -04:00
|
|
|
virtual bool OnItemUse(
|
2020-04-21 16:19:22 -04:00
|
|
|
cWorld * a_World,
|
|
|
|
cPlayer * a_Player,
|
|
|
|
cBlockPluginInterface & a_PluginInterface,
|
|
|
|
const cItem & a_HeldItem,
|
|
|
|
const Vector3i a_ClickedBlockPos,
|
|
|
|
eBlockFace a_ClickedBlockFace
|
2015-04-14 04:49:01 -04:00
|
|
|
) override
|
2014-02-14 10:38:22 -05:00
|
|
|
{
|
2020-04-21 16:19:22 -04:00
|
|
|
UNUSED(a_HeldItem);
|
|
|
|
UNUSED(a_ClickedBlockFace);
|
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
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
auto NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE);
|
2014-10-20 16:55:07 -04:00
|
|
|
if (NewMap == nullptr)
|
2014-02-17 09:27:12 -05:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-04-21 16:19:22 -04:00
|
|
|
// Replace map in the inventory:
|
|
|
|
a_Player->ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MAP, 1, static_cast<short>(NewMap->GetID() & 0x7fff)));
|
2014-02-14 10:38:22 -05:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
} ;
|