From 2588f5a605d135bc01996f3a685444dfb37978f8 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 28 Feb 2013 07:42:45 +0000 Subject: Simulators now have direct access to the cChunk object in the WakeUp() call git-svn-id: http://mc-server.googlecode.com/svn/trunk@1227 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/Simulator/SandSimulator.cpp | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) (limited to 'source/Simulator/SandSimulator.cpp') diff --git a/source/Simulator/SandSimulator.cpp b/source/Simulator/SandSimulator.cpp index 69513afef..f9d58f030 100644 --- a/source/Simulator/SandSimulator.cpp +++ b/source/Simulator/SandSimulator.cpp @@ -6,6 +6,8 @@ #include "../BlockID.h" #include "../Defines.h" #include "../FallingBlock.h" +#include "../Chunk.h" + @@ -70,19 +72,29 @@ bool cSandSimulator::IsAllowedBlock( BLOCKTYPE a_BlockType ) -void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z) +void cSandSimulator::AddBlock(int a_BlockX, int a_BlockY, int a_BlockZ, cChunk * a_Chunk) { - if(!IsAllowedBlock(m_World->GetBlock(a_X, a_Y, a_Z))) + // TODO: Optimize this by passing the block type along + int RelX = a_BlockX; + int RelY = a_BlockY; + int RelZ = a_BlockZ; + int ChunkX, ChunkZ; + cChunkDef::AbsoluteToRelative(RelX, RelY, RelZ, ChunkX, ChunkZ); + if (!IsAllowedBlock(a_Chunk->GetBlock(RelX, RelY, RelZ))) + { return; + } - Vector3i Block(a_X, a_Y, a_Z); + Vector3i Block(a_BlockX, a_BlockY, a_BlockZ); //check for duplicates - for( BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr ) + for (BlockList::iterator itr = m_Blocks->begin(); itr != m_Blocks->end(); ++itr) { Vector3i Pos = *itr; - if( Pos.x == a_X && Pos.y == a_Y && Pos.z == a_Z ) + if ((Pos.x == a_BlockX) && (Pos.y == a_BlockY) && (Pos.z == a_BlockZ)) + { return; + } } m_Blocks->push_back(Block); @@ -92,10 +104,10 @@ void cSandSimulator::AddBlock(int a_X, int a_Y, int a_Z) -bool cSandSimulator::IsPassable( BLOCKTYPE a_BlockType ) +bool cSandSimulator::IsPassable(BLOCKTYPE a_BlockType) { - return a_BlockType == E_BLOCK_AIR + return (a_BlockType == E_BLOCK_AIR) || IsBlockWater(a_BlockType) || IsBlockLava(a_BlockType) - || a_BlockType == E_BLOCK_FIRE; + || (a_BlockType == E_BLOCK_FIRE); } -- cgit v1.2.3