Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockEnchantingTable.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "../Item.h"
6 #include "../UI/EnchantingWindow.h"
7 #include "../BlockEntities/EnchantingTableEntity.h"
8 #include "../Entities/Player.h"
9 
10 
11 
12 
13 
15  public cBlockHandler
16 {
18 
19 public:
20 
21  using Super::Super;
22 
23 private:
24 
25  virtual bool OnUse(
26  cChunkInterface & a_ChunkInterface,
27  cWorldInterface & a_WorldInterface,
28  cPlayer & a_Player,
29  const Vector3i a_BlockPos,
30  eBlockFace a_BlockFace,
31  const Vector3i a_CursorPos
32  ) const override
33  {
34  AString WindowName = "Enchant";
35  a_WorldInterface.DoWithBlockEntityAt(a_BlockPos, [&WindowName](cBlockEntity & a_Entity)
36  {
38 
39  const auto & EnchantingTable = static_cast<cEnchantingTableEntity &>(a_Entity);
40  const auto & CustomName = EnchantingTable.GetCustomName();
41  if (!CustomName.empty())
42  {
43  WindowName = CustomName;
44  }
45 
46  return false;
47  });
48 
49  cWindow * Window = new cEnchantingWindow(a_BlockPos, std::move(WindowName));
50  a_Player.OpenWindow(*Window);
51 
52  return true;
53  }
54 
55 
56  virtual bool IsUseable(void) const override
57  {
58  return true;
59  }
60 
61 
62  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
63  {
64  // Drops handled by the block entity:
65  return {};
66  }
67 
68 
69  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
70  {
71  UNUSED(a_Meta);
72  return 29;
73  }
74 };
@ E_BLOCK_ENCHANTMENT_TABLE
Definition: BlockType.h:131
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
Byte ColourID
Definition: Globals.h:162
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
std::string AString
Definition: StringUtils.h:11
BLOCKTYPE GetBlockType() const
Definition: BlockEntity.h:97
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
virtual bool IsUseable(void) const override
Called to check whether this block supports a rclk action.
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
Called when the user right clicks the block and the block is useable.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
virtual bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback)=0
Calls the callback for the block entity at the specified coords; returns false if there's no block en...
Definition: Player.h:29
void OpenWindow(cWindow &a_Window)
Opens the specified window; closes the current one first using CloseWindow()
Definition: Player.cpp:1123
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
Represents a UI window.
Definition: Window.h:54