1
0

g_BlockXXX => cBlockInfo::XXX

This commit is contained in:
andrew 2014-03-01 21:34:19 +02:00
parent 5c5502be9e
commit d73cdba1f6
33 changed files with 91 additions and 73 deletions

View File

@ -7,13 +7,13 @@
BlockInfo BlockInfo::ms_Info[256]; cBlockInfo cBlockInfo::ms_Info[256];
BlockInfo::BlockInfo() cBlockInfo::cBlockInfo()
: m_LightValue(0x00) : m_LightValue(0x00)
, m_SpreadLightFalloff(0x0f) , m_SpreadLightFalloff(0x0f)
, m_Transparent(false) , m_Transparent(false)
@ -29,7 +29,7 @@ BlockInfo::BlockInfo()
BlockInfo & BlockInfo::GetById(unsigned int a_ID) cBlockInfo & cBlockInfo::GetById(unsigned int a_ID)
{ {
ASSERT(a_ID < 256); ASSERT(a_ID < 256);
@ -40,7 +40,7 @@ BlockInfo & BlockInfo::GetById(unsigned int a_ID)
void BlockInfo::Initialize(void) void cBlockInfo::Initialize(void)
{ {
// Emissive blocks // Emissive blocks
ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; ms_Info[E_BLOCK_FIRE ].m_LightValue = 15;
@ -413,7 +413,7 @@ class cBlockInfoInitializer
public: public:
cBlockInfoInitializer(void) cBlockInfoInitializer(void)
{ {
BlockInfo::Initialize(); cBlockInfo::Initialize();
} }
} BlockInfoInitializer; } BlockInfoInitializer;

View File

@ -6,27 +6,44 @@
class BlockInfo class cBlockInfo
{ {
public: public:
BlockInfo(); cBlockInfo();
/** (Re-)Initializes the internal BlockInfo structures. */ /** (Re-)Initializes the internal BlockInfo structures. */
static void Initialize(void); static void Initialize(void);
/** Returns the associated BlockInfo structure. */ /** Returns the associated BlockInfo structure. */
static BlockInfo & GetById(unsigned int a_ID); static cBlockInfo & GetById(unsigned int a_ID);
/** How much light do the blocks emit on their own? */
NIBBLETYPE m_LightValue; NIBBLETYPE m_LightValue;
/** How much light do the blocks consume? */
NIBBLETYPE m_SpreadLightFalloff; NIBBLETYPE m_SpreadLightFalloff;
/** Is a block completely transparent? (light doesn't get decreased(?)) */
bool m_Transparent; bool m_Transparent;
/** Is a block destroyed after a single hit? */
bool m_OneHitDig; bool m_OneHitDig;
/** Can a piston break this block? */
bool m_PistonBreakable; bool m_PistonBreakable;
/** Can this block hold snow atop? */
bool m_IsSnowable; bool m_IsSnowable;
/** Does this block require a tool to drop? */
bool m_RequiresSpecialTool; bool m_RequiresSpecialTool;
/** Is this block solid (player cannot walk through)? */
bool m_IsSolid; bool m_IsSolid;
/** Does this block fully occupy it's voxel - is it a 'full' block? */
bool m_FullyOccupiesVoxel; bool m_FullyOccupiesVoxel;
@ -34,7 +51,7 @@ public:
inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; } inline static NIBBLETYPE GetSpreadLightFalloff(unsigned int a_ID) { return GetById(a_ID).m_SpreadLightFalloff; }
inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; } inline static bool IsTransparent (unsigned int a_ID) { return GetById(a_ID).m_Transparent; }
inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; } inline static bool IsOneHitDig (unsigned int a_ID) { return GetById(a_ID).m_OneHitDig; }
inline static bool IsPistoneBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; } inline static bool IsPistonBreakable (unsigned int a_ID) { return GetById(a_ID).m_PistonBreakable; }
inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; } inline static bool IsSnowable (unsigned int a_ID) { return GetById(a_ID).m_IsSnowable; }
inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; } inline static bool RequiresSpecialTool (unsigned int a_ID) { return GetById(a_ID).m_RequiresSpecialTool; }
inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; } inline static bool IsSolid (unsigned int a_ID) { return GetById(a_ID).m_IsSolid; }
@ -44,7 +61,7 @@ public:
protected: protected:
// TODO xdot: Change to std::vector to support dynamic block IDs // TODO xdot: Change to std::vector to support dynamic block IDs
static BlockInfo ms_Info[256]; static cBlockInfo ms_Info[256];
}; };

View File

@ -101,7 +101,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); return (a_RelY > 0) && (cBlockInfo::IsSolid(BlockIsOn));
} }
} ; } ;

View File

@ -54,7 +54,7 @@ public:
NIBBLETYPE BlockMeta; NIBBLETYPE BlockMeta;
if ( if (
a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) && a_Chunk.UnboundedRelGetBlock(a_RelX + Coords[i].x, a_RelY, a_RelZ + Coords[i].z, BlockType, BlockMeta) &&
(g_BlockIsSolid[BlockType]) cBlockInfo::IsSolid(BlockType)
) )
{ {
return false; return false;

View File

@ -36,7 +36,7 @@ public:
if (a_RelY < cChunkDef::Height - 1) if (a_RelY < cChunkDef::Height - 1)
{ {
BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ); BLOCKTYPE Above = a_Chunk.GetBlock(a_RelX, a_RelY + 1, a_RelZ);
if ((!g_BlockTransparent[Above] && !g_BlockOneHitDig[Above]) || IsBlockWater(Above)) if ((!cBlockInfo::IsTransparent(Above) && !cBlockInfo::IsOneHitDig(Above)) || IsBlockWater(Above))
{ {
a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL); a_Chunk.FastSetBlock(a_RelX, a_RelY, a_RelZ, E_BLOCK_DIRT, E_META_DIRT_NORMAL);
return; return;
@ -77,7 +77,7 @@ public:
BLOCKTYPE AboveDest; BLOCKTYPE AboveDest;
NIBBLETYPE AboveMeta; NIBBLETYPE AboveMeta;
Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta); Chunk->GetBlockTypeMeta(BlockX, BlockY + 1, BlockZ, AboveDest, AboveMeta);
if ((g_BlockOneHitDig[AboveDest] || g_BlockTransparent[AboveDest]) && !IsBlockWater(AboveDest)) if ((cBlockInfo::IsOneHitDig(AboveDest) || cBlockInfo::IsTransparent(AboveDest)) && !IsBlockWater(AboveDest))
{ {
Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0); Chunk->FastSetBlock(BlockX, BlockY, BlockZ, E_BLOCK_GRASS, 0);
} }

View File

@ -91,7 +91,7 @@ public:
AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true); AddFaceDirection( a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, true);
return g_BlockIsSolid[a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ)]; return cBlockInfo::IsSolid(a_ChunkInterface.GetBlock(a_BlockX, a_BlockY, a_BlockZ));
} }

View File

@ -102,7 +102,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
} }
} ; } ;

View File

@ -98,7 +98,7 @@ public:
{ {
return false; return false;
} }
if (!g_BlockIsSolid[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]) if (!cBlockInfo::IsSolid(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)))
{ {
return false; return false;
} }
@ -130,7 +130,7 @@ public:
// Too close to the edge, cannot simulate // Too close to the edge, cannot simulate
return true; return true;
} }
return g_BlockIsSolid[BlockType]; return cBlockInfo::IsSolid(BlockType);
} }
} }
return true; return true;

View File

@ -20,7 +20,7 @@ public:
virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override virtual bool CanBeAt(cChunkInterface & a_ChunkInterface, int a_RelX, int a_RelY, int a_RelZ, const cChunk & a_Chunk) override
{ {
return ((a_RelY > 0) && g_BlockFullyOccupiesVoxel[a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)]); return ((a_RelY > 0) && cBlockInfo::FullyOccupiesVoxel(a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ)));
} }

View File

@ -72,7 +72,7 @@ public:
BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ); BLOCKTYPE BlockBelow = a_Chunk.GetBlock(a_RelX, a_RelY - 1, a_RelZ);
NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ); NIBBLETYPE MetaBelow = a_Chunk.GetMeta(a_RelX, a_RelY - 1, a_RelZ);
if (g_BlockIsSnowable[BlockBelow] || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7))) if (cBlockInfo::IsSnowable(BlockBelow) || ((BlockBelow == E_BLOCK_SNOW) && (MetaBelow == 7)))
{ {
// If block below is snowable, or it is a thin slow block and has a meta of 7 (full thin snow block), say yay // If block below is snowable, or it is a thin slow block and has a meta of 7 (full thin snow block), say yay
return true; return true;

View File

@ -99,7 +99,7 @@ public:
static bool CanBePlacedOn(BLOCKTYPE a_BlockType, eBlockFace a_BlockFace) static bool CanBePlacedOn(BLOCKTYPE a_BlockType, eBlockFace a_BlockFace)
{ {
if ( !g_BlockFullyOccupiesVoxel[a_BlockType] ) if ( !cBlockInfo::FullyOccupiesVoxel(a_BlockType) )
{ {
return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle return (a_BlockFace == BLOCK_FACE_TOP); // Allow placement only when torch upright (for glass, etc.); exceptions won't even be sent by client, no need to handle
} }
@ -129,7 +129,7 @@ public:
{ {
return Face; return Face;
} }
else if ((g_BlockFullyOccupiesVoxel[BlockInQuestion]) && (i != BLOCK_FACE_BOTTOM)) else if (cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) && (i != BLOCK_FACE_BOTTOM))
{ {
// Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face // Otherwise, if block in that direction is torch placeable and we haven't gotten to it via the bottom face, return that face
return Face; return Face;
@ -163,7 +163,7 @@ public:
// No need to check for upright orientation, it was done when the torch was placed // No need to check for upright orientation, it was done when the torch was placed
return true; return true;
} }
else if ( !g_BlockFullyOccupiesVoxel[BlockInQuestion] ) else if ( !cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) )
{ {
return false; return false;
} }

View File

@ -97,7 +97,7 @@ public:
AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true);
BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn); BLOCKTYPE BlockIsOn; a_Chunk.UnboundedRelGetBlockType(a_RelX, a_RelY, a_RelZ, BlockIsOn);
return (a_RelY > 0) && (g_BlockIsSolid[BlockIsOn]); return (a_RelY > 0) && cBlockInfo::IsSolid(BlockIsOn);
} }
}; };

View File

@ -70,7 +70,7 @@ public:
/// Returns true if the specified block type is good for vines to attach to /// Returns true if the specified block type is good for vines to attach to
static bool IsBlockAttachable(BLOCKTYPE a_BlockType) static bool IsBlockAttachable(BLOCKTYPE a_BlockType)
{ {
return (a_BlockType == E_BLOCK_LEAVES) || g_BlockIsSolid[a_BlockType]; return (a_BlockType == E_BLOCK_LEAVES) || cBlockInfo::IsSolid(a_BlockType);
} }

View File

@ -883,7 +883,7 @@ void cChunk::ApplyWeatherToTop()
FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1); FastSetBlock(X, Height, Z, E_BLOCK_SNOW, TopMeta - 1);
} }
} }
else if (g_BlockIsSnowable[TopBlock]) else if (cBlockInfo::IsSnowable(TopBlock))
{ {
SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0); SetBlock(X, Height + 1, Z, E_BLOCK_SNOW, 0);
} }
@ -1540,10 +1540,10 @@ void cChunk::FastSetBlock(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockT
SetNibble(m_BlockMeta, index, a_BlockMeta); SetNibble(m_BlockMeta, index, a_BlockMeta);
// ONLY recalculate lighting if it's necessary! // ONLY recalculate lighting if it's necessary!
if( if (
(g_BlockLightValue[OldBlockType ] != g_BlockLightValue[a_BlockType]) || (cBlockInfo::GetLightValue (OldBlockType) != cBlockInfo::GetLightValue (a_BlockType)) ||
(g_BlockSpreadLightFalloff[OldBlockType] != g_BlockSpreadLightFalloff[a_BlockType]) || (cBlockInfo::GetSpreadLightFalloff(OldBlockType) != cBlockInfo::GetSpreadLightFalloff(a_BlockType)) ||
(g_BlockTransparent[OldBlockType] != g_BlockTransparent[a_BlockType]) (cBlockInfo::IsTransparent (OldBlockType) != cBlockInfo::IsTransparent (a_BlockType))
) )
{ {
m_IsLightValid = false; m_IsLightValid = false;

View File

@ -819,7 +819,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc
if ( if (
(m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately (m_Player->IsGameModeCreative()) || // In creative mode, digging is done immediately
g_BlockOneHitDig[a_OldBlock] // One-hit blocks get destroyed immediately, too cBlockInfo::IsOneHitDig(a_OldBlock) // One-hit blocks get destroyed immediately, too
) )
{ {
HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta); HandleBlockDigFinished(a_BlockX, a_BlockY, a_BlockZ, a_BlockFace, a_OldBlock, a_OldMeta);

View File

@ -654,7 +654,7 @@ namespace ItemCategory
inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType) inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType)
{ {
if(!IsValidBlock(a_BlockType)) return false; if(!IsValidBlock(a_BlockType)) return false;
return g_BlockRequiresSpecialTool[a_BlockType]; return cBlockInfo::RequiresSpecialTool(a_BlockType);
} }

View File

@ -582,11 +582,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR; BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
if (!g_BlockIsSolid[BlockIn]) // Making sure we are not inside a solid block if (!cBlockInfo::IsSolid(BlockIn)) // Making sure we are not inside a solid block
{ {
if (m_bOnGround) // check if it's still on the ground if (m_bOnGround) // check if it's still on the ground
{ {
if (!g_BlockIsSolid[BlockBelow]) // Check if block below is air or water. if (!cBlockInfo::IsSolid(BlockBelow)) // Check if block below is air or water.
{ {
m_bOnGround = false; m_bOnGround = false;
} }
@ -616,7 +616,7 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
// The pickup is too close to an unloaded chunk, bail out of any physics handling // The pickup is too close to an unloaded chunk, bail out of any physics handling
return; return;
} }
if (!g_BlockIsSolid[GotBlock]) if (!cBlockInfo::IsSolid(GotBlock))
{ {
NextPos.x += gCrossCoords[i].x; NextPos.x += gCrossCoords[i].x;
NextPos.z += gCrossCoords[i].z; NextPos.z += gCrossCoords[i].z;

View File

@ -720,7 +720,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
if (GetSpeedZ() > 0) if (GetSpeedZ() > 0)
{ {
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ()));
if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{ {
// We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P // We could try to detect a block in front based purely on coordinates, but xoft made a bounding box system - why not use? :P
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1); cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)ceil(GetPosZ())), 0.5, 1);
@ -737,7 +737,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
else if (GetSpeedZ() < 0) else if (GetSpeedZ() < 0)
{ {
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1); BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1);
if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{ {
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1); cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) - 1), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight());
@ -757,7 +757,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
if (GetSpeedX() > 0) if (GetSpeedX() > 0)
{ {
BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()));
if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{ {
cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); cBoundingBox bbBlock(Vector3d((int)ceil(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); cBoundingBox bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());
@ -773,7 +773,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
else if (GetSpeedX() < 0) else if (GetSpeedX() < 0)
{ {
BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ()));
if (!IsBlockRail(Block) && g_BlockIsSolid[Block]) if (!IsBlockRail(Block) && cBlockInfo::IsSolid(Block))
{ {
cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1); cBoundingBox bbBlock(Vector3d((int)floor(GetPosX()) - 1, (int)floor(GetPosY()), (int)floor(GetPosZ())), 0.5, 1);
cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); cBoundingBox bbMinecart(Vector3d(GetPosX() - 1, floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight());
@ -798,10 +798,10 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta)
BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); BLOCKTYPE BlockZM = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1);
BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); BLOCKTYPE BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1);
if ( if (
(!IsBlockRail(BlockXM) && g_BlockIsSolid[BlockXM]) || (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) ||
(!IsBlockRail(BlockXP) && g_BlockIsSolid[BlockXP]) || (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) ||
(!IsBlockRail(BlockZM) && g_BlockIsSolid[BlockZM]) || (!IsBlockRail(BlockZM) && cBlockInfo::IsSolid(BlockZM)) ||
(!IsBlockRail(BlockZP) && g_BlockIsSolid[BlockZP]) (!IsBlockRail(BlockZP) && cBlockInfo::IsSolid(BlockZP))
) )
{ {
SetSpeed(0, 0, 0); SetSpeed(0, 0, 0);

View File

@ -1904,7 +1904,7 @@ void cPlayer::Detach()
{ {
for (int z = PosZ - 2; z <= (PosZ + 2); ++z) for (int z = PosZ - 2; z <= (PosZ + 2); ++z)
{ {
if (!g_BlockIsSolid[m_World->GetBlock(x, y, z)] && g_BlockIsSolid[m_World->GetBlock(x, y - 1, z)]) if (!cBlockInfo::IsSolid(m_World->GetBlock(x, y, z)) && cBlockInfo::IsSolid(m_World->GetBlock(x, y - 1, z)))
{ {
TeleportToCoords(x, y, z); TeleportToCoords(x, y, z);
return; return;

View File

@ -50,12 +50,12 @@ protected:
LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)", LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)",
a_BlockType, a_BlockMeta, a_BlockType, a_BlockMeta,
a_BlockX, a_BlockY, a_BlockZ, a_EntryFace, a_BlockX, a_BlockY, a_BlockZ, a_EntryFace,
g_BlockIsSolid[a_BlockType] ? "solid" : "non-solid", cBlockInfo::IsSolid(a_BlockType) ? "solid" : "non-solid",
ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str() ItemToString(cItem(a_BlockType, 1, a_BlockMeta)).c_str()
); );
*/ */
if (g_BlockIsSolid[a_BlockType]) if (cBlockInfo::IsSolid(a_BlockType))
{ {
// The projectile hit a solid block // The projectile hit a solid block
// Calculate the exact hit coords: // Calculate the exact hit coords:

View File

@ -88,7 +88,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc)
{ {
continue; continue;
} }
if (!g_BlockIsSolid[a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ)]) // Only place on solid blocks if (!cBlockInfo::IsSolid(a_ChunkDesc.GetBlockType(PosX, y - 1, PosZ))) // Only place on solid blocks
{ {
continue; continue;
} }
@ -131,7 +131,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a
} }
BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z); BLOCKTYPE BlockBelow = a_ChunkDesc.GetBlockType(x, y - 1, z);
if (!g_BlockIsSolid[BlockBelow]) // Only place on solid blocks if (!cBlockInfo::IsSolid(BlockBelow)) // Only place on solid blocks
{ {
continue; continue;
} }
@ -329,7 +329,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc)
case biFrozenOcean: case biFrozenOcean:
{ {
int Height = a_ChunkDesc.GetHeight(x, z); int Height = a_ChunkDesc.GetHeight(x, z);
if (g_BlockIsSnowable[a_ChunkDesc.GetBlockType(x, Height, z)]) if (cBlockInfo::IsSnowable(a_ChunkDesc.GetBlockType(x, Height, z)))
{ {
a_ChunkDesc.SetBlockType(x, Height + 1, z, E_BLOCK_SNOW); a_ChunkDesc.SetBlockType(x, Height + 1, z, E_BLOCK_SNOW);
a_ChunkDesc.SetHeight(x, z, Height + 1); a_ChunkDesc.SetHeight(x, z, Height + 1);

View File

@ -250,6 +250,7 @@ T Clamp(T a_Value, T a_Min, T a_Max)
#include "ChunkDef.h" #include "ChunkDef.h"
#include "BiomeDef.h" #include "BiomeDef.h"
#include "BlockID.h" #include "BlockID.h"
#include "BlockInfo.h"
#include "Entities/Effects.h" #include "Entities/Effects.h"

View File

@ -27,7 +27,7 @@ public:
BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta
) override ) override
{ {
if (!g_BlockFullyOccupiesVoxel[a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ)]) // Some solid blocks, such as cocoa beans, are not suitable for dust if (!cBlockInfo::FullyOccupiesVoxel(a_World->GetBlock(a_BlockX, a_BlockY - 1, a_BlockZ))) // Some solid blocks, such as cocoa beans, are not suitable for dust
{ {
return false; return false;
} }

View File

@ -391,7 +391,7 @@ void cLightingThread::PrepareBlockLight(void)
int idx = BaseZ + x; int idx = BaseZ + x;
for (int y = m_HeightMap[idx], Index = idx + y * BlocksPerYLayer; y >= 0; y--, Index -= BlocksPerYLayer) for (int y = m_HeightMap[idx], Index = idx + y * BlocksPerYLayer; y >= 0; y--, Index -= BlocksPerYLayer)
{ {
if (g_BlockLightValue[m_BlockTypes[Index]] == 0) if (cBlockInfo::GetLightValue(m_BlockTypes[Index]) == 0)
{ {
continue; continue;
} }
@ -401,7 +401,7 @@ void cLightingThread::PrepareBlockLight(void)
m_SeedIdx1[m_NumSeeds++] = Index; m_SeedIdx1[m_NumSeeds++] = Index;
// Light it up: // Light it up:
m_BlockLight[Index] = g_BlockLightValue[m_BlockTypes[Index]]; m_BlockLight[Index] = cBlockInfo::GetLightValue(m_BlockTypes[Index]);
} }
} }
} }

View File

@ -169,13 +169,13 @@ protected:
ASSERT(a_DstIdx >= 0); ASSERT(a_DstIdx >= 0);
ASSERT(a_DstIdx < (int)ARRAYCOUNT(m_BlockTypes)); ASSERT(a_DstIdx < (int)ARRAYCOUNT(m_BlockTypes));
if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]]) if (a_Light[a_SrcIdx] <= a_Light[a_DstIdx] + cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]))
{ {
// We're not offering more light than the dest block already has // We're not offering more light than the dest block already has
return; return;
} }
a_Light[a_DstIdx] = a_Light[a_SrcIdx] - g_BlockSpreadLightFalloff[m_BlockTypes[a_DstIdx]]; a_Light[a_DstIdx] = a_Light[a_SrcIdx] - cBlockInfo::GetSpreadLightFalloff(m_BlockTypes[a_DstIdx]);
if (!a_IsSeedOut[a_DstIdx]) if (!a_IsSeedOut[a_DstIdx])
{ {
a_IsSeedOut[a_DstIdx] = true; a_IsSeedOut[a_DstIdx] = true;

View File

@ -145,7 +145,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
case cMonster::mtBat: case cMonster::mtBat:
{ {
return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && (!g_BlockTransparent[BlockAbove]); return (a_RelY <= 63) && (BlockLight <= 4) && (SkyLight <= 4) && (TargetBlock == E_BLOCK_AIR) && !cBlockInfo::IsTransparent(BlockAbove);
} }
case cMonster::mtChicken: case cMonster::mtChicken:
@ -157,7 +157,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return ( return (
(TargetBlock == E_BLOCK_AIR) && (TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) &&
(!g_BlockTransparent[BlockBelow]) && (!cBlockInfo::IsTransparent(BlockBelow)) &&
(BlockBelow == E_BLOCK_GRASS) && (BlockBelow == E_BLOCK_GRASS) &&
(SkyLight >= 9) (SkyLight >= 9)
); );
@ -188,7 +188,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
(TargetBlock == E_BLOCK_AIR) && (TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) &&
(BlockTop == E_BLOCK_AIR) && (BlockTop == E_BLOCK_AIR) &&
(!g_BlockTransparent[BlockBelow]) && (!cBlockInfo::IsTransparent(BlockBelow)) &&
(SkyLight <= 7) && (SkyLight <= 7) &&
(BlockLight <= 7) (BlockLight <= 7)
); );
@ -215,7 +215,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
HaveFloor || HaveFloor ||
( (
a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) && a_Chunk->UnboundedRelGetBlockType(a_RelX + x, a_RelY - 1, a_RelZ + z, TargetBlock) &&
!g_BlockTransparent[TargetBlock] !cBlockInfo::IsTransparent(TargetBlock)
) )
); );
} }
@ -230,7 +230,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return ( return (
(TargetBlock == E_BLOCK_AIR) && (TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) &&
(!g_BlockTransparent[BlockBelow]) && (!cBlockInfo::IsTransparent(BlockBelow)) &&
(SkyLight <= 7) && (SkyLight <= 7) &&
(BlockLight <= 7) && (BlockLight <= 7) &&
(m_Random.NextInt(2, a_Biome) == 0) (m_Random.NextInt(2, a_Biome) == 0)
@ -242,7 +242,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return ( return (
(TargetBlock == E_BLOCK_AIR) && (TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) &&
(!g_BlockTransparent[BlockBelow]) && (!cBlockInfo::IsTransparent(BlockBelow)) &&
( (
(a_RelY <= 40) || (a_Biome == biSwampland) (a_RelY <= 40) || (a_Biome == biSwampland)
) )
@ -255,7 +255,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R
return ( return (
(TargetBlock == E_BLOCK_AIR) && (TargetBlock == E_BLOCK_AIR) &&
(BlockAbove == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) &&
(!g_BlockTransparent[BlockBelow]) && (!cBlockInfo::IsTransparent(BlockBelow)) &&
(m_Random.NextInt(20, a_Biome) == 0) (m_Random.NextInt(20, a_Biome) == 0)
); );
} }

View File

@ -148,11 +148,11 @@ void cMonster::TickPathFinding()
BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYPP = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY + 2, gCrossCoords[i].z + PosZ);
BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ); BLOCKTYPE BlockAtYM = m_World->GetBlock(gCrossCoords[i].x + PosX, PosY - 1, gCrossCoords[i].z + PosZ);
if ((!g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) if ((!cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
{ {
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ)); m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY, gCrossCoords[i].z + PosZ));
} }
else if ((g_BlockIsSolid[BlockAtY]) && (!g_BlockIsSolid[BlockAtYP]) && (!g_BlockIsSolid[BlockAtYPP]) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE)) else if ((cBlockInfo::IsSolid(BlockAtY)) && (!cBlockInfo::IsSolid(BlockAtYP)) && (!cBlockInfo::IsSolid(BlockAtYPP)) && (!IsBlockLava(BlockAtYM)) && (BlockAtY != E_BLOCK_FENCE) && (BlockAtY != E_BLOCK_FENCE_GATE))
{ {
m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ)); m_PotentialCoordinates.push_back(Vector3d((gCrossCoords[i].x + PosX), PosY + 1, gCrossCoords[i].z + PosZ));
} }
@ -416,9 +416,9 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
else if (PosY > cChunkDef::Height) else if (PosY > cChunkDef::Height)
PosY = cChunkDef::Height; PosY = cChunkDef::Height;
if (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))]) if (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))))
{ {
while (!g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY > 0)) while (!cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY > 0))
{ {
PosY--; PosY--;
} }
@ -427,7 +427,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ)
} }
else else
{ {
while (g_BlockIsSolid[m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))] && (PosY < cChunkDef::Height)) while (cBlockInfo::IsSolid(m_World->GetBlock((int)floor(a_PosX), PosY, (int)floor(a_PosZ))) && (PosY < cChunkDef::Height))
{ {
PosY++; PosY++;
} }

View File

@ -38,7 +38,7 @@ void cSnowGolem::Tick(float a_Dt, cChunk & a_Chunk)
{ {
BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ())); BLOCKTYPE BlockBelow = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()) - 1, (int) floor(GetPosZ()));
BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ())); BLOCKTYPE Block = m_World->GetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()));
if (Block == E_BLOCK_AIR && g_BlockIsSolid[BlockBelow]) if (Block == E_BLOCK_AIR && cBlockInfo::IsSolid(BlockBelow))
{ {
m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0); m_World->SetBlock((int) floor(GetPosX()), (int) floor(GetPosY()), (int) floor(GetPosZ()), E_BLOCK_SNOW, 0);
} }

View File

@ -242,7 +242,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta)
{ {
UNUSED(a_BlockMeta); UNUSED(a_BlockMeta);
return g_BlockPistonBreakable[a_BlockType]; return cBlockInfo::IsPistonBreakable(a_BlockType);
} }

View File

@ -239,7 +239,7 @@ int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, in
{ {
return m_BurnStepTimeFuel; return m_BurnStepTimeFuel;
} }
IsBlockBelowSolid = g_BlockIsSolid[BlockBelow]; IsBlockBelowSolid = cBlockInfo::IsSolid(BlockBelow);
} }
for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)

View File

@ -566,14 +566,14 @@ void cIncrementalRedstoneSimulator::HandleRedstoneWire(int a_BlockX, int a_Block
{ {
if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above... if ((i >= 4) && (i <= 7)) // If we are currently checking for wire surrounding ourself one block above...
{ {
if (g_BlockIsSolid[m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ)]) // If there is something solid above us (wire cut off)... if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX, a_BlockY + 1, a_BlockZ))) // If there is something solid above us (wire cut off)...
{ {
continue; // We don't receive power from that wire continue; // We don't receive power from that wire
} }
} }
else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us else if ((i >= 8) && (i <= 11)) // See above, but this is for wire below us
{ {
if (g_BlockIsSolid[m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)]) if (cBlockInfo::IsSolid(m_World.GetBlock(a_BlockX + gCrossCoords[i].x, a_BlockY + gCrossCoords[i].y + 1, a_BlockZ + gCrossCoords[i].z)))
{ {
continue; continue;
} }

View File

@ -170,7 +170,7 @@ private:
/* ====== Misc Functions ====== */ /* ====== Misc Functions ====== */
/** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */ /** Returns if a block is viable to be the MiddleBlock of a SetLinkedPowered operation */
inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return g_BlockFullyOccupiesVoxel[Block]; } inline static bool IsViableMiddleBlock(BLOCKTYPE Block) { return cBlockInfo::FullyOccupiesVoxel(Block); }
/** Returns if a block is a mechanism (something that accepts power and does something) */ /** Returns if a block is a mechanism (something that accepts power and does something) */
inline static bool IsMechanism(BLOCKTYPE Block) inline static bool IsMechanism(BLOCKTYPE Block)

View File

@ -226,7 +226,7 @@ bool cTracer::Trace( const Vector3f & a_Start, const Vector3f & a_Direction, int
BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z); BLOCKTYPE BlockID = m_World->GetBlock(pos.x, pos.y, pos.z);
// Block is counted as a collision if we are not doing a line of sight and it is solid, // Block is counted as a collision if we are not doing a line of sight and it is solid,
// or if the block is not air and not water. That way mobs can still see underwater. // or if the block is not air and not water. That way mobs can still see underwater.
if ((!a_LineOfSight && g_BlockIsSolid[BlockID]) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID))) if ((!a_LineOfSight && cBlockInfo::IsSolid(BlockID)) || (a_LineOfSight && (BlockID != E_BLOCK_AIR) && !IsBlockWater(BlockID)))
{ {
BlockHitPosition = pos; BlockHitPosition = pos;
int Normal = GetHitNormal(a_Start, End, pos ); int Normal = GetHitNormal(a_Start, End, pos );