cBlockInfo: further cleanup (#5001)
* cBlockInfo: further cleanup + Use switch statements instead of lookup in dynamically initialised arrays - Remove some deprecated bindings * Update Stubs removing references to BlockInfoArray
This commit is contained in:
parent
f8d72c8fa9
commit
64442b05f8
@ -292,32 +292,6 @@ tolua_lerror:
|
||||
|
||||
|
||||
|
||||
static int tolua_cBlockInfo_Get(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
if (
|
||||
!L.CheckParamStaticSelf("cBlockInfo") ||
|
||||
!L.CheckParamNumber(2)
|
||||
)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
BLOCKTYPE BlockType{};
|
||||
L.GetStackValue(2, BlockType);
|
||||
|
||||
LOGWARNING("cBlockInfo:Get() is deprecated, use the static querying functions instead");
|
||||
L.LogStackTrace(0);
|
||||
|
||||
cBlockInfo & BlockInfo = const_cast<cBlockInfo &>(cBlockInfo::Get(BlockType));
|
||||
L.Push(&BlockInfo);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_cBlockInfo_GetPlaceSound(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
@ -339,85 +313,6 @@ static int tolua_cBlockInfo_GetPlaceSound(lua_State * tolua_S)
|
||||
|
||||
|
||||
|
||||
static int tolua_get_cBlockInfo_m_PlaceSound(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamSelf("const cBlockInfo"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
L.Push("");
|
||||
LOGWARNING("cBlockInfo.m_PlaceSound is deprecated");
|
||||
L.LogStackTrace(0);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_set_cBlockInfo_m_PlaceSound(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamSelf("cBlockInfo"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOGWARNING("cBlockInfo.m_PlaceSound is deprecated");
|
||||
L.LogStackTrace(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** cBlockInfo variables: access the corresponding getter function instead of the variable.
|
||||
\tparam VariableType The type of the variable being accessed.
|
||||
\tparam GetterFunction The function called to get the value returned to lua. */
|
||||
template <typename VariableType, VariableType (*GetterFunction)(BLOCKTYPE)>
|
||||
static int tolua_get_cBlockInfo(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamSelf("const cBlockInfo"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
const cBlockInfo * Self = nullptr;
|
||||
L.GetStackValue(1, Self);
|
||||
|
||||
L.Push(GetterFunction(Self->m_BlockType));
|
||||
LOGWARNING("cBlockInfo variables are deprecated, use the static functions instead.");
|
||||
L.LogStackTrace(0);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/** cBlockInfo variables: Print deprecation message on assignment. */
|
||||
static int tolua_set_cBlockInfo(lua_State * tolua_S)
|
||||
{
|
||||
cLuaState L(tolua_S);
|
||||
if (!L.CheckParamSelf("cBlockInfo"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
LOGWARNING("cBlockInfo variables are deprecated in favour of the static functions.");
|
||||
L.LogStackTrace(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
static int tolua_get_cItem_m_Lore(lua_State * tolua_S)
|
||||
{
|
||||
// Maintain legacy m_Lore variable as Lore table split by ` (grave-accent)
|
||||
@ -785,23 +680,7 @@ void DeprecatedBindings::Bind(lua_State * tolua_S)
|
||||
tolua_function(tolua_S, "StringToMobType", tolua_AllToLua_StringToMobType00);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cBlockInfo");
|
||||
tolua_function(tolua_S, "Get", tolua_cBlockInfo_Get);
|
||||
tolua_function(tolua_S, "GetPlaceSound", tolua_cBlockInfo_GetPlaceSound);
|
||||
tolua_variable(tolua_S, "m_PlaceSound", tolua_get_cBlockInfo_m_PlaceSound, tolua_set_cBlockInfo_m_PlaceSound);
|
||||
tolua_variable(tolua_S, "m_LightValue", tolua_get_cBlockInfo<NIBBLETYPE, cBlockInfo::GetLightValue >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_SpreadLightFalloff", tolua_get_cBlockInfo<NIBBLETYPE, cBlockInfo::GetSpreadLightFalloff>, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_Transparent", tolua_get_cBlockInfo<bool, cBlockInfo::IsTransparent >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_OneHitDig", tolua_get_cBlockInfo<bool, cBlockInfo::IsOneHitDig >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_PistonBreakable", tolua_get_cBlockInfo<bool, cBlockInfo::IsPistonBreakable >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_IsRainBlocker", tolua_get_cBlockInfo<bool, cBlockInfo::IsRainBlocker >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_IsSkylightDispersant", tolua_get_cBlockInfo<bool, cBlockInfo::IsSkylightDispersant >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_IsSnowable", tolua_get_cBlockInfo<bool, cBlockInfo::IsSnowable >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_IsSolid", tolua_get_cBlockInfo<bool, cBlockInfo::IsSolid >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_UseableBySpectator", tolua_get_cBlockInfo<bool, cBlockInfo::IsUseableBySpectator >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_FullyOccupiesVoxel", tolua_get_cBlockInfo<bool, cBlockInfo::FullyOccupiesVoxel >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_CanBeTerraformed", tolua_get_cBlockInfo<bool, cBlockInfo::CanBeTerraformed >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_BlockHeight", tolua_get_cBlockInfo<float, cBlockInfo::GetBlockHeight >, tolua_set_cBlockInfo);
|
||||
tolua_variable(tolua_S, "m_Hardness", tolua_get_cBlockInfo<float, cBlockInfo::GetHardness >, tolua_set_cBlockInfo);
|
||||
tolua_endmodule(tolua_S);
|
||||
|
||||
tolua_beginmodule(tolua_S, "cItem");
|
||||
|
2020
src/BlockInfo.cpp
2020
src/BlockInfo.cpp
File diff suppressed because it is too large
Load Diff
131
src/BlockInfo.h
131
src/BlockInfo.h
@ -6,42 +6,11 @@
|
||||
|
||||
|
||||
|
||||
|
||||
// tolua_begin
|
||||
class cBlockInfo
|
||||
{
|
||||
public:
|
||||
// tolua_end
|
||||
|
||||
/** The block type associated with this cBlockInfo. Needed for DeprecatedBindings.cpp */
|
||||
BLOCKTYPE m_BlockType;
|
||||
|
||||
/** 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. */
|
||||
inline static const cBlockInfo & Get(BLOCKTYPE a_Type);
|
||||
|
||||
// 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; }
|
||||
/** Warning: IsOneHitDig does not take into account enchantments / status effects / swim state / floating state
|
||||
and therefore may be incorrect. Only use to check if hardness is 0
|
||||
If you want to check if a player would instantly mine a_Block use cPlayer::CanInstantlyMine(a_Block) */
|
||||
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 IsRainBlocker (BLOCKTYPE a_Type) { return Get(a_Type).m_IsRainBlocker; }
|
||||
inline static bool IsSkylightDispersant (BLOCKTYPE a_Type)
|
||||
{
|
||||
return ((Get(a_Type).m_IsSkylightDispersant) || (Get(a_Type).m_SpreadLightFalloff > 1));
|
||||
}
|
||||
static bool IsSnowable(BLOCKTYPE a_Type);
|
||||
inline static bool IsSolid (BLOCKTYPE a_Type) { return Get(a_Type).m_IsSolid; }
|
||||
inline static bool IsUseableBySpectator (BLOCKTYPE a_Type) { return Get(a_Type).m_UseableBySpectator; }
|
||||
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 float GetHardness (BLOCKTYPE a_Type) { return Get(a_Type).m_Hardness; }
|
||||
|
||||
// tolua_end
|
||||
|
||||
@ -49,53 +18,53 @@ public:
|
||||
See Physics\Explodinator.cpp for details of explosion block destruction. */
|
||||
static float GetExplosionAbsorption(BLOCKTYPE Block);
|
||||
|
||||
/** Creates a default BlockInfo structure, initializes all values to their defaults */
|
||||
cBlockInfo();
|
||||
|
||||
private:
|
||||
|
||||
/** Storage for all the BlockInfo structures. */
|
||||
class cBlockInfoArray;
|
||||
// tolua_begin
|
||||
|
||||
/** How much light do the blocks emit on their own? */
|
||||
NIBBLETYPE m_LightValue;
|
||||
static NIBBLETYPE GetLightValue(BLOCKTYPE Block);
|
||||
|
||||
/** How much light do the blocks consume? */
|
||||
NIBBLETYPE m_SpreadLightFalloff;
|
||||
|
||||
/** Is a block transparent? (https://minecraft.gamepedia.com/Opacity) */
|
||||
bool m_Transparent;
|
||||
|
||||
/** Is a block destroyed after a single hit? */
|
||||
bool m_OneHitDig;
|
||||
|
||||
/** Can a piston break this block? */
|
||||
bool m_PistonBreakable;
|
||||
|
||||
/** Does this block block the passage of rain? */
|
||||
bool m_IsRainBlocker;
|
||||
|
||||
/** Does this block disperse sky light? (only relevant for transparent blocks) */
|
||||
bool m_IsSkylightDispersant;
|
||||
|
||||
/** Is this block solid (player cannot walk through)? */
|
||||
bool m_IsSolid;
|
||||
|
||||
/** Can a spectator interact with this block */
|
||||
bool m_UseableBySpectator;
|
||||
|
||||
/** Does this block fully occupy its voxel - is it a 'full' block? */
|
||||
bool m_FullyOccupiesVoxel;
|
||||
static NIBBLETYPE GetSpreadLightFalloff(BLOCKTYPE Block);
|
||||
|
||||
/** Can a finisher change it? */
|
||||
bool m_CanBeTerraformed;
|
||||
static bool CanBeTerraformed(BLOCKTYPE Block);
|
||||
|
||||
/** Block height */
|
||||
float m_BlockHeight;
|
||||
/** Does this block fully occupy its voxel - is it a 'full' block? */
|
||||
static bool FullyOccupiesVoxel(BLOCKTYPE Block);
|
||||
|
||||
/** Is a block destroyed after a single hit?
|
||||
Warning: IsOneHitDig does not take into account enchantments / status effects / swim state / floating state
|
||||
and therefore may be incorrect. Only use to check if hardness is 0.
|
||||
If you want to check if a player would instantly mine a_Block use cPlayer::CanInstantlyMine(a_Block) */
|
||||
static bool IsOneHitDig(BLOCKTYPE Block);
|
||||
|
||||
/** Can a piston break this block? */
|
||||
static bool IsPistonBreakable(BLOCKTYPE Block);
|
||||
|
||||
/** Does this block block the passage of rain? */
|
||||
static bool IsRainBlocker(BLOCKTYPE Block);
|
||||
|
||||
/** Does this block disperse sky light? (only relevant for transparent blocks) */
|
||||
static bool IsSkylightDispersant(BLOCKTYPE Block);
|
||||
|
||||
static bool IsSnowable(BLOCKTYPE Block);
|
||||
|
||||
/** Is this block solid (player cannot walk through)? */
|
||||
static bool IsSolid(BLOCKTYPE Block);
|
||||
|
||||
/** Is a block transparent? (https://minecraft.gamepedia.com/Opacity) */
|
||||
static bool IsTransparent(BLOCKTYPE Block);
|
||||
|
||||
/** Can a spectator interact with this block? */
|
||||
static bool IsUseableBySpectator(BLOCKTYPE Block);
|
||||
|
||||
/** Block's height. */
|
||||
static float GetBlockHeight(BLOCKTYPE Block);
|
||||
|
||||
/** Block's hardness. The greater the value the longer the player needs to break the block. */
|
||||
float m_Hardness;
|
||||
}; // tolua_export
|
||||
static float GetHardness(BLOCKTYPE Block);
|
||||
};
|
||||
// tolua_end
|
||||
|
||||
|
||||
|
||||
@ -130,25 +99,3 @@ bool IsBlockMaterialLeaves(BLOCKTYPE a_BlockType);
|
||||
bool IsBlockMaterialGourd(BLOCKTYPE a_BlockType);
|
||||
|
||||
bool IsBlockMaterialRock(BLOCKTYPE a_BlockType);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
class cBlockInfo::cBlockInfoArray:
|
||||
public std::array<cBlockInfo, 256>
|
||||
{
|
||||
public:
|
||||
/** Initializes the contained BlockInfo structures with block-specific values. */
|
||||
cBlockInfoArray();
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
inline const cBlockInfo & cBlockInfo::Get(BLOCKTYPE a_Type)
|
||||
{
|
||||
static const cBlockInfoArray ms_Info;
|
||||
return ms_Info[a_Type];
|
||||
}
|
||||
|
@ -86,16 +86,9 @@ extern "C" int luaopen_lxp(lua_State * a_LuaState)
|
||||
|
||||
|
||||
|
||||
cBlockInfo::cBlockInfo()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBlockInfo::cBlockInfoArray::cBlockInfoArray()
|
||||
bool cBlockInfo::IsSolid(BLOCKTYPE)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
@ -13,22 +13,6 @@
|
||||
|
||||
|
||||
|
||||
cBlockInfo::cBlockInfo()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBlockInfo::cBlockInfoArray::cBlockInfoArray()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
cBoundingBox::cBoundingBox(double, double, double, double, double, double)
|
||||
{
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user