summaryrefslogtreecommitdiffstats
path: root/src/BlockInfo.h
blob: 9f562e53171afb1f151c3b3490fe7311ff57e0e5 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132

#pragma once





// fwd:
class cBlockHandler;




// tolua_begin
class cBlockInfo
{
public:

	/** Returns the associated BlockInfo structure for the specified block type. */
	
	/** This accessor makes sure that the cBlockInfo structures are properly initialized exactly once.
	It does so by using the C++ singleton approximation - storing the actual singleton as the function's static variable.
	It works only if it is called for the first time before the app spawns other threads. */
	static cBlockInfo & Get(BLOCKTYPE a_Type)
	{
		static cBlockInfo ms_Info[256];
		static bool IsBlockInfoInitialized = false;
		if (!IsBlockInfoInitialized)
		{
			cBlockInfo::Initialize(ms_Info);
			IsBlockInfoInitialized = true;
		}
		return ms_Info[a_Type];
	}


	/** How much light do the blocks emit on their own? */
	NIBBLETYPE m_LightValue;

	/** How much light do the blocks consume? */
	NIBBLETYPE m_SpreadLightFalloff;

	/** Is a block completely transparent? (light doesn't get decreased(?)) */
	bool m_Transparent;

	/** Is a block destroyed after a single hit? */
	bool m_OneHitDig;

	/** Can a piston break this block? */
	bool m_PistonBreakable;

	/** Can this block hold snow atop? */
	bool m_IsSnowable;

	/** Is this block solid (player cannot walk through)? */
	bool m_IsSolid;

	/** Does this block fully occupy its voxel - is it a 'full' block? */
	bool m_FullyOccupiesVoxel;

	/** Can a finisher change it? */
	bool m_CanBeTerraformed;

	/** Block height */
	float m_BlockHeight;

	/** Sound when placing this block */
	AString m_PlaceSound;

	// tolua_end

	/** Associated block handler. */
	cBlockHandler * m_Handler;

	// tolua_begin

	inline static NIBBLETYPE GetLightValue        (BLOCKTYPE a_Type) { return Get(a_Type).m_LightValue;          }
	inline static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE a_Type) { return Get(a_Type).m_SpreadLightFalloff;  }
	inline static bool IsTransparent              (BLOCKTYPE a_Type) { return Get(a_Type).m_Transparent;         }
	inline static bool IsOneHitDig                (BLOCKTYPE a_Type) { return Get(a_Type).m_OneHitDig;           }
	inline static bool IsPistonBreakable          (BLOCKTYPE a_Type) { return Get(a_Type).m_PistonBreakable;     }
	inline static bool IsSnowable                 (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSnowable;          }
	inline static bool IsSolid                    (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid;             }
	inline static bool FullyOccupiesVoxel         (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel;  }
	inline static bool CanBeTerraformed           (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed;    }
	inline static float GetBlockHeight            (BLOCKTYPE a_Type) { return Get(a_Type).m_BlockHeight;         }
	inline static AString GetPlaceSound           (BLOCKTYPE a_Type) { return Get(a_Type).m_PlaceSound;          }

	// tolua_end

	inline static cBlockHandler * GetHandler      (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler;             }

protected:
	/** Storage for all the BlockInfo structures. */
	typedef cBlockInfo cBlockInfoArray[256];

	/** Creates a default BlockInfo structure, initializes all values to their defaults */
	cBlockInfo()
		: m_LightValue(0x00)
		, m_SpreadLightFalloff(0x0f)
		, m_Transparent(false)
		, m_OneHitDig(false)
		, m_PistonBreakable(false)
		, m_IsSnowable(false)
		, m_IsSolid(true)
		, m_FullyOccupiesVoxel(false)
		, m_CanBeTerraformed(false)
		, m_BlockHeight(1.0)
		, m_PlaceSound("")
		, m_Handler(nullptr)
	{}

	/** Cleans up the stored values */
	~cBlockInfo();

	/** Initializes the specified BlockInfo structures with block-specific values. */
	static void Initialize(cBlockInfoArray & a_BlockInfos);
};  // tolua_export





// Shortcut to get the blockhandler for a specific block
inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
{
	return cBlockInfo::Get(a_BlockType).m_Handler;
}