Cuberite
A lightweight, fast and extensible game server for Minecraft
TrappedChestHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../../BlockEntities/ChestEntity.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_BlockType);
15  UNUSED(a_QueryPosition);
16  UNUSED(a_QueryBlockType);
17  UNUSED(IsLinked);
18 
19  return DataForChunk(a_Chunk).GetCachedPowerData(a_Position);
20  }
21 
22  static unsigned char GetPowerLevel(cChunk & a_Chunk, Vector3i a_Position)
23  {
24  int NumberOfPlayers = 0;
25  a_Chunk.DoWithBlockEntityAt(a_Position, [&NumberOfPlayers](cBlockEntity & a_BlockEntity)
26  {
27  ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_TRAPPED_CHEST);
28 
29  NumberOfPlayers = static_cast<cChestEntity &>(a_BlockEntity).GetNumberOfPlayers();
30  return false;
31  });
32 
33  return static_cast<unsigned char>(std::min(NumberOfPlayers, 15));
34  }
35 
36  static void Update(cChunk & a_Chunk, cChunk & CurrentlyTicking, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
37  {
38  // LOGD("Evaluating tricky the trapped chest (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
39 
40  const auto PowerLevel = GetPowerLevel(a_Chunk, a_Position);
41  const auto PreviousPower = DataForChunk(a_Chunk).ExchangeUpdateOncePowerData(a_Position, PowerLevel);
42 
43  if (PowerLevel != PreviousPower)
44  {
45  UpdateAdjustedRelatives(a_Chunk, CurrentlyTicking, a_Position, RelativeAdjacents);
46  }
47  }
48 
49  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
50  {
51  UNUSED(a_Chunk);
52  UNUSED(a_Position);
53  UNUSED(a_BlockType);
54  UNUSED(a_Meta);
55  UNUSED(Callback);
56  }
57 };
@ E_BLOCK_TRAPPED_CHEST
Definition: BlockType.h:161
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 UpdateAdjustedRelatives(const cChunk &a_Chunk, const cChunk &a_TickingChunk, const Vector3i a_Position, const ArrayType &a_Relative)
unsigned char PowerLevel
unsigned char Power(const BlockState Block)
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 &CurrentlyTicking, 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)
static unsigned char GetPowerLevel(cChunk &a_Chunk, Vector3i a_Position)
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