Cuberite
A lightweight, fast and extensible game server for Minecraft
ItemRedstoneDust.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "ItemHandler.h"
5 
6 
7 
8 
9 
11 {
12 public:
13  cItemRedstoneDustHandler(int a_ItemType)
14  : cItemHandler(a_ItemType)
15  {
16  }
17 
18  virtual bool IsPlaceable(void) override
19  {
20  return true;
21  }
22 
24  cWorld * a_World, cPlayer * a_Player,
25  int a_BlockX, int a_BlockY, int a_BlockZ, eBlockFace a_BlockFace,
26  int a_CursorX, int a_CursorY, int a_CursorZ,
27  BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
28  ) override
29  {
30  // Check if coords are out of range:
31  if ((a_BlockY <= 0) || (a_BlockY >= cChunkDef::Height))
32  {
33  return false;
34  }
35 
36  // Check the block below, if it supports dust on top of it:
37  BLOCKTYPE BlockType;
38  NIBBLETYPE BlockMeta;
39  if (!a_World->GetBlockTypeMeta(a_BlockX, a_BlockY - 1, a_BlockZ, BlockType, BlockMeta))
40  {
41  return false;
42  }
43  if (!IsBlockTypeUnderSuitable(BlockType, BlockMeta))
44  {
45  return false;
46  }
47 
48  a_BlockType = E_BLOCK_REDSTONE_WIRE;
49  a_BlockMeta = 0;
50  return true;
51  }
52 
53 
55  static bool IsBlockTypeUnderSuitable(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
56  {
57  if (cBlockInfo::FullyOccupiesVoxel(a_BlockType))
58  {
59  return true;
60  }
61 
62  switch (a_BlockType)
63  {
66  case E_BLOCK_STONE_SLAB:
67  {
68  // Slabs can support redstone if they're upside down:
69  return ((a_BlockMeta & 0x08) != 0);
70  }
71  }
72  return false;
73  }
74 } ;
75 
76 
77 
78 
virtual bool IsPlaceable(void) override
Blocks simply get placed.
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
virtual bool GetPlacementBlockTypeMeta(cWorld *a_World, 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 when the player right-clicks with this item and IsPlaceable() == true, and OnPlayerPlace() is ...
Definition: Player.h:27
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
static const int Height
Definition: ChunkDef.h:135
bool GetBlockTypeMeta(Vector3i a_BlockPos, BLOCKTYPE &a_BlockType, NIBBLETYPE &a_BlockMeta)
Retrieves the block type and meta at the specified coords.
Definition: World.cpp:1909
Definition: World.h:65
static bool IsBlockTypeUnderSuitable(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
Returns true if the specified block type / meta is suitable to have redstone dust on top of it...
cItemRedstoneDustHandler(int a_ItemType)
static bool FullyOccupiesVoxel(BLOCKTYPE a_Type)
Definition: BlockInfo.h:50
eBlockFace
Block face constants, used in PlayerDigging and PlayerBlockPlacement packets and bbox collision calc...
Definition: Defines.h:29