diff --git a/src/BlockInfo.cpp b/src/BlockInfo.cpp index 6ae59db53..5fd6d33c1 100644 --- a/src/BlockInfo.cpp +++ b/src/BlockInfo.cpp @@ -7,13 +7,13 @@ -BlockInfo BlockInfo::ms_Info[256]; +cBlockInfo cBlockInfo::ms_Info[256]; -BlockInfo::BlockInfo() +cBlockInfo::cBlockInfo() : m_LightValue(0x00) , m_SpreadLightFalloff(0x0f) , 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); @@ -40,7 +40,7 @@ BlockInfo & BlockInfo::GetById(unsigned int a_ID) -void BlockInfo::Initialize(void) +void cBlockInfo::Initialize(void) { // Emissive blocks ms_Info[E_BLOCK_FIRE ].m_LightValue = 15; @@ -413,7 +413,7 @@ class cBlockInfoInitializer public: cBlockInfoInitializer(void) { - BlockInfo::Initialize(); + cBlockInfo::Initialize(); } } BlockInfoInitializer; diff --git a/src/BlockInfo.h b/src/BlockInfo.h index 1e09b0df5..a06c47a47 100644 --- a/src/BlockInfo.h +++ b/src/BlockInfo.h @@ -6,27 +6,44 @@ -class BlockInfo +class cBlockInfo { public: - BlockInfo(); + cBlockInfo(); /** (Re-)Initializes the internal BlockInfo structures. */ static void Initialize(void); /** 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; + + /** 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; + + /** Does this block require a tool to drop? */ bool m_RequiresSpecialTool; + + /** Is this block solid (player cannot walk through)? */ bool m_IsSolid; + + /** Does this block fully occupy it's voxel - is it a 'full' block? */ bool m_FullyOccupiesVoxel; @@ -34,7 +51,7 @@ public: 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 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 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; } @@ -44,7 +61,7 @@ public: protected: // TODO xdot: Change to std::vector to support dynamic block IDs - static BlockInfo ms_Info[256]; + static cBlockInfo ms_Info[256]; }; diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index ca6850ced..2db9b7ec7 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -101,7 +101,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); 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)); } } ; diff --git a/src/Blocks/BlockCactus.h b/src/Blocks/BlockCactus.h index 83595d2b9..ed441517d 100644 --- a/src/Blocks/BlockCactus.h +++ b/src/Blocks/BlockCactus.h @@ -54,7 +54,7 @@ public: NIBBLETYPE BlockMeta; if ( 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; diff --git a/src/Blocks/BlockDirt.h b/src/Blocks/BlockDirt.h index 91534c5e5..544424a04 100644 --- a/src/Blocks/BlockDirt.h +++ b/src/Blocks/BlockDirt.h @@ -36,7 +36,7 @@ public: if (a_RelY < cChunkDef::Height - 1) { 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); return; @@ -77,7 +77,7 @@ public: BLOCKTYPE AboveDest; NIBBLETYPE 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); } diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index 6a105d5c9..a3e9edc6b 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -91,7 +91,7 @@ public: 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)); } diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 48c7e774b..ef6e102cd 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -102,7 +102,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); 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); } } ; diff --git a/src/Blocks/BlockRail.h b/src/Blocks/BlockRail.h index 52d6f60b3..07e9814cd 100644 --- a/src/Blocks/BlockRail.h +++ b/src/Blocks/BlockRail.h @@ -98,7 +98,7 @@ public: { 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; } @@ -130,7 +130,7 @@ public: // Too close to the edge, cannot simulate return true; } - return g_BlockIsSolid[BlockType]; + return cBlockInfo::IsSolid(BlockType); } } return true; diff --git a/src/Blocks/BlockRedstone.h b/src/Blocks/BlockRedstone.h index 10de96197..a898c9acb 100644 --- a/src/Blocks/BlockRedstone.h +++ b/src/Blocks/BlockRedstone.h @@ -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 { - 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))); } diff --git a/src/Blocks/BlockSnow.h b/src/Blocks/BlockSnow.h index a3daf0393..b21995d3c 100644 --- a/src/Blocks/BlockSnow.h +++ b/src/Blocks/BlockSnow.h @@ -72,7 +72,7 @@ public: BLOCKTYPE BlockBelow = a_Chunk.GetBlock(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 return true; diff --git a/src/Blocks/BlockTorch.h b/src/Blocks/BlockTorch.h index f2a4c8665..84bbb37ec 100644 --- a/src/Blocks/BlockTorch.h +++ b/src/Blocks/BlockTorch.h @@ -99,7 +99,7 @@ public: 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 } @@ -129,7 +129,7 @@ public: { 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 return Face; @@ -163,7 +163,7 @@ public: // No need to check for upright orientation, it was done when the torch was placed return true; } - else if ( !g_BlockFullyOccupiesVoxel[BlockInQuestion] ) + else if ( !cBlockInfo::FullyOccupiesVoxel(BlockInQuestion) ) { return false; } diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index 08fc28327..70a369e69 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -97,7 +97,7 @@ public: AddFaceDirection(a_RelX, a_RelY, a_RelZ, BlockMetaDataToBlockFace(Meta), true); 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); } }; diff --git a/src/Blocks/BlockVine.h b/src/Blocks/BlockVine.h index ee7dcee8a..d8c114284 100644 --- a/src/Blocks/BlockVine.h +++ b/src/Blocks/BlockVine.h @@ -70,7 +70,7 @@ public: /// Returns true if the specified block type is good for vines to attach to 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); } diff --git a/src/Chunk.cpp b/src/Chunk.cpp index 8dfbbeef5..a75828461 100644 --- a/src/Chunk.cpp +++ b/src/Chunk.cpp @@ -883,7 +883,7 @@ void cChunk::ApplyWeatherToTop() 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); } @@ -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); // ONLY recalculate lighting if it's necessary! - if( - (g_BlockLightValue[OldBlockType ] != g_BlockLightValue[a_BlockType]) || - (g_BlockSpreadLightFalloff[OldBlockType] != g_BlockSpreadLightFalloff[a_BlockType]) || - (g_BlockTransparent[OldBlockType] != g_BlockTransparent[a_BlockType]) + if ( + (cBlockInfo::GetLightValue (OldBlockType) != cBlockInfo::GetLightValue (a_BlockType)) || + (cBlockInfo::GetSpreadLightFalloff(OldBlockType) != cBlockInfo::GetSpreadLightFalloff(a_BlockType)) || + (cBlockInfo::IsTransparent (OldBlockType) != cBlockInfo::IsTransparent (a_BlockType)) ) { m_IsLightValid = false; diff --git a/src/ClientHandle.cpp b/src/ClientHandle.cpp index b08ceb5f6..60f14af54 100644 --- a/src/ClientHandle.cpp +++ b/src/ClientHandle.cpp @@ -819,7 +819,7 @@ void cClientHandle::HandleBlockDigStarted(int a_BlockX, int a_BlockY, int a_Bloc if ( (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); diff --git a/src/Defines.h b/src/Defines.h index ba2866f83..31d48860f 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -654,7 +654,7 @@ namespace ItemCategory inline bool BlockRequiresSpecialTool(BLOCKTYPE a_BlockType) { if(!IsValidBlock(a_BlockType)) return false; - return g_BlockRequiresSpecialTool[a_BlockType]; + return cBlockInfo::RequiresSpecialTool(a_BlockType); } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index 8554ab2a5..96e8c15a5 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -582,11 +582,11 @@ void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk) int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width); BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ ); 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 (!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; } @@ -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 return; } - if (!g_BlockIsSolid[GotBlock]) + if (!cBlockInfo::IsSolid(GotBlock)) { NextPos.x += gCrossCoords[i].x; NextPos.z += gCrossCoords[i].z; diff --git a/src/Entities/Minecart.cpp b/src/Entities/Minecart.cpp index d854906b7..f52a7b6d9 100644 --- a/src/Entities/Minecart.cpp +++ b/src/Entities/Minecart.cpp @@ -720,7 +720,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) if (GetSpeedZ() > 0) { 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 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) { 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 bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ() - 1), GetWidth() / 2, GetHeight()); @@ -757,7 +757,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) if (GetSpeedX() > 0) { 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 bbMinecart(Vector3d(GetPosX(), floor(GetPosY()), GetPosZ()), GetWidth() / 2, GetHeight()); @@ -773,7 +773,7 @@ bool cMinecart::TestBlockCollision(NIBBLETYPE a_RailMeta) else if (GetSpeedX() < 0) { 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 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 BlockZP = m_World->GetBlock((int)floor(GetPosX()), (int)floor(GetPosY()), (int)floor(GetPosZ()) + 1); if ( - (!IsBlockRail(BlockXM) && g_BlockIsSolid[BlockXM]) || - (!IsBlockRail(BlockXP) && g_BlockIsSolid[BlockXP]) || - (!IsBlockRail(BlockZM) && g_BlockIsSolid[BlockZM]) || - (!IsBlockRail(BlockZP) && g_BlockIsSolid[BlockZP]) + (!IsBlockRail(BlockXM) && cBlockInfo::IsSolid(BlockXM)) || + (!IsBlockRail(BlockXP) && cBlockInfo::IsSolid(BlockXP)) || + (!IsBlockRail(BlockZM) && cBlockInfo::IsSolid(BlockZM)) || + (!IsBlockRail(BlockZP) && cBlockInfo::IsSolid(BlockZP)) ) { SetSpeed(0, 0, 0); diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 8f94f1feb..42ee14cf3 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1904,7 +1904,7 @@ void cPlayer::Detach() { 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); return; diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index ef82c6e94..03bc0c99d 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -50,12 +50,12 @@ protected: LOGD("Hit block %d:%d at {%d, %d, %d} face %d, %s (%s)", a_BlockType, a_BlockMeta, 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() ); */ - if (g_BlockIsSolid[a_BlockType]) + if (cBlockInfo::IsSolid(a_BlockType)) { // The projectile hit a solid block // Calculate the exact hit coords: diff --git a/src/Generating/FinishGen.cpp b/src/Generating/FinishGen.cpp index 02045f76a..f2d66af70 100644 --- a/src/Generating/FinishGen.cpp +++ b/src/Generating/FinishGen.cpp @@ -88,7 +88,7 @@ void cFinishGenNetherClumpFoliage::GenFinish(cChunkDesc & a_ChunkDesc) { 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; } @@ -131,7 +131,7 @@ void cFinishGenNetherClumpFoliage::TryPlaceClump(cChunkDesc & a_ChunkDesc, int a } 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; } @@ -329,7 +329,7 @@ void cFinishGenSnow::GenFinish(cChunkDesc & a_ChunkDesc) case biFrozenOcean: { 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.SetHeight(x, z, Height + 1); diff --git a/src/Globals.h b/src/Globals.h index e4737a98a..28805a83f 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -250,6 +250,7 @@ T Clamp(T a_Value, T a_Min, T a_Max) #include "ChunkDef.h" #include "BiomeDef.h" #include "BlockID.h" +#include "BlockInfo.h" #include "Entities/Effects.h" diff --git a/src/Items/ItemRedstoneDust.h b/src/Items/ItemRedstoneDust.h index 18c6b8615..274d905a5 100644 --- a/src/Items/ItemRedstoneDust.h +++ b/src/Items/ItemRedstoneDust.h @@ -27,7 +27,7 @@ public: BLOCKTYPE & a_BlockType, NIBBLETYPE & a_BlockMeta ) 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; } diff --git a/src/LightingThread.cpp b/src/LightingThread.cpp index 9c81d004d..44dadb8a9 100644 --- a/src/LightingThread.cpp +++ b/src/LightingThread.cpp @@ -391,7 +391,7 @@ void cLightingThread::PrepareBlockLight(void) int idx = BaseZ + x; 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; } @@ -401,7 +401,7 @@ void cLightingThread::PrepareBlockLight(void) m_SeedIdx1[m_NumSeeds++] = Index; // Light it up: - m_BlockLight[Index] = g_BlockLightValue[m_BlockTypes[Index]]; + m_BlockLight[Index] = cBlockInfo::GetLightValue(m_BlockTypes[Index]); } } } diff --git a/src/LightingThread.h b/src/LightingThread.h index 72d561348..198f27248 100644 --- a/src/LightingThread.h +++ b/src/LightingThread.h @@ -169,13 +169,13 @@ protected: ASSERT(a_DstIdx >= 0); 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 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]) { a_IsSeedOut[a_DstIdx] = true; diff --git a/src/MobSpawner.cpp b/src/MobSpawner.cpp index c86268e63..7704f6cf3 100644 --- a/src/MobSpawner.cpp +++ b/src/MobSpawner.cpp @@ -145,7 +145,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R 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: @@ -157,7 +157,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R return ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (BlockBelow == E_BLOCK_GRASS) && (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) && (BlockAbove == E_BLOCK_AIR) && (BlockTop == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (SkyLight <= 7) && (BlockLight <= 7) ); @@ -215,7 +215,7 @@ bool cMobSpawner::CanSpawnHere(cChunk * a_Chunk, int a_RelX, int a_RelY, int a_R HaveFloor || ( 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 ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (SkyLight <= 7) && (BlockLight <= 7) && (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 ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && ( (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 ( (TargetBlock == E_BLOCK_AIR) && (BlockAbove == E_BLOCK_AIR) && - (!g_BlockTransparent[BlockBelow]) && + (!cBlockInfo::IsTransparent(BlockBelow)) && (m_Random.NextInt(20, a_Biome) == 0) ); } diff --git a/src/Mobs/Monster.cpp b/src/Mobs/Monster.cpp index ac9137ccd..6e3c91d58 100644 --- a/src/Mobs/Monster.cpp +++ b/src/Mobs/Monster.cpp @@ -148,11 +148,11 @@ void cMonster::TickPathFinding() 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); - 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)); } - 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)); } @@ -416,9 +416,9 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) else if (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--; } @@ -427,7 +427,7 @@ int cMonster::FindFirstNonAirBlockPosition(double a_PosX, double a_PosZ) } 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++; } diff --git a/src/Mobs/SnowGolem.cpp b/src/Mobs/SnowGolem.cpp index 67e3a3bb8..c1979a495 100644 --- a/src/Mobs/SnowGolem.cpp +++ b/src/Mobs/SnowGolem.cpp @@ -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 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); } diff --git a/src/Piston.cpp b/src/Piston.cpp index 5eb14451d..b21d576f3 100644 --- a/src/Piston.cpp +++ b/src/Piston.cpp @@ -242,7 +242,7 @@ bool cPiston::CanPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) bool cPiston::CanBreakPush(BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta) { UNUSED(a_BlockMeta); - return g_BlockPistonBreakable[a_BlockType]; + return cBlockInfo::IsPistonBreakable(a_BlockType); } diff --git a/src/Simulator/FireSimulator.cpp b/src/Simulator/FireSimulator.cpp index b77fa1658..6aef97079 100644 --- a/src/Simulator/FireSimulator.cpp +++ b/src/Simulator/FireSimulator.cpp @@ -239,7 +239,7 @@ int cFireSimulator::GetBurnStepTime(cChunk * a_Chunk, int a_RelX, int a_RelY, in { return m_BurnStepTimeFuel; } - IsBlockBelowSolid = g_BlockIsSolid[BlockBelow]; + IsBlockBelowSolid = cBlockInfo::IsSolid(BlockBelow); } for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++) diff --git a/src/Simulator/IncrementalRedstoneSimulator.cpp b/src/Simulator/IncrementalRedstoneSimulator.cpp index 91de9e0cc..0640227b0 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.cpp +++ b/src/Simulator/IncrementalRedstoneSimulator.cpp @@ -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 (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 } } 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; } diff --git a/src/Simulator/IncrementalRedstoneSimulator.h b/src/Simulator/IncrementalRedstoneSimulator.h index e6bc28621..8b7363366 100644 --- a/src/Simulator/IncrementalRedstoneSimulator.h +++ b/src/Simulator/IncrementalRedstoneSimulator.h @@ -170,7 +170,7 @@ private: /* ====== Misc Functions ====== */ /** 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) */ inline static bool IsMechanism(BLOCKTYPE Block) diff --git a/src/Tracer.cpp b/src/Tracer.cpp index ef136302f..968a64439 100644 --- a/src/Tracer.cpp +++ b/src/Tracer.cpp @@ -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); // 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. - 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; int Normal = GetHitNormal(a_Start, End, pos );