diff options
author | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-07 11:45:30 +0100 |
---|---|---|
committer | madmaxoft@gmail.com <madmaxoft@gmail.com@0a769ca7-a7f5-676a-18bf-c427514a06d6> | 2013-02-07 11:45:30 +0100 |
commit | fe7e07d69d3227d6e5cfbeefd88b47b3f5961184 (patch) | |
tree | 1e0b8b33b1b195ad3b90b6c6e81d00240be57291 | |
parent | cBlockArea can now be saved as a .schematic file. (diff) | |
download | cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar.gz cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar.bz2 cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar.lz cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar.xz cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.tar.zst cuberite-fe7e07d69d3227d6e5cfbeefd88b47b3f5961184.zip |
-rw-r--r-- | MCServer/Plugins/Debuggers/Debuggers.lua | 9 | ||||
-rw-r--r-- | source/Bindings.cpp | 70 | ||||
-rw-r--r-- | source/Bindings.h | 2 | ||||
-rw-r--r-- | source/BlockArea.cpp | 45 | ||||
-rw-r--r-- | source/BlockArea.h | 6 |
5 files changed, 127 insertions, 5 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua index c80957511..04f7af3c9 100644 --- a/MCServer/Plugins/Debuggers/Debuggers.lua +++ b/MCServer/Plugins/Debuggers/Debuggers.lua @@ -150,7 +150,7 @@ function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, C end
- -- Rclk with an ender pearl saves a predefined area around the cursor into a .schematic file
+ -- Rclk with an ender pearl saves a predefined area around the cursor into a .schematic file. Also tests area copying
if (Player:GetEquippedItem().m_ItemType == E_ITEM_ENDER_PEARL) then
local Area = cBlockArea();
if not(Area:Read(Player:GetWorld(),
@@ -159,8 +159,11 @@ function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, C LOG("LUA: Area couldn't be read");
return false;
end
- LOG("LUA: Area read, saving now.");
- if not(Area:SaveToSchematicFile("schematics/out.schematic")) then
+ LOG("LUA: Area read, copying now.");
+ local Area2 = cBlockArea();
+ Area2:CopyFrom(Area);
+ LOG("LUA: Copied, now saving.");
+ if not(Area2:SaveToSchematicFile("schematics/test.schematic")) then
LOG("LUA: Cannot save schematic file.");
return false;
end
diff --git a/source/Bindings.cpp b/source/Bindings.cpp index 9843e6578..d3450955e 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/07/13 10:38:08. +** Generated automatically by tolua++-1.0.92 on 02/07/13 11:39:26. */ #ifndef __cplusplus @@ -17825,6 +17825,72 @@ tolua_lerror: } #endif //#ifndef TOLUA_DISABLE +/* method: CopyTo of class cBlockArea */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_CopyTo00 +static int tolua_AllToLua_cBlockArea_CopyTo00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"const cBlockArea",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"cBlockArea",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + const cBlockArea* self = (const cBlockArea*) tolua_tousertype(tolua_S,1,0); + cBlockArea* a_Into = ((cBlockArea*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CopyTo'", NULL); +#endif + { + self->CopyTo(*a_Into); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'CopyTo'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + +/* method: CopyFrom of class cBlockArea */ +#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_CopyFrom00 +static int tolua_AllToLua_cBlockArea_CopyFrom00(lua_State* tolua_S) +{ +#ifndef TOLUA_RELEASE + tolua_Error tolua_err; + if ( + !tolua_isusertype(tolua_S,1,"cBlockArea",0,&tolua_err) || + (tolua_isvaluenil(tolua_S,2,&tolua_err) || !tolua_isusertype(tolua_S,2,"const cBlockArea",0,&tolua_err)) || + !tolua_isnoobj(tolua_S,3,&tolua_err) + ) + goto tolua_lerror; + else +#endif + { + cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0); + const cBlockArea* a_From = ((const cBlockArea*) tolua_tousertype(tolua_S,2,0)); +#ifndef TOLUA_RELEASE + if (!self) tolua_error(tolua_S,"invalid 'self' in function 'CopyFrom'", NULL); +#endif + { + self->CopyFrom(*a_From); + } + } + return 0; +#ifndef TOLUA_RELEASE + tolua_lerror: + tolua_error(tolua_S,"#ferror in function 'CopyFrom'.",&tolua_err); + return 0; +#endif +} +#endif //#ifndef TOLUA_DISABLE + /* method: DumpToRawFile of class cBlockArea */ #ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_DumpToRawFile00 static int tolua_AllToLua_cBlockArea_DumpToRawFile00(lua_State* tolua_S) @@ -21809,6 +21875,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S) tolua_function(tolua_S,"Read",tolua_AllToLua_cBlockArea_Read01); tolua_function(tolua_S,"Write",tolua_AllToLua_cBlockArea_Write00); tolua_function(tolua_S,"Write",tolua_AllToLua_cBlockArea_Write01); + tolua_function(tolua_S,"CopyTo",tolua_AllToLua_cBlockArea_CopyTo00); + tolua_function(tolua_S,"CopyFrom",tolua_AllToLua_cBlockArea_CopyFrom00); tolua_function(tolua_S,"DumpToRawFile",tolua_AllToLua_cBlockArea_DumpToRawFile00); tolua_function(tolua_S,"LoadFromSchematicFile",tolua_AllToLua_cBlockArea_LoadFromSchematicFile00); tolua_function(tolua_S,"SaveToSchematicFile",tolua_AllToLua_cBlockArea_SaveToSchematicFile00); diff --git a/source/Bindings.h b/source/Bindings.h index c58c2044d..5d3bb6014 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/07/13 10:38:08. +** Generated automatically by tolua++-1.0.92 on 02/07/13 11:39:26. */ /* Exported function */ diff --git a/source/BlockArea.cpp b/source/BlockArea.cpp index f7132f50d..11878edeb 100644 --- a/source/BlockArea.cpp +++ b/source/BlockArea.cpp @@ -151,6 +151,51 @@ bool cBlockArea::Write(cWorld * a_World, int a_MinBlockX, int a_MinBlockY, int a +void cBlockArea::CopyTo(cBlockArea & a_Into) const
+{
+ if (&a_Into == this)
+ {
+ LOGWARNING("Trying to copy a cBlockArea into self, ignoring.");
+ return;
+ }
+
+ a_Into.Clear();
+ a_Into.SetSize(m_SizeX, m_SizeY, m_SizeZ, GetDataTypes());
+ a_Into.m_OriginX = m_OriginX;
+ a_Into.m_OriginY = m_OriginY;
+ a_Into.m_OriginZ = m_OriginZ;
+ int BlockCount = GetBlockCount();
+ if (HasBlockTypes())
+ {
+ memcpy(a_Into.m_BlockTypes, m_BlockTypes, BlockCount * sizeof(BLOCKTYPE));
+ }
+ if (HasBlockMetas())
+ {
+ memcpy(a_Into.m_BlockMetas, m_BlockMetas, BlockCount * sizeof(NIBBLETYPE));
+ }
+ if (HasBlockLights())
+ {
+ memcpy(a_Into.m_BlockLight, m_BlockLight, BlockCount * sizeof(NIBBLETYPE));
+ }
+ if (HasBlockSkyLights())
+ {
+ memcpy(a_Into.m_BlockSkyLight, m_BlockSkyLight, BlockCount * sizeof(NIBBLETYPE));
+ }
+}
+
+
+
+
+
+void cBlockArea::CopyFrom(const cBlockArea & a_From)
+{
+ a_From.CopyTo(*this);
+}
+
+
+
+
+
void cBlockArea::DumpToRawFile(const AString & a_FileName)
{
cFile f;
diff --git a/source/BlockArea.h b/source/BlockArea.h index 2c4a9e3ba..ace596be6 100644 --- a/source/BlockArea.h +++ b/source/BlockArea.h @@ -56,6 +56,12 @@ public: /// 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);
+ /// Copies this object's contents into the specified BlockArea.
+ void CopyTo(cBlockArea & a_Into) const;
+
+ /// Copies the contents from the specified BlockArea into this object.
+ void CopyFrom(const cBlockArea & a_From);
+
/// For testing purposes only, dumps the area into a file.
void DumpToRawFile(const AString & a_FileName);
|