Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockConcretePowder.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 
17  using Super::Super;
18 
19 private:
20 
21  virtual void OnPlaced(
22  cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface,
23  Vector3i a_BlockPos,
24  BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta
25  ) const override
26  {
27  OnNeighborChanged(a_ChunkInterface, a_BlockPos, BLOCK_FACE_NONE);
28  }
29 
30  virtual void OnNeighborChanged(cChunkInterface & a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const override
31  {
32  a_ChunkInterface.DoWithChunkAt(a_BlockPos, [&](cChunk & a_Chunk) { CheckSoaked(cChunkDef::AbsoluteToRelative(a_BlockPos), a_Chunk); return true; });
33  }
34 
36  static void CheckSoaked(Vector3i a_Rel, cChunk & a_Chunk)
37  {
38  const auto & WaterCheck = cSimulator::AdjacentOffsets;
39  const bool ShouldSoak = std::any_of(WaterCheck.cbegin(), WaterCheck.cend(), [a_Rel, & a_Chunk](Vector3i a_Offset)
40  {
41  BLOCKTYPE NeighborType;
42  return (
43  a_Chunk.UnboundedRelGetBlockType(a_Rel.x + a_Offset.x, a_Rel.y + a_Offset.y, a_Rel.z + a_Offset.z, NeighborType)
44  && IsBlockWater(NeighborType)
45  );
46  });
47 
48  if (ShouldSoak)
49  {
50  NIBBLETYPE BlockMeta;
51  BlockMeta = a_Chunk.GetMeta(a_Rel.x, a_Rel.y, a_Rel.z);
52  a_Chunk.SetBlock(a_Rel, E_BLOCK_CONCRETE, BlockMeta);
53  }
54  }
55 
56  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
57  {
58  switch (a_Meta)
59  {
60  case E_META_CONCRETE_POWDER_WHITE: return 8;
61  case E_META_CONCRETE_POWDER_ORANGE: return 15;
62  case E_META_CONCRETE_POWDER_MAGENTA: return 16;
63  case E_META_CONCRETE_POWDER_LIGHTBLUE: return 17;
64  case E_META_CONCRETE_POWDER_YELLOW: return 18;
65  case E_META_CONCRETE_POWDER_LIGHTGREEN: return 19;
66  case E_META_CONCRETE_POWDER_PINK: return 20;
67  case E_META_CONCRETE_POWDER_GRAY: return 21;
68  case E_META_CONCRETE_POWDER_LIGHTGRAY: return 22;
69  case E_META_CONCRETE_POWDER_CYAN: return 23;
70  case E_META_CONCRETE_POWDER_PURPLE: return 24;
71  case E_META_CONCRETE_POWDER_BLUE: return 25;
72  case E_META_CONCRETE_POWDER_BROWN: return 26;
73  case E_META_CONCRETE_POWDER_GREEN: return 27;
74  case E_META_CONCRETE_POWDER_RED: return 28;
75  case E_META_CONCRETE_POWDER_BLACK: return 29;
76  default:
77  {
78  ASSERT(!"Unhandled meta in concrete powder handler!");
79  return 0;
80  }
81  }
82  }
83 };
@ E_META_CONCRETE_POWDER_LIGHTGRAY
Definition: BlockType.h:629
@ E_META_CONCRETE_POWDER_LIGHTBLUE
Definition: BlockType.h:624
@ E_META_CONCRETE_POWDER_YELLOW
Definition: BlockType.h:625
@ E_META_CONCRETE_POWDER_BLUE
Definition: BlockType.h:632
@ E_META_CONCRETE_POWDER_PURPLE
Definition: BlockType.h:631
@ E_META_CONCRETE_POWDER_PINK
Definition: BlockType.h:627
@ E_META_CONCRETE_POWDER_LIGHTGREEN
Definition: BlockType.h:626
@ E_META_CONCRETE_POWDER_BROWN
Definition: BlockType.h:633
@ E_META_CONCRETE_POWDER_BLACK
Definition: BlockType.h:636
@ E_META_CONCRETE_POWDER_MAGENTA
Definition: BlockType.h:623
@ E_META_CONCRETE_POWDER_GRAY
Definition: BlockType.h:628
@ E_META_CONCRETE_POWDER_GREEN
Definition: BlockType.h:634
@ E_META_CONCRETE_POWDER_ORANGE
Definition: BlockType.h:622
@ E_META_CONCRETE_POWDER_RED
Definition: BlockType.h:635
@ E_META_CONCRETE_POWDER_WHITE
Definition: BlockType.h:621
@ E_META_CONCRETE_POWDER_CYAN
Definition: BlockType.h:630
@ E_BLOCK_CONCRETE
Definition: BlockType.h:270
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_NONE
Definition: Defines.h:39
Byte ColourID
Definition: Globals.h:162
#define ASSERT(x)
Definition: Globals.h:276
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...
virtual void OnNeighborChanged(cChunkInterface &a_ChunkInterface, Vector3i a_BlockPos, eBlockFace a_WhichNeighbor) const override
Called when a direct neighbor of this block has been changed.
static void CheckSoaked(Vector3i a_Rel, cChunk &a_Chunk)
Check blocks above and around to see if they are water.
virtual void OnPlaced(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, Vector3i a_BlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) const override
Called by cWorld::SetBlock() after the block has been set.
constexpr cBlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockHandler.h:29
bool DoWithChunkAt(Vector3i a_BlockPos, cFunctionRef< bool(cChunk &)> a_Callback)
Definition: Chunk.h:36
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:279
void SetBlock(Vector3i a_RelBlockPos, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Definition: Chunk.cpp:1263
static void AbsoluteToRelative(int &a_X, int &a_Y, int &a_Z, int &a_ChunkX, int &a_ChunkZ)
Converts absolute block coords into relative (chunk + block) coords:
Definition: ChunkDef.h:147
static constexpr std::array< Vector3i, 6 > AdjacentOffsets
Contains offsets for direct adjacents of any position.
Definition: Simulator.h:34
T x
Definition: Vector3.h:17
T y
Definition: Vector3.h:17
T z
Definition: Vector3.h:17