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:
parent
0e236c03f9
commit
ec61713221
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on Fri Jun 8 03:43:28 2012.
|
** Generated automatically by tolua++-1.0.92 on 06/09/12 14:03:09.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
@ -10276,10 +10276,11 @@ static int tolua_AllToLua_cWorld_GrowPlant00(lua_State* tolua_S)
|
|||||||
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GrowPlant'", NULL);
|
if (!self) tolua_error(tolua_S,"invalid 'self' in function 'GrowPlant'", NULL);
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
self->GrowPlant(a_BlockX,a_BlockY,a_BlockZ);
|
bool tolua_ret = (bool) self->GrowPlant(a_BlockX,a_BlockY,a_BlockZ);
|
||||||
|
tolua_pushboolean(tolua_S,(bool)tolua_ret);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 1;
|
||||||
#ifndef TOLUA_RELEASE
|
#ifndef TOLUA_RELEASE
|
||||||
tolua_lerror:
|
tolua_lerror:
|
||||||
tolua_error(tolua_S,"#ferror in function 'GrowPlant'.",&tolua_err);
|
tolua_error(tolua_S,"#ferror in function 'GrowPlant'.",&tolua_err);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
** Lua binding: AllToLua
|
** Lua binding: AllToLua
|
||||||
** Generated automatically by tolua++-1.0.92 on Fri Jun 8 03:43:28 2012.
|
** Generated automatically by tolua++-1.0.92 on 06/09/12 14:03:09.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Exported function */
|
/* Exported function */
|
||||||
|
@ -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_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_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_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:
|
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);
|
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
|
} // for i
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,6 +238,9 @@ private:
|
|||||||
/// Grows sugarcane by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking)
|
/// Grows sugarcane by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking)
|
||||||
void GrowSugarcane (int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks);
|
void GrowSugarcane (int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks);
|
||||||
|
|
||||||
|
/// Grows cactus by the specified number of blocks, but no more than 3 blocks high (used by both bonemeal and ticking)
|
||||||
|
void GrowCactus (int a_RelX, int a_RelY, int a_RelZ, int a_NumBlocks);
|
||||||
|
|
||||||
/// Grows a melon or a pumpkin next to the block specified (assumed to be the stem)
|
/// Grows a melon or a pumpkin next to the block specified (assumed to be the stem)
|
||||||
void GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, MTRand & a_Random);
|
void GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, MTRand & a_Random);
|
||||||
|
|
||||||
|
@ -1118,6 +1118,23 @@ void cChunkMap::GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_Nu
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void cChunkMap::GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow)
|
||||||
|
{
|
||||||
|
int ChunkX, ChunkZ;
|
||||||
|
cChunkDef::AbsoluteToRelative(a_BlockX, a_BlockY, a_BlockZ, ChunkX, ChunkZ);
|
||||||
|
|
||||||
|
cCSLock Lock(m_CSLayers);
|
||||||
|
cChunkPtr Chunk = GetChunkNoLoad(ChunkX, ZERO_CHUNK_Y, ChunkZ);
|
||||||
|
if (Chunk != NULL)
|
||||||
|
{
|
||||||
|
Chunk->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, a_NumBlocksToGrow);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
|
void cChunkMap::SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ)
|
||||||
{
|
{
|
||||||
int ChunkX, ChunkZ;
|
int ChunkX, ChunkZ;
|
||||||
|
@ -157,6 +157,9 @@ public:
|
|||||||
/// Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height of 3
|
/// Grows a sugarcane present at the block specified by the amount of blocks specified, up to the max height of 3
|
||||||
void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow);
|
void GrowSugarcane(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow);
|
||||||
|
|
||||||
|
/// Grows a cactus present at the block specified by the amount of blocks specified, up to the max height of 3
|
||||||
|
void GrowCactus(int a_BlockX, int a_BlockY, int a_BlockZ, int a_NumBlocksToGrow);
|
||||||
|
|
||||||
/// Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call
|
/// Sets the blockticking to start at the specified block. Only one blocktick per chunk may be set, second call overwrites the first call
|
||||||
void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ);
|
void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ);
|
||||||
|
|
||||||
|
@ -921,6 +921,12 @@ bool cWorld::GrowPlant(int a_BlockX, int a_BlockY, int a_BlockZ)
|
|||||||
m_ChunkMap->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, 3);
|
m_ChunkMap->GrowSugarcane(a_BlockX, a_BlockY, a_BlockZ, 3);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case E_BLOCK_CACTUS:
|
||||||
|
{
|
||||||
|
m_ChunkMap->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, 3);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
} // switch (BlockType)
|
} // switch (BlockType)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user