Cuberite
A lightweight, fast and extensible game server for Minecraft
RedstoneLampHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 
6 
7 
9 {
10  static bool IsOn(BLOCKTYPE a_BlockType)
11  {
12  return (a_BlockType == E_BLOCK_REDSTONE_LAMP_ON);
13  }
14 
15  static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
16  {
17  return 0;
18  }
19 
20  static void Update(cChunk & a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
21  {
22  // LOGD("Evaluating lamp (%i %i %i)", a_Position.x, a_Position.y, a_Position.z);
23 
24  if (Power > 0)
25  {
26  if (!IsOn(a_BlockType))
27  {
28  a_Chunk.FastSetBlock(a_Position, E_BLOCK_REDSTONE_LAMP_ON, 0);
29  }
30  }
31  else
32  {
33  if (IsOn(a_BlockType))
34  {
35  a_Chunk.FastSetBlock(a_Position, E_BLOCK_REDSTONE_LAMP_OFF, 0);
36  }
37  }
38  }
39 
40  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
41  {
42  UNUSED(a_Chunk);
43  UNUSED(a_Meta);
44  UNUSED(a_BlockType);
45  InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
46  }
47 };
@ E_BLOCK_REDSTONE_LAMP_OFF
Definition: BlockType.h:138
@ E_BLOCK_REDSTONE_LAMP_ON
Definition: BlockType.h:139
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 UNUSED
Definition: Globals.h:72
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 PowerLevel GetPowerDeliveredToPosition(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
static void Update(cChunk &a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
static bool IsOn(BLOCKTYPE a_BlockType)
Definition: Chunk.h:36
void FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, BLOCKTYPE a_BlockMeta)
Definition: Chunk.cpp:1296