Cuberite
A lightweight, fast and extensible game server for Minecraft
HopperHandler.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "../../BlockEntities/HopperEntity.h"
5 
6 
7 
8 
9 
10 namespace HopperHandler
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 holey the hopper (%d %d %d)", a_Position.x, a_Position.y, a_Position.z);
26 
27  const bool ShouldBeLocked = Power != 0;
28  const bool PreviouslyLocked = (a_Meta & 0x8) == 0x8;
29 
30  if (ShouldBeLocked == PreviouslyLocked)
31  {
32  return;
33  }
34 
35  if (ShouldBeLocked)
36  {
37  a_Chunk.SetMeta(a_Position, a_Meta | 0x8);
38  }
39  else
40  {
41  a_Chunk.SetMeta(a_Position, a_Meta & ~0x8);
42  }
43 
44  a_Chunk.DoWithBlockEntityAt(a_Position, [ShouldBeLocked](cBlockEntity & a_BlockEntity)
45  {
46  ASSERT(a_BlockEntity.GetBlockType() == E_BLOCK_HOPPER);
47 
48  static_cast<cHopperEntity &>(a_BlockEntity).SetLocked(ShouldBeLocked);
49  return false;
50  });
51  }
52 
53  static void ForValidSourcePositions(const cChunk & a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, ForEachSourceCallback & Callback)
54  {
55  UNUSED(a_Chunk);
56  UNUSED(a_BlockType);
57  UNUSED(a_Meta);
58  InvokeForAdjustedRelatives(Callback, a_Position, RelativeAdjacents);
59  }
60 };
@ E_BLOCK_HOPPER
Definition: BlockType.h:171
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
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)
Definition: HopperHandler.h:53
static PowerLevel GetPowerDeliveredToPosition(const cChunk &a_Chunk, Vector3i a_Position, BLOCKTYPE a_BlockType, Vector3i a_QueryPosition, BLOCKTYPE a_QueryBlockType, bool IsLinked)
Definition: HopperHandler.h:12
static void Update(cChunk &a_Chunk, cChunk &, Vector3i a_Position, BLOCKTYPE a_BlockType, NIBBLETYPE a_Meta, const PowerLevel Power)
Definition: HopperHandler.h:23
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
void SetMeta(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE a_Meta)
Definition: Chunk.h:286