Cuberite
A lightweight, fast and extensible game server for Minecraft
BlockInfo.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 
5 
6 
7 
8 // fwd:
9 class cBlockHandler;
10 
11 
12 
13 
14 // tolua_begin
16 {
17 public:
18  // tolua_end
19 
22 
26  inline static const cBlockInfo & Get(BLOCKTYPE a_Type);
27 
28  // tolua_begin
29 
30  inline static NIBBLETYPE GetLightValue (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue; }
31  inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff; }
32  inline static bool IsTransparent (BLOCKTYPE a_Type) { return Get(a_Type).m_Transparent; }
33  inline static bool IsOneHitDig (BLOCKTYPE a_Type) { return Get(a_Type).m_OneHitDig; }
34  inline static bool IsPistonBreakable (BLOCKTYPE a_Type) { return Get(a_Type).m_PistonBreakable; }
35  inline static bool IsRainBlocker (BLOCKTYPE a_Type) { return Get(a_Type).m_IsRainBlocker; }
36  inline static bool IsSkylightDispersant (BLOCKTYPE a_Type)
37  {
38  return ((Get(a_Type).m_IsSkylightDispersant) || (Get(a_Type).m_SpreadLightFalloff > 1));
39  }
40  inline static bool IsSnowable (BLOCKTYPE a_Type)
41  {
42  return (
43  (a_Type == E_BLOCK_ICE) ||
44  (a_Type == E_BLOCK_LEAVES) ||
45  (!IsTransparent(a_Type) && (a_Type != E_BLOCK_PACKED_ICE))
46  );
47  }
48  inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
49  inline static bool IsUseableBySpectator (BLOCKTYPE a_Type) { return Get(a_Type).m_UseableBySpectator; }
50  inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
51  inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
52  inline static float GetBlockHeight (BLOCKTYPE a_Type) { return Get(a_Type).m_BlockHeight; }
53  inline static float GetHardness (BLOCKTYPE a_Type) { return Get(a_Type).m_Hardness; }
54 
55  // tolua_end
56 
57  inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler.get(); }
58 
61  m_BlockType(E_BLOCK_STONE),
62  m_LightValue(0x00),
64  m_Transparent(false),
65  m_OneHitDig(false),
66  m_PistonBreakable(false),
67  m_IsRainBlocker(false),
69  m_IsSolid(true),
70  m_UseableBySpectator(false),
71  m_FullyOccupiesVoxel(false),
72  m_CanBeTerraformed(false),
73  m_BlockHeight(1.0),
74  m_Hardness(0.0f),
75  m_Handler()
76  {
77  }
78 
79 private:
82 
85 
88 
91 
94 
97 
100 
103 
105  bool m_IsSolid;
106 
109 
112 
115 
118 
120  float m_Hardness;
121 
124  {
125  void operator () (cBlockHandler * a_Handler);
126  };
127 
129  std::unique_ptr<cBlockHandler, sHandlerDeleter> m_Handler;
130 }; // tolua_export
131 
132 
133 
134 
135 
137  public std::array<cBlockInfo, 256>
138 {
139 public:
141  cBlockInfoArray();
142 };
143 
144 
145 
146 
147 
148 inline const cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
149 {
150  static const cBlockInfoArray ms_Info;
151  return ms_Info[a_Type];
152 }
153 
154 
155 
156 
157 
158 // Shortcut to get the blockhandler for a specific block
159 inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
160 {
161  return cBlockInfo::GetHandler(a_BlockType);
162 }
static bool CanBeTerraformed(BLOCKTYPE a_Type)
Definition: BlockInfo.h:51
static float GetBlockHeight(BLOCKTYPE a_Type)
Definition: BlockInfo.h:52
static bool IsSolid(BLOCKTYPE a_Type)
Definition: BlockInfo.h:48
bool m_PistonBreakable
Can a piston break this block?
Definition: BlockInfo.h:96
unsigned char BLOCKTYPE
The datatype used by blockdata.
Definition: ChunkDef.h:42
static cBlockHandler * GetHandler(BLOCKTYPE a_Type)
Definition: BlockInfo.h:57
static bool IsSkylightDispersant(BLOCKTYPE a_Type)
Definition: BlockInfo.h:36
static bool IsUseableBySpectator(BLOCKTYPE a_Type)
Definition: BlockInfo.h:49
Custom deleter allows cBlockHandler to be an incomplete type.
Definition: BlockInfo.h:123
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
Definition: ChunkDef.h:45
bool m_Transparent
Is a block transparent? (https://minecraft.gamepedia.com/Opacity)
Definition: BlockInfo.h:90
std::unique_ptr< cBlockHandler, sHandlerDeleter > m_Handler
Associated block handler.
Definition: BlockInfo.h:129
cBlockInfo()
Creates a default BlockInfo structure, initializes all values to their defaults.
Definition: BlockInfo.h:60
bool m_CanBeTerraformed
Can a finisher change it?
Definition: BlockInfo.h:114
static NIBBLETYPE GetLightValue(BLOCKTYPE a_Type)
Definition: BlockInfo.h:30
float m_Hardness
Block&#39;s hardness.
Definition: BlockInfo.h:120
bool m_FullyOccupiesVoxel
Does this block fully occupy its voxel - is it a &#39;full&#39; block?
Definition: BlockInfo.h:111
static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type)
Definition: BlockInfo.h:31
bool m_UseableBySpectator
Can a spectator interact with this block.
Definition: BlockInfo.h:108
bool m_OneHitDig
Is a block destroyed after a single hit?
Definition: BlockInfo.h:93
BLOCKTYPE m_BlockType
The block type associated with this cBlockInfo.
Definition: BlockInfo.h:21
static const cBlockInfo & Get(BLOCKTYPE a_Type)
Returns the associated BlockInfo structure for the specified block type.
Definition: BlockInfo.h:148
static bool IsSnowable(BLOCKTYPE a_Type)
Definition: BlockInfo.h:40
bool m_IsSolid
Is this block solid (player cannot walk through)?
Definition: BlockInfo.h:105
NIBBLETYPE m_LightValue
How much light do the blocks emit on their own?
Definition: BlockInfo.h:81
float m_BlockHeight
Block height.
Definition: BlockInfo.h:117
static bool IsRainBlocker(BLOCKTYPE a_Type)
Definition: BlockInfo.h:35
bool m_IsRainBlocker
Does this block block the passage of rain?
Definition: BlockInfo.h:99
cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
Definition: BlockInfo.h:159
static bool FullyOccupiesVoxel(BLOCKTYPE a_Type)
Definition: BlockInfo.h:50
static bool IsTransparent(BLOCKTYPE a_Type)
Definition: BlockInfo.h:32
static bool IsPistonBreakable(BLOCKTYPE a_Type)
Definition: BlockInfo.h:34
NIBBLETYPE m_SpreadLightFalloff
How much light do the blocks consume?
Definition: BlockInfo.h:87
bool m_IsSkylightDispersant
Does this block disperse sky light? (only relevant for transparent blocks)
Definition: BlockInfo.h:102
static bool IsOneHitDig(BLOCKTYPE a_Type)
Definition: BlockInfo.h:33
void operator()(cBlockHandler *a_Handler)
Definition: BlockInfo.cpp:8
static float GetHardness(BLOCKTYPE a_Type)
Definition: BlockInfo.h:53