Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemEnchantingTable.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../BlockEntities/EnchantingTableEntity.h"
6 #include "../World.h"
7 
8 
9 
10 
11 
13  public cItemHandler
14 {
16 
17 public:
18 
19  using Super::Super;
20 
21 private:
22 
23  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
24  {
25  if (!Super::CommitPlacement(a_Player, a_HeldItem, a_PlacePosition, a_ClickedBlockFace, a_CursorPosition))
26  {
27  return false;
28  }
29 
30  if (a_HeldItem.IsCustomNameEmpty())
31  {
32  return true;
33  }
34 
35  a_Player.GetWorld()->DoWithBlockEntityAt(a_PlacePosition, [&a_HeldItem](cBlockEntity & a_BlockEntity)
36  {
37  ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_ENCHANTMENT_TABLE);
38 
39  static_cast<cEnchantingTableEntity &>(a_BlockEntity).SetCustomName(a_HeldItem.m_CustomName);
40  return false;
41  });
42 
43  return true;
44  }
45 
46 
47  virtual bool IsPlaceable(void) const override
48  {
49  return true;
50  }
51 } ;
@ E_BLOCK_ENCHANTMENT_TABLE
Definition: BlockType.h:131
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
#define ASSERT(x)
Definition: Globals.h:276
BLOCKTYPE GetBlockType() const
Definition: BlockEntity.h:97
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
Definition: Item.h:37
bool IsCustomNameEmpty(void) const
Definition: Item.h:101
AString m_CustomName
Definition: Item.h:167
virtual bool IsPlaceable(void) const override
Blocks simply get placed.
virtual bool CommitPlacement(cPlayer &a_Player, const cItem &a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
Performs the actual placement of this placeable item.
virtual bool CommitPlacement(cPlayer &a_Player, const cItem &a_HeldItem, Vector3i a_PlacePosition, eBlockFace a_ClickedBlockFace, Vector3i a_CursorPosition) const
Performs the actual placement of this placeable item.
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
virtual bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback) override
Calls the callback for the block entity at the specified coords; returns false if there's no block en...
Definition: World.cpp:1420