summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--source/Bindings.cpp11
-rw-r--r--source/Bindings.h2
-rw-r--r--source/cChunk.cpp47
-rw-r--r--source/cChunk.h3
-rw-r--r--source/cChunkMap.cpp17
-rw-r--r--source/cChunkMap.h3
-rw-r--r--source/cWorld.cpp6
7 files changed, 83 insertions, 6 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 5ad4ab7a9..8f8da6936 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** 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
@@ -13,8 +13,8 @@
/* Exported function */
TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
-#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
-#include "tolua_base.h"
+#include "Globals.h" // NOTE: MSVC stupidness requires this to be the same across all modules
+#include "tolua_base.h"
#include "cTorch.h"
#include "cStairs.h"
#include "cStep.h"
@@ -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);
#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
tolua_lerror:
tolua_error(tolua_S,"#ferror in function 'GrowPlant'.",&tolua_err);
diff --git a/source/Bindings.h b/source/Bindings.h
index a5764b31e..8b68cd874 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** 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 */
diff --git a/source/cChunk.cpp b/source/cChunk.cpp
index 1b70e84d1..526300972 100644
--- a/source/cChunk.cpp
+++ b/source/cChunk.cpp
@@ -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
}
diff --git a/source/cChunk.h b/source/cChunk.h
index d5bc5675e..b92b62ff8 100644
--- a/source/cChunk.h
+++ b/source/cChunk.h
@@ -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)
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)
void GrowMelonPumpkin(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType, MTRand & a_Random);
diff --git a/source/cChunkMap.cpp b/source/cChunkMap.cpp
index 6938c1cb7..a881c71ef 100644
--- a/source/cChunkMap.cpp
+++ b/source/cChunkMap.cpp
@@ -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)
{
int ChunkX, ChunkZ;
diff --git a/source/cChunkMap.h b/source/cChunkMap.h
index 69f0f3830..7ddb094c5 100644
--- a/source/cChunkMap.h
+++ b/source/cChunkMap.h
@@ -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
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
void SetNextBlockTick(int a_BlockX, int a_BlockY, int a_BlockZ);
diff --git a/source/cWorld.cpp b/source/cWorld.cpp
index 7f6390dca..b8e785dd5 100644
--- a/source/cWorld.cpp
+++ b/source/cWorld.cpp
@@ -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);
return true;
}
+
+ case E_BLOCK_CACTUS:
+ {
+ m_ChunkMap->GrowCactus(a_BlockX, a_BlockY, a_BlockZ, 3);
+ return true;
+ }
} // switch (BlockType)
return false;
}