From a49c004278b0e300521e9cedf44a46ac843a958b Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Sat, 13 Apr 2013 21:02:10 +0000 Subject: Rewritten entities so that they are owned by individual chunks and ticked within their chunk's Tick() git-svn-id: http://mc-server.googlecode.com/svn/trunk@1385 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/FallingBlock.cpp | 44 ++++++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 20 deletions(-) (limited to 'source/FallingBlock.cpp') diff --git a/source/FallingBlock.cpp b/source/FallingBlock.cpp index 5edae6283..db5679454 100644 --- a/source/FallingBlock.cpp +++ b/source/FallingBlock.cpp @@ -4,6 +4,7 @@ #include "World.h" #include "ClientHandle.h" #include "Simulator/SandSimulator.h" +#include "Chunk.h" @@ -40,7 +41,7 @@ void cFallingBlock::SpawnOn(cClientHandle & a_ClientHandle) -void cFallingBlock::Tick(float a_Dt, MTRand & a_TickRandom) +void cFallingBlock::Tick(float a_Dt, cChunk & a_Chunk) { float MilliDt = a_Dt * 0.001f; AddSpeedY(MilliDt * -9.8f); @@ -62,26 +63,29 @@ void cFallingBlock::Tick(float a_Dt, MTRand & a_TickRandom) return; } - if (BlockY < cChunkDef::Height - 1) + if (BlockY >= cChunkDef::Height) { - BLOCKTYPE BlockBelow; - NIBBLETYPE BelowMeta; - GetWorld()->GetBlockTypeMeta(BlockX, BlockY, BlockZ, BlockBelow, BelowMeta); - if (cSandSimulator::DoesBreakFallingThrough(BlockBelow, BelowMeta)) - { - // Fallen onto a block that breaks this into pickups (e. g. half-slab) - // Must finish the fall with coords one below the block: - cSandSimulator::FinishFalling(m_World, BlockX, BlockY, BlockZ, m_BlockType, m_BlockMeta); - Destroy(); - return; - } - else if (!cSandSimulator::CanContinueFallThrough(BlockBelow)) - { - // Fallen onto a solid block - cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta); - Destroy(); - return; - } + // Above the world, just wait for it to fall back down + return; + } + + int idx = a_Chunk.MakeIndexNoCheck(BlockX - a_Chunk.GetPosX() * cChunkDef::Width, BlockY, BlockZ - a_Chunk.GetPosZ() * cChunkDef::Width); + BLOCKTYPE BlockBelow = a_Chunk.GetBlock(idx); + NIBBLETYPE BelowMeta = a_Chunk.GetMeta(idx); + if (cSandSimulator::DoesBreakFallingThrough(BlockBelow, BelowMeta)) + { + // Fallen onto a block that breaks this into pickups (e. g. half-slab) + // Must finish the fall with coords one below the block: + cSandSimulator::FinishFalling(m_World, BlockX, BlockY, BlockZ, m_BlockType, m_BlockMeta); + Destroy(); + return; + } + else if (!cSandSimulator::CanContinueFallThrough(BlockBelow)) + { + // Fallen onto a solid block + cSandSimulator::FinishFalling(m_World, BlockX, BlockY + 1, BlockZ, m_BlockType, m_BlockMeta); + Destroy(); + return; } } -- cgit v1.2.3