1
0

Cacti grow by themselves and by bonemeal

git-svn-id: http://mc-server.googlecode.com/svn/trunk@583 0a769ca7-a7f5-676a-18bf-c427514a06d6
This commit is contained in:
madmaxoft@gmail.com
2012-06-09 12:03:49 +00:00
parent 0e236c03f9
commit ec61713221
7 changed files with 83 additions and 6 deletions

View File

@@ -572,6 +572,7 @@ void cChunk::TickBlocks(MTRand & a_TickRandom)
case E_BLOCK_MELON_STEM: TickMelonPumpkin(m_BlockTickX, m_BlockTickY, m_BlockTickZ, Index, ID, a_TickRandom); break;
case E_BLOCK_FARMLAND: TickFarmland (m_BlockTickX, m_BlockTickY, m_BlockTickZ); break;
case E_BLOCK_SUGARCANE: GrowSugarcane (m_BlockTickX, m_BlockTickY, m_BlockTickZ, 1); break;
case E_BLOCK_CACTUS: GrowCactus (m_BlockTickX, m_BlockTickY, m_BlockTickZ, 1); break;
case E_BLOCK_SAPLING:
{
@@ -846,6 +847,52 @@ void cChunk::GrowSugarcane(int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks)
{
UnboundedRelFastSetBlock(a_RelX, Top + i, a_RelZ, E_BLOCK_SUGARCANE, 0);
}
else
{
break;
}
} // for i
}
void cChunk::GrowCactus(int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks)
{
// Check the total height of the sugarcane blocks here:
int Top = a_RelY + 1;
while (
(Top < cChunkDef::Height) &&
(GetBlock(a_RelX, Top, a_RelZ) == E_BLOCK_CACTUS)
)
{
++Top;
}
int Bottom = a_RelY - 1;
while (
(Bottom > 0) &&
(GetBlock(a_RelX, Bottom, a_RelZ) == E_BLOCK_CACTUS)
)
{
--Bottom;
}
// Grow by at most a_NumBlocks, but no more than height 3:
int ToGrow = std::min(a_NumBlocks, 4 - (Top - Bottom));
for (int i = 0; i < ToGrow; i++)
{
BLOCKTYPE BlockType;
NIBBLETYPE BlockMeta;
if (UnboundedRelGetBlock(a_RelX, Top + i, a_RelZ, BlockType, BlockMeta) && (BlockType == E_BLOCK_AIR))
{
// TODO: Check the surrounding blocks, if they aren't air, break the cactus block into pickups (and continue breaking blocks above in the next loop iterations)
UnboundedRelFastSetBlock(a_RelX, Top + i, a_RelZ, E_BLOCK_CACTUS, 0);
}
else
{
break;
}
} // for i
}