1
0
Fork 0
cuberite-2a/src/Items/ItemEmptyMap.h

55 lines
1.1 KiB
C
Raw Normal View History

2014-02-14 15:38:22 +00:00
#pragma once
#include "../Item.h"
class cItemEmptyMapHandler final:
2014-02-14 15:38:22 +00:00
public cItemHandler
{
2020-04-13 16:38:06 +00:00
using Super = cItemHandler;
2014-02-15 18:06:47 +00:00
static const unsigned int DEFAULT_SCALE = 0;
2016-02-05 21:45:45 +00:00
2014-02-14 15:38:22 +00:00
public:
2020-04-13 16:38:06 +00:00
using Super::Super;
2014-02-14 15:38:22 +00:00
virtual bool OnItemUse(
cWorld * a_World,
cPlayer * a_Player,
cBlockPluginInterface & a_PluginInterface,
const cItem & a_HeldItem,
const Vector3i a_ClickedBlockPos,
eBlockFace a_ClickedBlockFace
) const override
2014-02-14 15:38:22 +00:00
{
UNUSED(a_HeldItem);
UNUSED(a_ClickedBlockFace);
2014-02-14 15:38:22 +00: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.
const int RegionWidth = cChunkDef::Width * 8;
2014-02-14 15:38:22 +00:00
2015-06-30 14:50:15 +00:00
int CenterX = FloorC(a_Player->GetPosX() / RegionWidth) * RegionWidth + (RegionWidth / 2);
int CenterZ = FloorC(a_Player->GetPosZ() / RegionWidth) * RegionWidth + (RegionWidth / 2);
2014-02-14 15:38:22 +00:00
auto NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE);
2014-10-20 20:55:07 +00:00
if (NewMap == nullptr)
2014-02-17 14:27:12 +00:00
{
return true;
}
// Replace map in the inventory:
a_Player->ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MAP, 1, static_cast<short>(NewMap->GetID() & 0x7fff)));
2014-02-14 15:38:22 +00:00
return true;
}
} ;