Cuberite
A lightweight, fast and extensible game server for Minecraft
PistonHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../../Blocks/BlockPiston.h"
5 
6 
7 
8 
9 
10 namespace PistonHandler
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 pisty the piston (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
26 
27  const bool ShouldBeExtended = Power != 0;
28  if (ShouldBeExtended == cBlockPistonHandler::IsExtended(a_Meta))
29  {
30  return;
31  }
32 
33  a_Position = cChunkDef::RelativeToAbsolute(a_Position, a_Chunk.GetPos());
34 
35  if (ShouldBeExtended)
36  {
37  cBlockPistonHandler::ExtendPiston(a_Position, *a_Chunk.GetWorld());
38  }
39  else
40  {
41  cBlockPistonHandler::RetractPiston(a_Position, *a_Chunk.GetWorld());
42  }
43 
44  // It is necessary to delay after a signal to prevent an infinite loop (#3168)
45  // However, this delay is already present: as a side effect of the implementation of piston animation in Blocks\BlockPiston.cpp
46  }
47 
48  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
49  {
50  UNUSED(a_Chunk);
51  UNUSED(a_BlockType);
52 
54  const auto FrontOffset = AddFaceDirection(Vector3i(), Face);
55 
56  for (const auto & Offset : RelativeAdjacents)
57  {
58  if (Offset != FrontOffset)
59  {
60  Callback(a_Position + Offset);
61  }
62  }
63 
64  // Consider indirect power:
65  Callback.CheckIndirectPower();
66  }
67 };
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
void AddFaceDirection(int &a_BlockX, int &a_BlockY, int &a_BlockZ, eBlockFace a_BlockFace, bool a_bInverse)
Modifies the specified coords so that they point to the block adjacent to the one specified through i...
Definition: Defines.cpp:378
#define UNUSED
Definition: Globals.h:72
constexpr std::array< Vector3i, 6 > RelativeAdjacents
unsigned char PowerLevel
Vector3< int > Vector3i
Definition: Vector3.h:487
unsigned char Power(const BlockState Block)
static void Update(cChunk &a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
Definition: PistonHandler.h:23
static PowerLevel GetPowerDeliveredToPosition(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
Definition: PistonHandler.h:12
static void ForValidSourcePositions(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback &Callback)
Definition: PistonHandler.h:48
static void RetractPiston(Vector3i a_BlockPos, cWorld &a_World)
static void ExtendPiston(Vector3i a_BlockPos, cWorld &a_World)
Definition: BlockPiston.cpp:44
static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData)
Definition: BlockPiston.h:27
static bool IsExtended(NIBBLETYPE a_PistonMeta)
Returns true if the piston (with the specified meta) is extended.
Definition: BlockPiston.h:52
Definition: Chunk.h:36
cChunkCoords GetPos() const
Definition: Chunk.h:133
cWorld * GetWorld(void) const
Definition: Chunk.h:135
static Vector3i RelativeToAbsolute(Vector3i a_RelBlockPosition, cChunkCoords a_ChunkCoords)
Converts relative block coordinates into absolute coordinates with a known chunk location.
Definition: ChunkDef.h:174
void CheckIndirectPower()
Callback invoked for blocks supporting quasiconnectivity.