Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockSnow.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 
6 
7 
8 
9 
10 class cBlockSnowHandler final :
11  public cBlockHandler
12 {
14 
15 public:
16 
17  using Super::Super;
18 
19 private:
20 
21  enum
22  {
23  FullBlockMeta = 7 // Meta value of a full-height snow block.
24  };
25 
26 
27  virtual bool DoesIgnoreBuildCollision(const cWorld & a_World, const cItem & a_HeldItem, const Vector3i a_Position, const NIBBLETYPE a_Meta, const eBlockFace a_ClickedBlockFace, const bool a_ClickedDirectly) const override
28  {
29  if (a_Meta == 0)
30  {
31  return true; // If at normal snowfall height (lowest), we ignore collision.
32  }
33 
34  // Special case if a player is holding a (thin) snow block and its size can be increased:
35  if ((a_HeldItem.m_ItemType == E_BLOCK_SNOW) && (a_Meta < FullBlockMeta))
36  {
37  return !a_ClickedDirectly || (a_ClickedBlockFace == BLOCK_FACE_YP); // If clicked an adjacent block, or clicked YP directly, we ignore collision.
38  }
39 
40  return false;
41  }
42 
43 
44 
45 
46 
47  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
48  {
49  // No drop unless dug up with a shovel:
50  if ((a_Tool == nullptr) || !ItemCategory::IsShovel(a_Tool->m_ItemType))
51  {
52  return {};
53  }
54 
55  if (ToolHasSilkTouch(a_Tool))
56  {
57  return cItem(m_BlockType, 1, 0);
58  }
59  else
60  {
61  // Drop as many snowballs as there were "layers" of snow:
62  return cItem(E_ITEM_SNOWBALL, 1 + (a_BlockMeta & 0x07), 0);
63  }
64  }
65 
66 
67 
68 
69 
70  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
71  {
72  if (a_Position.y <= 0)
73  {
74  return false;
75  }
76  auto BelowPos = a_Position.addedY(-1);
77  auto BlockBelow = a_Chunk.GetBlock(BelowPos);
78  auto MetaBelow = a_Chunk.GetMeta(BelowPos);
79  return CanBeOn(BlockBelow, MetaBelow);
80  }
81 
82 
83 
84 
85 
86  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
87  {
88  UNUSED(a_Meta);
89  return 14;
90  }
91 
92 
93 
94 
95 
96  virtual bool IsInsideBlock(const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const override
97  {
98  return a_RelPosition.y < (cBlockInfo::GetBlockHeight(m_BlockType) * (a_BlockMeta & 0x07));
99  }
100 
101 
102 private:
103 
105  static bool CanBeOn(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
106  {
107  // If block below is snowable, or it is a thin snow block and is a full thin snow block, say yay:
108  return (
109  cBlockInfo::IsSnowable(a_BlockType) ||
110  (
111  (a_BlockType == E_BLOCK_SNOW) &&
112  (a_BlockMeta == FullBlockMeta)
113  )
114  );
115  }
116 
117 } ;
118 
119 
120 
121 
@ E_BLOCK_SNOW
Definition: BlockType.h:92
@ E_ITEM_SNOWBALL
Definition: BlockType.h:376
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
@ BLOCK_FACE_YP
Definition: Defines.h:43
Byte ColourID
Definition: Globals.h:162
#define UNUSED
Definition: Globals.h:72
bool IsShovel(short a_ItemType)
Definition: Defines.cpp:486
static float GetBlockHeight(BLOCKTYPE Block)
Block's height.
Definition: BlockInfo.cpp:1153
static bool IsSnowable(BLOCKTYPE Block)
Definition: BlockInfo.cpp:879
static bool ToolHasSilkTouch(const cItem *a_Tool)
Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
const BLOCKTYPE m_BlockType
Definition: BlockHandler.h:205
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...
Definition: BlockSnow.h:86
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.
Definition: BlockSnow.h:47
static bool CanBeOn(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Returns true if snow can be placed on top of a block with the given type and meta.
Definition: BlockSnow.h:105
virtual bool DoesIgnoreBuildCollision(const cWorld &a_World, const cItem &a_HeldItem, const Vector3i a_Position, const NIBBLETYPE a_Meta, const eBlockFace a_ClickedBlockFace, const bool a_ClickedDirectly) const override
Checks if the player can build "inside" this block.
Definition: BlockSnow.h:27
virtual bool CanBeAt(const cChunk &a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockSnow.h:70
virtual bool IsInsideBlock(const Vector3d a_RelPosition, const NIBBLETYPE a_BlockMeta) const override
Tests if a_RelPosition is inside the block, where a_RelPosition is relative to the origin of the bloc...
Definition: BlockSnow.h:96
Definition: Chunk.h:36
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:279
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:146
Definition: Item.h:37
short m_ItemType
Definition: Item.h:163
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
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
Definition: World.h:53