Cuberite
A lightweight, fast and extensible game server for Minecraft
PoweredRailHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 
6 
7 
9 {
13  {
14  switch (a_Meta & 0x7)
15  {
16  case E_META_RAIL_ZM_ZP: return { 0, 0, 1 };
17  case E_META_RAIL_XM_XP: return { 1, 0, 0 };
18  case E_META_RAIL_ASCEND_XP: return { 1, 1, 0 };
19  case E_META_RAIL_ASCEND_XM: return { 1, 1, 0 };
20  case E_META_RAIL_ASCEND_ZM: return { 0, 1, 1 };
21  case E_META_RAIL_ASCEND_ZP: return { 0, 1, 1 };
22  default:
23  {
24  ASSERT(!"Impossible rail meta! wat wat wat");
25  return { 0, 0, 0 };
26  }
27  }
28  }
29 
30  static PowerLevel GetPowerDeliveredToPosition(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
31  {
32  UNUSED(a_QueryBlockType);
33 
34  const auto Meta = a_Chunk.GetMeta(a_Position);
35  const auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(Meta);
36  if (((Offset + a_Position) == a_QueryPosition) || ((-Offset + a_Position) == a_QueryPosition))
37  {
38  const auto Power = DataForChunk(a_Chunk).GetCachedPowerData(a_Position);
39  return (Power <= 7) ? 0 : (Power - 1);
40  }
41  return 0;
42  }
43 
44  static void Update(cChunk & a_Chunk, cChunk & CurrentlyTickingChunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
45  {
46  // LOGD("Evaluating tracky the rail (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
47 
48  switch (a_BlockType)
49  {
51  {
52  /*
53  if ((m_Chunk->GetMeta(a_RelBlockX, a_RelBlockY, a_RelBlockZ) & 0x08) == 0x08)
54  {
55  SetAllDirsAsPowered(a_RelBlockX, a_RelBlockY, a_RelBlockZ, a_MyType);
56  }
57  */
58  return;
59  }
62  {
63  const auto Offset = GetPoweredRailAdjacentXZCoordinateOffset(a_Meta);
64  if (Power != DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, Power))
65  {
66  a_Chunk.SetMeta(a_Position, (Power == 0) ? (a_Meta & 0x07) : (a_Meta | 0x08));
67 
68  UpdateAdjustedRelative(a_Chunk, CurrentlyTickingChunk, a_Position, Offset);
69  UpdateAdjustedRelative(a_Chunk, CurrentlyTickingChunk, a_Position, -Offset);
70  }
71 
72  return;
73  }
74  default:
75  {
76  ASSERT(!"Unhandled type of rail in passed to rail handler!");
77  }
78  }
79  }
80 
81  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
82  {
83  UNUSED(a_Chunk);
84  UNUSED(a_Meta);
85 
86  if ((a_BlockType == E_BLOCK_POWERED_RAIL) || (a_BlockType == E_BLOCK_ACTIVATOR_RAIL))
87  {
88  InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
89  }
90  }
91 };
@ E_META_RAIL_ASCEND_ZM
Definition: BlockType.h:785
@ E_META_RAIL_ZM_ZP
Definition: BlockType.h:781
@ E_META_RAIL_ASCEND_XM
Definition: BlockType.h:784
@ E_META_RAIL_ASCEND_XP
Definition: BlockType.h:783
@ E_META_RAIL_XM_XP
Definition: BlockType.h:782
@ E_META_RAIL_ASCEND_ZP
Definition: BlockType.h:786
@ E_BLOCK_ACTIVATOR_RAIL
Definition: BlockType.h:174
@ E_BLOCK_POWERED_RAIL
Definition: BlockType.h:37
@ E_BLOCK_DETECTOR_RAIL
Definition: BlockType.h:38
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)
void UpdateAdjustedRelative(const cChunk &a_Chunk, const cChunk &a_TickingChunk, const Vector3i a_Position, const Vector3i a_Offset)
unsigned char PowerLevel
unsigned char Power(const BlockState Block)
static Vector3i GetPoweredRailAdjacentXZCoordinateOffset(NIBBLETYPE a_Meta)
Get the offset along which the rail faces.
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 &CurrentlyTickingChunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
static void ForValidSourcePositions(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback &Callback)
Definition: Chunk.h:36
NIBBLETYPE GetMeta(int a_RelX, int a_RelY, int a_RelZ) const
Definition: Chunk.h:279
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
Definition: Chunk.h:286