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 "BlockType.h"
6 #include "Mixins.h"
7 #include "ChunkInterface.h"
8 #include "BlockSlab.h"
9 #include "BlockStairs.h"
10 #include "../Chunk.h"
11 
12 
13 
14 
15 
17  public cYawRotator<cBlockHandler, 0x03, 0x00, 0x01, 0x02, 0x03>
18 {
20 
21 public:
22 
23  using Super::Super;
24 
26  {
27  return -GetRearCoordinateOffset(a_Meta);
28  }
29 
31  {
32  switch (a_Meta & E_META_REDSTONE_REPEATER_FACING_MASK) // We only want the direction (bottom) bits
33  {
34  case E_META_REDSTONE_REPEATER_FACING_ZM: return { -1, 0, 0 };
35  case E_META_REDSTONE_REPEATER_FACING_XP: return { 0, 0, -1 };
36  case E_META_REDSTONE_REPEATER_FACING_ZP: return { 1, 0, 0 };
37  case E_META_REDSTONE_REPEATER_FACING_XM: return { 0, 0, 1 };
38 
39  default:
40  {
41  LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
42  ASSERT(!"Unknown metadata while determining orientation of repeater!");
43  return { 0, 0, 0 };
44  }
45  }
46  }
47 
49  {
50  switch (a_Meta & E_META_REDSTONE_REPEATER_FACING_MASK) // We only want the direction (bottom) bits
51  {
52  case E_META_REDSTONE_REPEATER_FACING_ZM: return { 0, 0, 1 };
53  case E_META_REDSTONE_REPEATER_FACING_XP: return { -1, 0, 0 };
54  case E_META_REDSTONE_REPEATER_FACING_ZP: return { 0, 0, -1 };
55  case E_META_REDSTONE_REPEATER_FACING_XM: return { 1, 0, 0 };
56  default:
57  {
58  LOGWARNING("%s: Unknown metadata: %d", __FUNCTION__, a_Meta);
59  ASSERT(!"Unknown metadata while determining orientation of repeater!");
60  return { 0, 0, 0 };
61  }
62  }
63  }
64 
65 private:
66 
67  virtual bool OnUse(
68  cChunkInterface & a_ChunkInterface,
69  cWorldInterface & a_WorldInterface,
70  cPlayer & a_Player,
71  const Vector3i a_BlockPos,
72  eBlockFace a_BlockFace,
73  const Vector3i a_CursorPos
74  ) const override
75  {
76  // Increment the delay setting:
77  a_ChunkInterface.SetBlockMeta(a_BlockPos, ((a_ChunkInterface.GetBlockMeta(a_BlockPos) + 0x04) & 0x0f));
78  return true;
79  }
80 
81 
82 
83 
84 
85  virtual void OnCancelRightClick(
86  cChunkInterface & a_ChunkInterface,
87  cWorldInterface & a_WorldInterface,
88  cPlayer & a_Player,
89  const Vector3i a_BlockPos,
90  eBlockFace a_BlockFace
91  ) const override
92  {
93  UNUSED(a_ChunkInterface);
94  a_WorldInterface.SendBlockTo(a_BlockPos, a_Player);
95  }
96 
97 
98 
99 
100 
101  virtual bool IsUseable(void) const override
102  {
103  return true;
104  }
105 
106 
107 
108 
109 
110  virtual bool CanBeAt(const cChunk & a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
111  {
112  if (a_Position.y <= 0)
113  {
114  return false;
115  }
116 
117  BLOCKTYPE BelowBlock;
118  NIBBLETYPE BelowBlockMeta;
119  a_Chunk.GetBlockTypeMeta(a_Position.addedY(-1), BelowBlock, BelowBlockMeta);
120 
121  if (cBlockInfo::FullyOccupiesVoxel(BelowBlock))
122  {
123  return true;
124  }
125 
126  // upside down slabs
127  if (cBlockSlabHandler::IsAnySlabType(BelowBlock))
128  {
129  return BelowBlockMeta & E_META_WOODEN_SLAB_UPSIDE_DOWN;
130  }
131 
132  // upside down stairs
133  if (cBlockStairsHandler::IsAnyStairType(BelowBlock))
134  {
135  return BelowBlockMeta & E_BLOCK_STAIRS_UPSIDE_DOWN;
136  }
137 
138  return false;
139  }
140 
141 
142 
143 
144 
145  virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem * const a_Tool) const override
146  {
147  return cItem(E_ITEM_REDSTONE_REPEATER, 1, 0);
148  }
149 
150 
151 
152 
153 
154  virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
155  {
156  UNUSED(a_Meta);
157  return 11;
158  }
159 } ;
160 
161 
162 
163 
@ E_META_REDSTONE_REPEATER_FACING_XP
Definition: BlockType.h:799
@ E_META_WOODEN_SLAB_UPSIDE_DOWN
Definition: BlockType.h:989
@ E_BLOCK_STAIRS_UPSIDE_DOWN
Definition: BlockType.h:902
@ E_META_REDSTONE_REPEATER_FACING_ZP
Definition: BlockType.h:800
@ E_META_REDSTONE_REPEATER_FACING_MASK
Definition: BlockType.h:802
@ E_META_REDSTONE_REPEATER_FACING_ZM
Definition: BlockType.h:798
@ E_META_REDSTONE_REPEATER_FACING_XM
Definition: BlockType.h:801
@ E_ITEM_REDSTONE_REPEATER
Definition: BlockType.h:401
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
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc.
Definition: Defines.h:38
Byte ColourID
Definition: Globals.h:162
#define ASSERT(x)
Definition: Globals.h:276
#define UNUSED
Definition: Globals.h:72
void LOGWARNING(std::string_view a_Format, const Args &... args)
Definition: LoggerSimple.h:67
static bool FullyOccupiesVoxel(BLOCKTYPE Block)
Does this block fully occupy its voxel - is it a 'full' block?
Definition: BlockInfo.cpp:606
virtual bool CanBeAt(const cChunk &a_Chunk, const Vector3i a_Position, const NIBBLETYPE a_Meta) const override
virtual void OnCancelRightClick(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace) const override
static Vector3i GetLeftCoordinateOffset(NIBBLETYPE a_Meta)
virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) const override
virtual bool OnUse(cChunkInterface &a_ChunkInterface, cWorldInterface &a_WorldInterface, cPlayer &a_Player, const Vector3i a_BlockPos, eBlockFace a_BlockFace, const Vector3i a_CursorPos) const override
virtual bool IsUseable(void) const override
static Vector3i GetFrontCoordinateOffset(NIBBLETYPE a_Meta)
static Vector3i GetRearCoordinateOffset(NIBBLETYPE a_Meta)
virtual cItems ConvertToPickups(const NIBBLETYPE a_BlockMeta, const cItem *const a_Tool) const override
static bool IsAnySlabType(BLOCKTYPE a_BlockType)
Returns true if the specified blocktype is one of the slabs handled by this handler.
Definition: BlockSlab.h:30
static bool IsAnyStairType(BLOCKTYPE a_Block)
Definition: BlockStairs.h:19
void SetBlockMeta(Vector3i a_BlockPos, NIBBLETYPE a_MetaData)
Sets the meta for the specified block, while keeping the blocktype.
NIBBLETYPE GetBlockMeta(Vector3i a_Pos)
Mixin for blocks whose meta on placement depends on the yaw of the player placing the block.
Definition: Mixins.h:162
cMetaRotator< cBlockHandler, BitMask, North, East, South, West, false > Super
Definition: Mixins.h:163
virtual void SendBlockTo(int a_BlockX, int a_BlockY, int a_BlockZ, const cPlayer &a_Player)=0
Sends the block on those coords to the player.
Definition: Chunk.h:36
void GetBlockTypeMeta(Vector3i a_RelPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta) const
Definition: Chunk.cpp:1757
Definition: Player.h:29
Definition: Item.h:37
This class bridges a vector of cItem for safe access via Lua.
Definition: Item.h:215
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
Definition: Vector3.h:314
T y
Definition: Vector3.h:17