Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemEmptyMap.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../Item.h"
5 
6 
7 
8 
9 
11  public cItemHandler
12 {
14 
15  static const unsigned int DEFAULT_SCALE = 0;
16 
17 public:
18 
19  using Super::Super;
20 
21 
22 
23 
24 
25  virtual bool OnItemUse(
26  cWorld * a_World,
27  cPlayer * a_Player,
28  cBlockPluginInterface & a_PluginInterface,
29  const cItem & a_HeldItem,
30  const Vector3i a_ClickedBlockPos,
31  eBlockFace a_ClickedBlockFace
32  ) const override
33  {
34  UNUSED(a_HeldItem);
35  UNUSED(a_ClickedBlockFace);
36 
37  // The map center is fixed at the central point of the 8x8 block of chunks you are standing in when you right-click it.
38 
39  const int RegionWidth = cChunkDef::Width * 8;
40 
41  int CenterX = FloorC(a_Player->GetPosX() / RegionWidth) * RegionWidth + (RegionWidth / 2);
42  int CenterZ = FloorC(a_Player->GetPosZ() / RegionWidth) * RegionWidth + (RegionWidth / 2);
43 
44  auto NewMap = a_World->GetMapManager().CreateMap(CenterX, CenterZ, DEFAULT_SCALE);
45  if (NewMap == nullptr)
46  {
47  return true;
48  }
49 
50  // Replace map in the inventory:
51  a_Player->ReplaceOneEquippedItemTossRest(cItem(E_ITEM_MAP, 1, static_cast<short>(NewMap->GetID() & 0x7fff)));
52  return true;
53  }
54 } ;
@ E_ITEM_MAP
Definition: BlockType.h:403
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
#define UNUSED
Definition: Globals.h:72
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
Definition: Globals.h:347
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld.
static const int Width
Definition: ChunkDef.h:124
double GetPosX(void) const
Definition: Entity.h:195
double GetPosZ(void) const
Definition: Entity.h:197
Definition: Player.h:29
void ReplaceOneEquippedItemTossRest(const cItem &)
Removes one item from the the current equipped item stack, and attempts to add the specified item sta...
Definition: Player.cpp:1745
Definition: Item.h:37
static const unsigned int DEFAULT_SCALE
Definition: ItemEmptyMap.h:15
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
Called when the player tries to use the item (right mouse button).
Definition: ItemEmptyMap.h:25
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
friend class cItem
Definition: ItemHandler.h:25
cMap * CreateMap(int a_CenterX, int a_CenterY, unsigned int a_Scale=3)
Creates a new map.
Definition: MapManager.cpp:74
Definition: World.h:53
cMapManager & GetMapManager(void)
Returns the associated map manager instance.
Definition: World.h:703