Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemBigFlower.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 #include "../BlockInfo.h"
6 
7 
8 
9 
10 
12  public cItemHandler
13 {
15 
16 public:
17 
18  using Super::Super;
19 
20  virtual bool CommitPlacement(cPlayer & a_Player, const cItem & a_HeldItem, const Vector3i a_PlacePosition, const eBlockFace a_ClickedBlockFace, const Vector3i a_CursorPosition) const override
21  {
22  // Needs at least two free blocks to build in:
23  if (a_PlacePosition.y >= (cChunkDef::Height - 1))
24  {
25  return false;
26  }
27 
28  const auto & World = *a_Player.GetWorld();
29  const auto TopPos = a_PlacePosition.addedY(1);
30  BLOCKTYPE TopType;
31  NIBBLETYPE TopMeta;
32  World.GetBlockTypeMeta(TopPos, TopType, TopMeta);
33 
34  if (!cBlockHandler::For(TopType).DoesIgnoreBuildCollision(World, a_HeldItem, TopPos, TopMeta, a_ClickedBlockFace, false))
35  {
36  return false;
37  }
38 
39  return a_Player.PlaceBlocks(
40  {
41  { a_PlacePosition, E_BLOCK_BIG_FLOWER, static_cast<NIBBLETYPE>(a_HeldItem.m_ItemDamage & 0x07) },
43  });
44  }
45 };
@ E_META_BIG_FLOWER_TOP
Definition: BlockType.h:562
@ E_BLOCK_BIG_FLOWER
Definition: BlockType.h:194
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:44
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:41
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
Utilities to allow casting a cWorld to one of its interfaces without including World....
Definition: OpaqueWorld.h:13
static const cBlockHandler & For(BLOCKTYPE a_BlockType)
static const int Height
Definition: ChunkDef.h:125
cWorld * GetWorld(void) const
Definition: Entity.h:190
Definition: Player.h:29
bool PlaceBlocks(std::initializer_list< sSetBlock > a_Blocks)
Calls the block placement hooks and places the blocks in the world.
Definition: Player.cpp:2449
Definition: Item.h:37
short m_ItemDamage
Definition: Item.h:165
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.
Definition: ItemBigFlower.h:20
constexpr cItemHandler(int a_ItemType)
Definition: ItemHandler.h:37
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:314
T y
Definition: Vector3.h:17