2014-03-01 10:04:17 -05:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// fwd:
|
|
|
|
class cBlockHandler;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
// tolua_begin
|
2014-03-01 14:34:19 -05:00
|
|
|
class cBlockInfo
|
2014-03-01 10:04:17 -05:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Returns the associated BlockInfo structure for the specified block type. */
|
2016-02-05 16:45:45 -05:00
|
|
|
|
2014-09-17 13:40:10 -04:00
|
|
|
/** This accessor makes sure that the cBlockInfo structures are properly initialized exactly once.
|
2017-07-03 12:34:27 -04:00
|
|
|
It does so by using the C++ singleton approximation - storing the actual singleton as the function's static variable. */
|
|
|
|
static cBlockInfo & Get(BLOCKTYPE a_Type);
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** How much light do the blocks emit on their own? */
|
2014-03-01 10:04:17 -05:00
|
|
|
NIBBLETYPE m_LightValue;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** How much light do the blocks consume? */
|
2014-03-01 10:04:17 -05:00
|
|
|
NIBBLETYPE m_SpreadLightFalloff;
|
|
|
|
|
2017-09-07 06:56:17 -04:00
|
|
|
/** Is a block transparent? (https://minecraft.gamepedia.com/Opacity) */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_Transparent;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Is a block destroyed after a single hit? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_OneHitDig;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
|
|
|
/** Can a piston break this block? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_PistonBreakable;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
2017-12-26 16:25:57 -05:00
|
|
|
/** Does this block block the passage of rain? */
|
|
|
|
bool m_IsRainBlocker;
|
|
|
|
|
|
|
|
/** Does this block disperse sky light? (only relevant for transparent blocks) */
|
2017-09-07 06:56:17 -04:00
|
|
|
bool m_IsSkylightDispersant;
|
|
|
|
|
2014-03-01 14:34:19 -05:00
|
|
|
/** Is this block solid (player cannot walk through)? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_IsSolid;
|
2014-03-01 14:34:19 -05:00
|
|
|
|
2016-10-12 08:38:45 -04:00
|
|
|
/** Can a spectator interact with this block */
|
|
|
|
bool m_UseableBySpectator;
|
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
/** Does this block fully occupy its voxel - is it a 'full' block? */
|
2014-03-01 10:04:17 -05:00
|
|
|
bool m_FullyOccupiesVoxel;
|
|
|
|
|
2014-07-29 16:31:31 -04:00
|
|
|
/** Can a finisher change it? */
|
|
|
|
bool m_CanBeTerraformed;
|
|
|
|
|
2015-11-10 08:02:07 -05:00
|
|
|
/** Block height */
|
|
|
|
float m_BlockHeight;
|
|
|
|
|
2016-11-06 13:30:19 -05:00
|
|
|
/** Block's hardness. The greater the value the longer the player needs to break the block. */
|
|
|
|
float m_Hardness;
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// tolua_end
|
|
|
|
|
2017-07-03 12:34:27 -04:00
|
|
|
/** Custom deleter allows cBlockHandler to be an incomplete type. */
|
|
|
|
struct sHandlerDeleter
|
|
|
|
{
|
|
|
|
void operator () (cBlockHandler * a_Handler);
|
|
|
|
};
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
/** Associated block handler. */
|
2017-07-03 12:34:27 -04:00
|
|
|
std::unique_ptr<cBlockHandler, sHandlerDeleter> m_Handler;
|
2014-03-02 14:25:05 -05:00
|
|
|
|
2018-01-23 16:07:06 -05:00
|
|
|
/** The block type associated with this cBlockInfo. Needed for DeprecatedBindings.cpp */
|
|
|
|
BLOCKTYPE m_BlockType;
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// tolua_begin
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-03-02 09:24:09 -05:00
|
|
|
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; }
|
2017-12-26 16:25:57 -05:00
|
|
|
inline static bool IsRainBlocker (BLOCKTYPE a_Type) { return Get(a_Type).m_IsRainBlocker; }
|
2017-09-07 06:56:17 -04:00
|
|
|
inline static bool IsSkylightDispersant (BLOCKTYPE a_Type)
|
|
|
|
{
|
|
|
|
return ((Get(a_Type).m_IsSkylightDispersant) || (Get(a_Type).m_SpreadLightFalloff > 1));
|
|
|
|
}
|
2018-01-23 16:07:06 -05:00
|
|
|
inline static bool IsSnowable (BLOCKTYPE a_Type)
|
|
|
|
{
|
|
|
|
return (
|
|
|
|
(a_Type == E_BLOCK_ICE)
|
|
|
|
|| (a_Type == E_BLOCK_LEAVES)
|
|
|
|
|| (!Get(a_Type).m_Transparent && (a_Type != E_BLOCK_PACKED_ICE))
|
|
|
|
);
|
|
|
|
}
|
2014-03-02 09:24:09 -05:00
|
|
|
inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
|
2016-10-12 08:38:45 -04:00
|
|
|
inline static bool IsUseableBySpectator (BLOCKTYPE a_Type) { return Get(a_Type).m_UseableBySpectator; }
|
2014-03-02 09:24:09 -05:00
|
|
|
inline static bool FullyOccupiesVoxel (BLOCKTYPE a_Type) { return Get(a_Type).m_FullyOccupiesVoxel; }
|
2014-07-29 16:31:31 -04:00
|
|
|
inline static bool CanBeTerraformed (BLOCKTYPE a_Type) { return Get(a_Type).m_CanBeTerraformed; }
|
2015-11-10 08:02:07 -05:00
|
|
|
inline static float GetBlockHeight (BLOCKTYPE a_Type) { return Get(a_Type).m_BlockHeight; }
|
2016-11-06 13:30:19 -05:00
|
|
|
inline static float GetHardness (BLOCKTYPE a_Type) { return Get(a_Type).m_Hardness; }
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-03-02 03:50:24 -05:00
|
|
|
// tolua_end
|
|
|
|
|
2017-07-03 12:34:27 -04:00
|
|
|
inline static cBlockHandler * GetHandler (BLOCKTYPE a_Type) { return Get(a_Type).m_Handler.get(); }
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2014-06-25 02:07:06 -04:00
|
|
|
/** Creates a default BlockInfo structure, initializes all values to their defaults */
|
2014-09-17 13:40:10 -04:00
|
|
|
cBlockInfo()
|
|
|
|
: m_LightValue(0x00)
|
|
|
|
, m_SpreadLightFalloff(0x0f)
|
|
|
|
, m_Transparent(false)
|
|
|
|
, m_OneHitDig(false)
|
|
|
|
, m_PistonBreakable(false)
|
2017-12-26 16:25:57 -05:00
|
|
|
, m_IsRainBlocker(false)
|
2017-09-07 06:56:17 -04:00
|
|
|
, m_IsSkylightDispersant(false)
|
2014-09-17 13:40:10 -04:00
|
|
|
, m_IsSolid(true)
|
2016-10-12 08:38:45 -04:00
|
|
|
, m_UseableBySpectator(false)
|
2014-09-17 13:40:10 -04:00
|
|
|
, m_FullyOccupiesVoxel(false)
|
|
|
|
, m_CanBeTerraformed(false)
|
2015-11-10 08:02:07 -05:00
|
|
|
, m_BlockHeight(1.0)
|
2016-11-06 13:30:19 -05:00
|
|
|
, m_Hardness(0.0f)
|
2017-07-03 12:34:27 -04:00
|
|
|
, m_Handler()
|
2018-01-23 16:07:06 -05:00
|
|
|
, m_BlockType(E_BLOCK_AIR)
|
2014-09-17 13:40:10 -04:00
|
|
|
{}
|
2014-03-01 10:04:17 -05:00
|
|
|
|
2017-07-03 12:34:27 -04:00
|
|
|
private:
|
|
|
|
/** Storage for all the BlockInfo structures. */
|
|
|
|
class cBlockInfoArray;
|
2014-07-17 13:13:23 -04:00
|
|
|
}; // tolua_export
|
2014-03-01 10:04:17 -05:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
|
2017-07-03 12:34:27 -04:00
|
|
|
class cBlockInfo::cBlockInfoArray:
|
|
|
|
public std::array<cBlockInfo, 256>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/** Initializes the contained BlockInfo structures with block-specific values. */
|
|
|
|
cBlockInfoArray();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
inline cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
|
|
|
|
{
|
|
|
|
static cBlockInfoArray ms_Info;
|
|
|
|
return ms_Info[a_Type];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-03-02 14:25:05 -05:00
|
|
|
// Shortcut to get the blockhandler for a specific block
|
|
|
|
inline cBlockHandler * BlockHandler(BLOCKTYPE a_BlockType)
|
|
|
|
{
|
2017-07-03 12:34:27 -04:00
|
|
|
return cBlockInfo::Get(a_BlockType).m_Handler.get();
|
2014-03-02 14:25:05 -05:00
|
|
|
}
|