Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemSign.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../World.h"
6 #include "../Blocks/BlockSignPost.h"
7 #include "../Blocks/BlockWallSign.h"
8 #include "../ClientHandle.h"
9 
10 
11 
12 
13 
15  public cItemHandler
16 {
18 public:
19  cItemSignHandler(int a_ItemType) :
20  super(a_ItemType)
21  {
22  }
23 
24 
25  virtual bool OnPlayerPlace(
26  cWorld & a_World, cPlayer & a_Player, const cItem & a_EquippedItem,
27  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
28  int a_CursorX, int a_CursorY, int a_CursorZ
29  ) override
30  {
31  // Check if placing on something ignoring build collision to edit the correct sign later on:
32  BLOCKTYPE ClickedBlock;
33  NIBBLETYPE ClickedBlockMeta;
34  a_World.GetBlockTypeMeta(a_BlockX, a_BlockY, a_BlockZ, ClickedBlock, ClickedBlockMeta);
35  cChunkInterface ChunkInterface(a_World.GetChunkMap());
36  bool isReplacingClickedBlock = BlockHandler(ClickedBlock)->DoesIgnoreBuildCollision(ChunkInterface, { a_BlockX, a_BlockY, a_BlockZ }, a_Player, ClickedBlockMeta);
37 
38  // If the regular placement doesn't work, do no further processing:
39  if (!super::OnPlayerPlace(a_World, a_Player, a_EquippedItem, a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_CursorX, a_CursorY, a_CursorZ))
40  {
41  return false;
42  }
43 
44  // Use isReplacingClickedBlock to make sure we will edit the right sign:
45  if (!isReplacingClickedBlock)
46  {
47  AddFaceDirection(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace);
48  }
49 
50  // After successfully placing the sign, open the sign editor for the player:
51  a_Player.GetClientHandle()->SendEditSign(a_BlockX, a_BlockY, a_BlockZ);
52  return true;
53  }
54 
55 
56  virtual bool IsPlaceable(void) override
57  {
58  return true;
59  }
60 
61 
63  cWorld * a_World, cPlayer * a_Player,
64  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
65  int a_CursorX, int a_CursorY, int a_CursorZ,
66  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
67  ) override
68  {
69  if (a_BlockFace == BLOCK_FACE_TOP)
70  {
71  a_BlockMeta = cBlockSignPostHandler::RotationToMetaData(a_Player->GetYaw());
72  a_BlockType = E_BLOCK_SIGN_POST;
73  }
74  else
75  {
76  a_BlockMeta = cBlockWallSignHandler::DirectionToMetaData(a_BlockFace);
77  a_BlockType = E_BLOCK_WALLSIGN;
78  }
79  return true;
80  }
81 } ;
82 
83 
84 
85 
virtual bool IsPlaceable(void) override
Blocks simply get placed.
Definition: ItemSign.h:56
virtual bool DoesIgnoreBuildCollision(cChunkInterface &ChunkInterface, Vector3i a_Pos, cPlayer &a_Player, NIBBLETYPE a_Meta)
Checks if the player can build "inside" this block.
cItemSignHandler(int a_ItemType)
Definition: ItemSign.h:19
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
static NIBBLETYPE RotationToMetaData(double a_Rotation)
Definition: BlockSignPost.h:46
Definition: Player.h:27
virtual bool OnPlayerPlace(cWorld &a_World, cPlayer &a_Player, const cItem &a_EquippedItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
Called when the player tries to place the item (right mouse button, IsPlaceable() == true)...
Definition: ItemSign.h:25
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
virtual bool GetPlacementBlockTypeMeta(cWorld *a_World, cPlayer *a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called when the player right-clicks with this item and IsPlaceable() == true, and OnPlayerPlace() is ...
Definition: ItemSign.h:62
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse=false)
Definition: Defines.h:859
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Retrieves the block type and meta at the specified coords.
Definition: World.cpp:1909
Definition: World.h:65
virtual bool OnPlayerPlace(cWorld &a_World, cPlayer &a_Player, const cItem &a_EquippedItem, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ)
Called when the player tries to place the item (right mouse button, IsPlaceable() == true)...
cItemHandler super
Definition: ItemSign.h:17
cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockInfo.h:159
double GetYaw(void) const
Definition: Entity.h:209
cChunkMap * GetChunkMap(void)
Definition: World.h:1044
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
static NIBBLETYPE DirectionToMetaData(eBlockFace a_Direction)
Definition: BlockWallSign.h:66
Definition: Item.h:36