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 
11  public cBlockHandler
12 {
13 public:
14  enum
15  {
16  FullBlockMeta = 7 // Meta value of a full-height snow block
17  };
18 
20  : cBlockHandler(a_BlockType)
21  {
22  }
23 
25  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
26  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
27  int a_CursorX, int a_CursorY, int a_CursorZ,
28  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
29  ) override
30  {
31  a_BlockType = m_BlockType;
32 
33  BLOCKTYPE BlockBeforePlacement;
34  NIBBLETYPE MetaBeforePlacement;
35  a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY, a_BlockZ}, BlockBeforePlacement, MetaBeforePlacement);
36 
37  if ((BlockBeforePlacement == E_BLOCK_SNOW) && (MetaBeforePlacement < FullBlockMeta))
38  {
39  // Only increment if:
40  // - A snow block was already there (not first time placement) AND
41  // - Height is smaller than the maximum possible
42  a_BlockMeta = MetaBeforePlacement + 1;
43  return true;
44  }
45 
46  // First time placement, check placement is valid
47  a_BlockMeta = 0;
48 
49  BLOCKTYPE BlockBelow;
50  NIBBLETYPE MetaBelow;
51  return (
52  (a_BlockY > 0) &&
53  a_ChunkInterface.GetBlockTypeMeta({a_BlockX, a_BlockY - 1, a_BlockZ}, BlockBelow, MetaBelow) &&
54  CanBeOn(BlockBelow, MetaBelow)
55  );
56  }
57 
58  virtual bool DoesIgnoreBuildCollision(cChunkInterface & a_ChunkInterface, Vector3i a_Pos, cPlayer & a_Player, NIBBLETYPE a_Meta) override
59  {
60  if ((a_Player.GetEquippedItem().m_ItemType == E_BLOCK_SNOW) && (a_Meta < FullBlockMeta))
61  {
62  return true; // If a player is holding a (thin) snow block and it's size can be increased, return collision ignored
63  }
64 
65  if (a_Meta == 0)
66  {
67  return true; // If at normal snowfall height (lowest), we ignore collision
68  }
69 
70  return false;
71  }
72 
73 
74 
75 
76 
77  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
78  {
79  // No drop unless dug up with a shovel
80  if ((a_Tool == nullptr) || !ItemCategory::IsShovel(a_Tool->m_ItemType))
81  {
82  return {};
83  }
84 
85  if (ToolHasSilkTouch(a_Tool))
86  {
87  return cItem(m_BlockType, 1, 0);
88  }
89  else
90  {
91  // Drop as many snowballs as there were "layers" of snow:
92  return cItem(E_ITEM_SNOWBALL, 1 + (a_BlockMeta & 0x07), 0);
93  }
94  }
95 
96 
97 
98 
99 
100  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
101  {
102  if (a_RelY > 0)
103  {
104  BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
105  NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ);
106 
107  return CanBeOn(BlockBelow, MetaBelow);
108  }
109 
110  return false;
111  }
112 
113  virtual bool DoesDropOnUnsuitable(void) override
114  {
115  return false;
116  }
117 
118  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
119  {
120  UNUSED(a_Meta);
121  return 14;
122  }
123 
124  virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override
125  {
126  return a_Position.y < (cBlockInfo::GetBlockHeight(a_BlockType) * (a_BlockMeta & 0x07));
127  }
128 
129 private:
130 
132  static bool CanBeOn(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
133  {
134  // If block below is snowable, or it is a thin slow block and is a full thin snow block, say yay
135  return (
136  cBlockInfo::IsSnowable(a_BlockType) ||
137  (
138  (a_BlockType == E_BLOCK_SNOW) &&
139  (a_BlockMeta == FullBlockMeta)
140  )
141  );
142  }
143 
144 } ;
145 
146 
147 
148 
static float GetBlockHeight(BLOCKTYPE a_Type)
Definition: BlockInfo.h:52
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:132
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
bool GetBlockTypeMeta(Vector3i a_Pos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity *a_BlockEntity, const cEntity *a_Digger, const cItem *a_Tool) override
Returns the pickups that would result if the block was mined by a_Digger using a_Tool.
Definition: BlockSnow.h:77
const cItem & GetEquippedItem(void) const
Definition: Player.h:142
Definition: Player.h:27
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk) override
Checks if the block can stay at the specified relative coords in the chunk.
Definition: BlockSnow.h:100
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
static bool ToolHasSilkTouch(const cItem *a_Tool)
Returns true if the specified tool is valid and has a non-zero silk-touch enchantment.
Definition: Chunk.h:49
virtual bool IsInsideBlock(Vector3d a_Position, const BLOCKTYPE a_BlockType, const NIBBLETYPE a_BlockMeta) override
Tests if a_Position is inside the block where a_Position is relative to the origin of the block Note ...
Definition: BlockSnow.h:124
T y
Definition: Vector3.h:17
cBlockSnowHandler(BLOCKTYPE a_BlockType)
Definition: BlockSnow.h:19
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
Definition: BlockSnow.h:118
static bool IsSnowable(BLOCKTYPE a_Type)
Definition: BlockInfo.h:40
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:380
virtual bool DoesDropOnUnsuitable(void) override
Returns if this block drops if it gets destroyed by an unsuitable situation.
Definition: BlockSnow.h:113
#define UNUSED
Definition: Globals.h:152
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, 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 before a block is placed into a world.
Definition: BlockSnow.h:24
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
BLOCKTYPE GetBlock(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:177
Byte ColourID
Definition: Globals.h:118
bool IsShovel(short a_ItemID)
Definition: Defines.h:1065
Definition: Entity.h:73
short m_ItemType
Definition: Item.h:209
virtual bool DoesIgnoreBuildCollision(cChunkInterface &a_ChunkInterface, Vector3i a_Pos, cPlayer &a_Player, NIBBLETYPE a_Meta) override
Checks if the player can build "inside" this block.
Definition: BlockSnow.h:58
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234