Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemBed.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../World.h"
6 #include "../Blocks/BlockBed.h"
7 
8 
9 
10 
11 
13  public cItemHandler
14 {
15 public:
16  cItemBedHandler(int a_ItemType) :
17  cItemHandler(a_ItemType)
18  {
19  }
20 
21 
22  virtual bool IsPlaceable(void) override
23  {
24  return true;
25  }
26 
27 
28  virtual bool GetBlocksToPlace(
29  cWorld & a_World, cPlayer & a_Player, const cItem & a_EquippedItem,
30  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
31  int a_CursorX, int a_CursorY, int a_CursorZ,
32  sSetBlockVector & a_BlocksToPlace
33  ) override
34  {
35  // Can only be placed on the floor:
36  if (a_BlockFace != BLOCK_FACE_TOP)
37  {
38  return false;
39  }
40 
41  // The "foot" block:
43  a_BlocksToPlace.emplace_back(a_BlockX, a_BlockY, a_BlockZ, E_BLOCK_BED, BlockMeta);
44 
45  // Check if there is empty space for the "head" block:
46  // (Vanilla only allows beds to be placed into air)
48  if (a_World.GetBlock(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z) != E_BLOCK_AIR)
49  {
50  return false;
51  }
52  a_BlocksToPlace.emplace_back(a_BlockX + Direction.x, a_BlockY, a_BlockZ + Direction.z, E_BLOCK_BED, BlockMeta | 0x08);
53  return true;
54  }
55 } ;
56 
57 
58 
59 
virtual bool IsPlaceable(void) override
Blocks simply get placed.
Definition: ItemBed.h:22
BLOCKTYPE GetBlock(Vector3i a_BlockPos)
Returns the block type at the specified position.
Definition: World.h:416
T x
Definition: Vector3.h:17
Definition: Player.h:27
static Vector3i MetaDataToDirection(NIBBLETYPE a_MetaData)
Definition: BlockBed.h:62
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
virtual bool GetBlocksToPlace(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, sSetBlockVector &a_BlocksToPlace) override
Called from OnPlayerPlace() to determine the blocks that the current placement operation should set...
Definition: ItemBed.h:28
T z
Definition: Vector3.h:17
Direction
Definition: World.h:65
cItemBedHandler(int a_ItemType)
Definition: ItemBed.h:16
double GetYaw(void) const
Definition: Entity.h:209
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
static NIBBLETYPE RotationToMetaData(double a_Rotation)
Definition: BlockBed.h:45
Definition: Item.h:36
std::vector< sSetBlock > sSetBlockVector
Definition: ChunkDef.h:564