Cuberite
A lightweight, fast and extensible game server for Minecraft
CommandBlockHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../../BlockEntities/CommandBlockEntity.h"
5 
6 
7 
8 
9 
11 {
12  static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
13  {
14  UNUSED(a_Chunk);
15  UNUSED(a_Position);
16  UNUSED(a_BlockType);
17  UNUSED(a_QueryPosition);
18  UNUSED(a_QueryBlockType);
19  UNUSED(IsLinked);
20  return 0;
21  }
22 
23  static void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
24  {
25  // LOGD("Evaluating commander the cmdblck (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
26 
27  const auto Previous = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, Power);
28  if ((Previous != 0) || (Power == 0))
29  {
30  // If we're already powered or received an update of no power, don't activate
31  return;
32  }
33 
34  a_Chunk.DoWithBlockEntityAt(a_Position, [](cBlockEntity & a_BlockEntity)
35  {
36  ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_COMMAND_BLOCK);
37 
38  static_cast<cCommandBlockEntity &>(a_BlockEntity).Activate();
39  return false;
40  });
41  }
42 
43  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
44  {
45  UNUSED(a_Chunk);
46  UNUSED(a_BlockType);
47  UNUSED(a_Meta);
48  InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
49  }
50 };
@ E_BLOCK_COMMAND_BLOCK
Definition: BlockType.h:152
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
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
auto & DataForChunk(const cChunk &a_Chunk)
constexpr std::array< Vector3i, 6 > RelativeAdjacents
void InvokeForAdjustedRelatives(ForEachSourceCallback &Callback, const Vector3i Position, const ArrayType &Relative)
unsigned char PowerLevel
unsigned char Power(const BlockState Block)
static void ForValidSourcePositions(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback &Callback)
static void Update(cChunk &a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
static PowerLevel GetPowerDeliveredToPosition(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
BLOCKTYPE GetBlockType() const
Definition: BlockEntity.h:97
Definition: Chunk.h:36
bool DoWithBlockEntityAt(Vector3i a_Position, cBlockEntityCallback a_Callback)
Calls the callback for the block entity at the specified coords; returns false if there's no block en...
Definition: Chunk.cpp:1737