Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemPainting.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../World.h"
6 #include "../Entities/Player.h"
7 #include "../Entities/Painting.h"
8 
9 
10 
11 
12 
14  public cItemHandler
15 {
16 public:
17  cItemPaintingHandler(int a_ItemType)
18  : cItemHandler(a_ItemType)
19  {
20  }
21 
22 
23 
24  virtual bool OnItemUse(
25  cWorld * a_World, cPlayer * a_Player, cBlockPluginInterface & a_PluginInterface, const cItem & a_Item,
26  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace
27  ) override
28  {
29  if ((a_BlockFace == BLOCK_FACE_NONE) || (a_BlockFace == BLOCK_FACE_YM) || (a_BlockFace == BLOCK_FACE_YP))
30  {
31  // Paintings can't be flatly placed
32  return false;
33  }
34 
35  AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace); // Make sure block that will be occupied is free
36  BLOCKTYPE Block = a_World->GetBlock(a_BlockX, a_BlockY, a_BlockZ);
37 
38  if (Block == E_BLOCK_AIR)
39  {
40  static const struct // Define all the possible painting titles
41  {
42  AString Title;
43  } gPaintingTitlesList[] =
44  {
45  { "Kebab" },
46  { "Aztec" },
47  { "Alban" },
48  { "Aztec2" },
49  { "Bomb" },
50  { "Plant" },
51  { "Wasteland" },
52  { "Wanderer" },
53  { "Graham" },
54  { "Pool" },
55  { "Courbet" },
56  { "Sunset" },
57  { "Sea" },
58  { "Creebet" },
59  { "Match" },
60  { "Bust" },
61  { "Stage" },
62  { "Void" },
63  { "SkullAndRoses" },
64  { "Wither" },
65  { "Fighters" },
66  { "Skeleton" },
67  { "DonkeyKong" },
68  { "Pointer" },
69  { "Pigscene" },
70  { "BurningSkull" }
71  };
72 
73  auto Painting = cpp14::make_unique<cPainting>(gPaintingTitlesList[a_World->GetTickRandomNumber(ARRAYCOUNT(gPaintingTitlesList) - 1)].Title, a_BlockFace, Vector3i{a_BlockX, a_BlockY, a_BlockZ});
74  auto PaintingPtr = Painting.get();
75  if (!PaintingPtr->Initialize(std::move(Painting), *a_World))
76  {
77  return false;
78  }
79 
80  if (!a_Player->IsGameModeCreative())
81  {
82  a_Player->GetInventory().RemoveOneEquippedItem();
83  }
84 
85  return true;
86 
87  }
88  return false;
89  }
90 };
91 
92 
93 
94 
BLOCKTYPE GetBlock(Vector3i a_BlockPos)
Returns the block type at the specified position.
Definition: World.h:416
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
bool RemoveOneEquippedItem(void)
Removes one item out of the currently equipped item stack, returns true if successful, false if empty-handed.
Definition: Inventory.cpp:207
Definition: Player.h:27
int GetTickRandomNumber(int a_Range)
Returns a random number in range [0 .
Definition: World.cpp:3271
This interface is used to decouple block handlers from the cPluginManager dependency through cWorld...
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
Definition: Defines.h:859
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
Called when the player tries to use the item (right mouse button).
Definition: ItemPainting.h:24
Definition: World.h:65
cItemPaintingHandler(int a_ItemType)
Definition: ItemPainting.h:17
std::string AString
Definition: StringUtils.h:13
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
bool IsGameModeCreative(void) const
Returns true if the player is in Creative mode, either explicitly, or by inheriting from current worl...
Definition: Player.cpp:1260
cInventory & GetInventory(void)
Definition: Player.h:136
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
Definition: Globals.h:290
Definition: Item.h:36