summaryrefslogtreecommitdiffstats
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/Bindings.cpp209
-rw-r--r--source/Bindings.h2
-rw-r--r--source/BlockArea.cpp130
-rw-r--r--source/BlockArea.h24
4 files changed, 360 insertions, 5 deletions
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index eb4d9ef8f..12e16a628 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 02/10/13 14:41:15.
+** Generated automatically by tolua++-1.0.92 on 02/11/13 09:47:05.
*/
#ifndef __cplusplus
@@ -17659,6 +17659,114 @@ static int tolua_AllToLua_cBlockArea_Clear00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: Create of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Create00
+static int tolua_AllToLua_cBlockArea_Create00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_SizeX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_SizeY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_SizeZ = ((int) tolua_tonumber(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Create'", NULL);
+#endif
+ {
+ self->Create(a_SizeX,a_SizeY,a_SizeZ);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Create'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Create of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Create01
+static int tolua_AllToLua_cBlockArea_Create01(lua_State* tolua_S)
+{
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,5,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,6,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_SizeX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_SizeY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_SizeZ = ((int) tolua_tonumber(tolua_S,4,0));
+ int a_DataTypes = ((int) tolua_tonumber(tolua_S,5,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Create'", NULL);
+#endif
+ {
+ self->Create(a_SizeX,a_SizeY,a_SizeZ,a_DataTypes);
+ }
+ }
+ return 0;
+tolua_lerror:
+ return tolua_AllToLua_cBlockArea_Create00(tolua_S);
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: SetOrigin of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_SetOrigin00
+static int tolua_AllToLua_cBlockArea_SetOrigin00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,5,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_OriginX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_OriginY = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_OriginZ = ((int) tolua_tonumber(tolua_S,4,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'SetOrigin'", NULL);
+#endif
+ {
+ self->SetOrigin(a_OriginX,a_OriginY,a_OriginZ);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'SetOrigin'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: Read of class cBlockArea */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Read00
static int tolua_AllToLua_cBlockArea_Read00(lua_State* tolua_S)
@@ -18122,6 +18230,100 @@ static int tolua_AllToLua_cBlockArea_Merge00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: Fill of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Fill00
+static int tolua_AllToLua_cBlockArea_Fill00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,1,&tolua_err) ||
+ !tolua_isnumber(tolua_S,5,1,&tolua_err) ||
+ !tolua_isnumber(tolua_S,6,1,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,7,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_DataTypes = ((int) tolua_tonumber(tolua_S,2,0));
+ unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,3,0));
+ unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,4,0));
+ unsigned char a_BlockLight = (( unsigned char) tolua_tonumber(tolua_S,5,0));
+ unsigned char a_BlockSkyLight = (( unsigned char) tolua_tonumber(tolua_S,6,0x0f));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Fill'", NULL);
+#endif
+ {
+ self->Fill(a_DataTypes,a_BlockType,a_BlockMeta,a_BlockLight,a_BlockSkyLight);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Fill'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: FillRelCuboid of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_FillRelCuboid00
+static int tolua_AllToLua_cBlockArea_FillRelCuboid00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,4,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,5,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,6,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,7,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,8,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,9,0,&tolua_err) ||
+ !tolua_isnumber(tolua_S,10,1,&tolua_err) ||
+ !tolua_isnumber(tolua_S,11,1,&tolua_err) ||
+ !tolua_isnumber(tolua_S,12,1,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,13,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_MinRelX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_MaxRelX = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_MinRelY = ((int) tolua_tonumber(tolua_S,4,0));
+ int a_MaxRelY = ((int) tolua_tonumber(tolua_S,5,0));
+ int a_MinRelZ = ((int) tolua_tonumber(tolua_S,6,0));
+ int a_MaxRelZ = ((int) tolua_tonumber(tolua_S,7,0));
+ int a_DataTypes = ((int) tolua_tonumber(tolua_S,8,0));
+ unsigned char a_BlockType = (( unsigned char) tolua_tonumber(tolua_S,9,0));
+ unsigned char a_BlockMeta = (( unsigned char) tolua_tonumber(tolua_S,10,0));
+ unsigned char a_BlockLight = (( unsigned char) tolua_tonumber(tolua_S,11,0));
+ unsigned char a_BlockSkyLight = (( unsigned char) tolua_tonumber(tolua_S,12,0x0f));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'FillRelCuboid'", NULL);
+#endif
+ {
+ self->FillRelCuboid(a_MinRelX,a_MaxRelX,a_MinRelY,a_MaxRelY,a_MinRelZ,a_MaxRelZ,a_DataTypes,a_BlockType,a_BlockMeta,a_BlockLight,a_BlockSkyLight);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'FillRelCuboid'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* method: SetRelBlockType of class cBlockArea */
#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_SetRelBlockType00
static int tolua_AllToLua_cBlockArea_SetRelBlockType00(lua_State* tolua_S)
@@ -22245,6 +22447,9 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,".call",tolua_AllToLua_cBlockArea_new00_local);
tolua_function(tolua_S,"delete",tolua_AllToLua_cBlockArea_delete00);
tolua_function(tolua_S,"Clear",tolua_AllToLua_cBlockArea_Clear00);
+ tolua_function(tolua_S,"Create",tolua_AllToLua_cBlockArea_Create00);
+ tolua_function(tolua_S,"Create",tolua_AllToLua_cBlockArea_Create01);
+ tolua_function(tolua_S,"SetOrigin",tolua_AllToLua_cBlockArea_SetOrigin00);
tolua_function(tolua_S,"Read",tolua_AllToLua_cBlockArea_Read00);
tolua_function(tolua_S,"Read",tolua_AllToLua_cBlockArea_Read01);
tolua_function(tolua_S,"Write",tolua_AllToLua_cBlockArea_Write00);
@@ -22257,6 +22462,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"Crop",tolua_AllToLua_cBlockArea_Crop00);
tolua_function(tolua_S,"Expand",tolua_AllToLua_cBlockArea_Expand00);
tolua_function(tolua_S,"Merge",tolua_AllToLua_cBlockArea_Merge00);
+ tolua_function(tolua_S,"Fill",tolua_AllToLua_cBlockArea_Fill00);
+ tolua_function(tolua_S,"FillRelCuboid",tolua_AllToLua_cBlockArea_FillRelCuboid00);
tolua_function(tolua_S,"SetRelBlockType",tolua_AllToLua_cBlockArea_SetRelBlockType00);
tolua_function(tolua_S,"SetBlockType",tolua_AllToLua_cBlockArea_SetBlockType00);
tolua_function(tolua_S,"SetRelBlockMeta",tolua_AllToLua_cBlockArea_SetRelBlockMeta00);
diff --git a/source/Bindings.h b/source/Bindings.h
index 1c5011759..d8b6c1c7e 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 02/10/13 14:41:16.
+** Generated automatically by tolua++-1.0.92 on 02/11/13 09:47:06.
*/
/* Exported function */
diff --git a/source/BlockArea.cpp b/source/BlockArea.cpp
index 01c1cf4c1..b87d2ecfa 100644
--- a/source/BlockArea.cpp
+++ b/source/BlockArea.cpp
@@ -134,6 +134,65 @@ void cBlockArea::Clear(void)
+void cBlockArea::Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
+{
+ Clear();
+ int BlockCount = a_SizeX * a_SizeY * a_SizeZ;
+ if ((a_DataTypes & baTypes) != 0)
+ {
+ m_BlockTypes = new BLOCKTYPE[BlockCount];
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockTypes[i] = E_BLOCK_AIR;
+ }
+ }
+ if ((a_DataTypes & baMetas) != 0)
+ {
+ m_BlockMetas = new NIBBLETYPE[BlockCount];
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockMetas[i] = 0;
+ }
+ }
+ if ((a_DataTypes & baLight) != 0)
+ {
+ m_BlockLight = new NIBBLETYPE[BlockCount];
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockLight[i] = 0;
+ }
+ }
+ if ((a_DataTypes & baSkyLight) != 0)
+ {
+ m_BlockSkyLight = new NIBBLETYPE[BlockCount];
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockSkyLight[i] = 0x0f;
+ }
+ }
+ m_SizeX = a_SizeX;
+ m_SizeY = a_SizeY;
+ m_SizeZ = a_SizeZ;
+ m_OriginX = 0;
+ m_OriginY = 0;
+ m_OriginZ = 0;
+}
+
+
+
+
+
+void cBlockArea::SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ)
+{
+ m_OriginX = a_OriginX;
+ m_OriginY = a_OriginY;
+ m_OriginZ = a_OriginZ;
+}
+
+
+
+
+
bool cBlockArea::Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes)
{
// Normalize the coords:
@@ -571,6 +630,77 @@ void cBlockArea::Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_R
+void cBlockArea::Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta, NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight)
+{
+ if ((a_DataTypes & GetDataTypes()) != a_DataTypes)
+ {
+ LOGWARNING("%s: requested datatypes that are not present in the BlockArea object, trimming those away (req 0x%x, stor 0x%x)",
+ __FUNCTION__, a_DataTypes, GetDataTypes()
+ );
+ a_DataTypes = a_DataTypes & GetDataTypes();
+ }
+
+ int BlockCount = GetBlockCount();
+ if ((a_DataTypes & baTypes) != 0)
+ {
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockTypes[i] = a_BlockType;
+ }
+ }
+ if ((a_DataTypes & baMetas) != 0)
+ {
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockMetas[i] = a_BlockMeta;
+ }
+ }
+ if ((a_DataTypes & baLight) != 0)
+ {
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockLight[i] = a_BlockLight;
+ }
+ }
+ if ((a_DataTypes & baSkyLight) != 0)
+ {
+ for (int i = 0; i < BlockCount; i++)
+ {
+ m_BlockSkyLight[i] = a_BlockSkyLight;
+ }
+ }
+}
+
+
+
+
+
+void cBlockArea::FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ,
+ int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta,
+ NIBBLETYPE a_BlockLight, NIBBLETYPE a_BlockSkyLight
+)
+{
+ if ((a_DataTypes & GetDataTypes()) != a_DataTypes)
+ {
+ LOGWARNING("%s: requested datatypes that are not present in the BlockArea object, trimming those away (req 0x%x, stor 0x%x)",
+ __FUNCTION__, a_DataTypes, GetDataTypes()
+ );
+ a_DataTypes = a_DataTypes & GetDataTypes();
+ }
+
+ if ((a_DataTypes & baTypes) != 0)
+ {
+ for (int y = a_MinRelY; y <= a_MaxRelY; y++) for (int z = a_MinRelZ; z <= a_MaxRelZ; z++) for (int x = a_MinRelX; x <= a_MaxRelX; x++)
+ {
+ m_BlockTypes[MakeIndex(x, y, z)] = a_BlockType;
+ } // for x, z, y
+ }
+}
+
+
+
+
+
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
{
if (m_BlockTypes == NULL)
diff --git a/source/BlockArea.h b/source/BlockArea.h
index 787731434..04c4a7d36 100644
--- a/source/BlockArea.h
+++ b/source/BlockArea.h
@@ -57,9 +57,21 @@ public:
/// Clears the data stored to reclaim memory
void Clear(void);
+ /** Creates a new area of the specified size and contents.
+ Origin is set to all zeroes.
+ BlockTypes are set to air, block metas to zero, blocklights to zero and skylights to full light.
+ */
+ void Create(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes = baTypes | baMetas);
+
+ /// Resets the origin. No other changes are made, contents are untouched.
+ void SetOrigin(int a_OriginX, int a_OriginY, int a_OriginZ);
+
/// Reads an area of blocks specified. Returns true if successful. All coords are inclusive.
bool Read(cWorld * a_World, int a_MinBlockX, int a_MaxBlockX, int a_MinBlockY, int a_MaxBlockY, int a_MinBlockZ, int a_MaxBlockZ, int a_DataTypes = baTypes | baMetas);
+ // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write
+ // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again
+
/// Writes the area back into cWorld at the coords specified. Returns true if successful in all chunks, false if only partially / not at all
bool Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a_MinBlockZ, int a_DataTypes = baTypes | baMetas);
@@ -72,9 +84,6 @@ public:
/// For testing purposes only, dumps the area into a file.
void DumpToRawFile(const AString & a_FileName);
- // TODO: Write() is not too good an interface: if it fails, there's no way to repeat only for the parts that didn't write
- // A better way may be to return a list of cBlockAreas for each part that didn't succeed writing, so that the caller may try again
-
/// Loads an area from a .schematic file. Returns true if successful
bool LoadFromSchematicFile(const AString & a_FileName);
@@ -106,6 +115,15 @@ public:
*/
void Merge(const cBlockArea & a_Src, int a_RelX, int a_RelY, int a_RelZ, eMergeStrategy a_Strategy);
+ /// Fills the entire block area with the specified data
+ void Fill(int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0, NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f);
+
+ /// Fills a cuboid inside the block area with the specified data
+ void FillRelCuboid(int a_MinRelX, int a_MaxRelX, int a_MinRelY, int a_MaxRelY, int a_MinRelZ, int a_MaxRelZ,
+ int a_DataTypes, BLOCKTYPE a_BlockType, NIBBLETYPE a_BlockMeta = 0,
+ NIBBLETYPE a_BlockLight = 0, NIBBLETYPE a_BlockSkyLight = 0x0f
+ );
+
// Setters:
void SetRelBlockType (int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType);
void SetBlockType (int a_BlockX, int a_BlockY, int a_BlockZ, BLOCKTYPE a_BlockType);