Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockRedstoneRepeater.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "BlockHandler.h"
5 #include "Mixins.h"
6 #include "ChunkInterface.h"
7 #include "BlockSlab.h"
8 #include "../Chunk.h"
9 
10 
11 
12 
13 
15  public cClearMetaOnDrop<cMetaRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03, true>>
16 {
18 
19 public:
20 
22  super(a_BlockType)
23  {
24  }
25 
27  cChunkInterface & a_ChunkInterface, cPlayer & a_Player,
28  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
29  int a_CursorX, int a_CursorY, int a_CursorZ,
30  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
31  ) override
32  {
33  a_BlockType = m_BlockType;
34  a_BlockMeta = RepeaterRotationToMetaData(a_Player.GetYaw());
35  return true;
36  }
37 
38  virtual bool OnUse(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
39  {
40  a_ChunkInterface.SetBlockMeta(a_BlockX, a_BlockY, a_BlockZ, ((a_ChunkInterface.GetBlockMeta({a_BlockX, a_BlockY, a_BlockZ}) + 0x04) & 0x0f));
41  return true;
42  }
43 
44  virtual void OnCancelRightClick(cChunkInterface & a_ChunkInterface, cWorldInterface & a_WorldInterface, cPlayer & a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
45  {
46  UNUSED(a_ChunkInterface);
47  a_WorldInterface.SendBlockTo(a_BlockX, a_BlockY, a_BlockZ, a_Player);
48  }
49 
50  virtual bool IsUseable(void) override
51  {
52  return true;
53  }
54 
55  virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
56  {
57  if (a_RelY <= 0)
58  {
59  return false;
60  }
61 
62  BLOCKTYPE BelowBlock;
63  NIBBLETYPE BelowBlockMeta;
64  a_Chunk.GetBlockTypeMeta(a_RelX, a_RelY - 1, a_RelZ, BelowBlock, BelowBlockMeta);
65 
66  if (cBlockInfo::FullyOccupiesVoxel(BelowBlock))
67  {
68  return true;
69  }
70  else if (cBlockSlabHandler::IsAnySlabType(BelowBlock))
71  {
72  // Check if the slab is turned up side down
73  if ((BelowBlockMeta & 0x08) == 0x08)
74  {
75  return true;
76  }
77  }
78  return false;
79  }
80 
81  inline static NIBBLETYPE RepeaterRotationToMetaData(double a_Rotation)
82  {
83  a_Rotation += 90 + 45; // So its not aligned with axis
84  if (a_Rotation > 360)
85  {
86  a_Rotation -= 360;
87  }
88 
89  if ((a_Rotation >= 0) && (a_Rotation < 90))
90  {
91  return 0x1;
92  }
93  else if ((a_Rotation >= 180) && (a_Rotation < 270))
94  {
95  return 0x3;
96  }
97  else if ((a_Rotation >= 90) && (a_Rotation < 180))
98  {
99  return 0x2;
100  }
101  else
102  {
103  return 0x0;
104  }
105  }
106 
107  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
108  {
109  UNUSED(a_Meta);
110  return 11;
111  }
112 
113 
115  {
116  switch (a_Meta & 0x3) // We only want the direction (bottom) bits
117  {
118  case 0x0: return {0, 0, 1};
119  case 0x1: return {-1, 0, 0};
120  case 0x2: return {0, 0, -1};
121  case 0x3: return {1, 0, 0};
122  default:
123  {
124  LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
125  ASSERT(!"Unknown metadata while determining orientation of repeater!");
126  return {0, 0, 0};
127  }
128  }
129  }
130 
131 
133  {
134  switch (a_Meta & 0x3) // We only want the direction (bottom) bits
135  {
136  case 0x0: return {0, 0, -1};
137  case 0x1: return {1, 0, 0};
138  case 0x2: return {0, 0, 1};
139  case 0x3: return {-1, 0, 0};
140  default:
141  {
142  LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
143  ASSERT(!"Unknown metadata while determining orientation of repeater!");
144  return {0, 0, 0};
145  }
146  }
147  }
148 } ;
149 
150 
151 
152 
static NIBBLETYPE RepeaterRotationToMetaData(double a_Rotation)
virtual bool IsUseable(void) override
Checks if the block can be placed at this point.
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Definition: Chunk.cpp:2230
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
Definition: Player.h:27
BLOCKTYPE m_BlockType
Definition: BlockHandler.h:213
static Vector3i GetRearCoordinateOffset(NIBBLETYPE a_Meta)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
Definition: Chunk.h:49
cBlockRedstoneRepeaterHandler(BLOCKTYPE a_BlockType)
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override
Returns the base colour ID of the block, as will be represented on a map, as per documentation: https...
static Vector3i GetFrontCoordinateOffset(NIBBLETYPE a_Meta)
#define ASSERT(x)
Definition: Globals.h:335
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
Definition: Logger.cpp:174
#define UNUSED
Definition: Globals.h:152
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace) override
Called when a right click to this block is cancelled.
static bool FullyOccupiesVoxel(BLOCKTYPE a_Type)
Definition: BlockInfo.h:50
double GetYaw(void) const
Definition: Entity.h:209
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
Byte ColourID
Definition: Globals.h:118
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ) override
Called if the user right clicks the block and the block is useable returns true if the use was succes...
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData, bool a_ShouldMarkDirty=true, bool a_ShouldInformClient=true)
Sets the meta for the specified block, while keeping the blocktype.
virtual bool GetPlacementBlockTypeMeta(cChunkInterface &a_ChunkInterface, cPlayer &a_Player, int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace, int a_CursorX, int a_CursorY, int a_CursorZ, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) override
Called before a block is placed into a world.
Mixin to clear the block&#39;s meta value when converting to a pickup.
Definition: Mixins.h:55
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, cPlayer &a_Player)=0
Sends the block on those coords to the player.
virtual bool CanBeAt(cChunkInterface &a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk &a_Chunk) override
Checks if the block can stay at the specified relative coords in the chunk.
static bool IsAnySlabType(BLOCKTYPE a_BlockType)
Returns true if the specified blocktype is one of the slabs handled by this handler.
Definition: BlockSlab.h:104