Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockIce.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 {
14 
15 public:
16 
18  super(a_BlockType)
19  {
20  }
21 
22 
23 
24 
25 
26  virtual cItems ConvertToPickups(NIBBLETYPE a_BlockMeta, cBlockEntity * a_BlockEntity, const cEntity * a_Digger, const cItem * a_Tool) override
27  {
28  // Only drop self when using silk-touch:
29  if (ToolHasSilkTouch(a_Tool))
30  {
31  return cItem(m_BlockType);
32  }
33  else
34  {
35  return {};
36  }
37  }
38 
39 
40 
41 
42 
43  virtual void OnBroken(
44  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
45  Vector3i a_BlockPos,
46  BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta
47  ) override
48  {
49  // If there's a solid block or a liquid underneath, convert to water, rather than air
50  if (a_BlockPos.y <= 0)
51  {
52  return;
53  }
54  auto blockTypeBelow = a_ChunkInterface.GetBlock(a_BlockPos.addedY(-1));
55  if (cBlockInfo::FullyOccupiesVoxel(blockTypeBelow) || IsBlockLiquid(blockTypeBelow))
56  {
57  a_ChunkInterface.SetBlock(a_BlockPos, E_BLOCK_WATER, 0);
58  }
59  }
60 
61 
62 
63 
64 
65  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
66  {
67  UNUSED(a_Meta);
68  return 5;
69  }
70 } ;
void SetBlock(Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Sets the block at the specified coords to the specified value.
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
cBlockIceHandler(BLOCKTYPE a_BlockType)
Definition: BlockIce.h:17
cBlockHandler(BLOCKTYPE a_BlockType)
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.
T y
Definition: Vector3.h:17
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:299
bool IsBlockLiquid(BLOCKTYPE a_BlockType)
Definition: Defines.h:484
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: BlockIce.h:26
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: BlockIce.h:65
#define UNUSED
Definition: Globals.h:152
static bool FullyOccupiesVoxel(BLOCKTYPE a_Type)
Definition: BlockInfo.h:50
BLOCKTYPE GetBlock(Vector3i a_Pos)
Byte ColourID
Definition: Globals.h:118
Definition: Entity.h:73
virtual void OnBroken(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_OldBlockType, NIBBLETYPE a_OldBlockMeta) override
Called after a block gets broken (replaced with air), either by player or by natural means...
Definition: BlockIce.h:43
Definition: Item.h:36
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:234