summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--MCServer/Plugins/Debuggers/Debuggers.lua31
-rw-r--r--source/Bindings.cpp48
-rw-r--r--source/Bindings.h2
-rw-r--r--source/BlockArea.cpp83
-rw-r--r--source/BlockArea.h9
5 files changed, 168 insertions, 5 deletions
diff --git a/MCServer/Plugins/Debuggers/Debuggers.lua b/MCServer/Plugins/Debuggers/Debuggers.lua
index 3e1a1ba5d..6776fa480 100644
--- a/MCServer/Plugins/Debuggers/Debuggers.lua
+++ b/MCServer/Plugins/Debuggers/Debuggers.lua
@@ -1,7 +1,7 @@
-- Global variables
PLUGIN = {}; -- Reference to own plugin object
-ShouldDumpFunctions = true; -- If set to true, all available functions are logged upon plugin initialization
+ShouldDumpFunctions = false; -- If set to true, all available functions are logged upon plugin initialization
@@ -103,6 +103,35 @@ function OnPlayerUsingItem(Player, BlockX, BlockY, BlockZ, BlockFace, CursorX, C
return true;
end
end
+
+ -- Rclk with a diamond to read a block area, dump it, crop it, dump it again, crop it again...
+ if (Player:GetEquippedItem().m_ItemType == E_ITEM_DIAMOND) then
+ local Area = cBlockArea();
+ Area:Read(Player:GetWorld(),
+ BlockX - 9, BlockX + 9,
+ BlockY - 7, BlockY + 7,
+ BlockZ - 9, BlockZ + 9
+ );
+
+ LOG("Size before cropping: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop0.dat");
+ Area:Crop(2, 3, 0, 0, 0, 0);
+ LOG("Size after cropping 1: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop1.dat");
+ Area:Crop(2, 3, 0, 0, 0, 0);
+ LOG("Size after cropping 2: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop2.dat");
+ Area:Crop(0, 0, 0, 0, 3, 2);
+ LOG("Size after cropping 3: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop3.dat");
+ Area:Crop(0, 0, 3, 2, 0, 0);
+ LOG("Size after cropping 4: " .. Area:GetSizeX() .. " x " .. Area:GetSizeY() .. " x " .. Area:GetSizeZ());
+ Area:DumpToRawFile("crop4.dat");
+
+ LOG("Crop test done");
+ return false;
+ end
+
end
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index ae51e3ee8..188f99259 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/05/13 19:20:01.
+** Generated automatically by tolua++-1.0.92 on 02/06/13 17:53:00.
*/
#ifndef __cplusplus
@@ -17859,6 +17859,49 @@ static int tolua_AllToLua_cBlockArea_DumpToRawFile00(lua_State* tolua_S)
}
#endif //#ifndef TOLUA_DISABLE
+/* method: Crop of class cBlockArea */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cBlockArea_Crop00
+static int tolua_AllToLua_cBlockArea_Crop00(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_isnoobj(tolua_S,8,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ cBlockArea* self = (cBlockArea*) tolua_tousertype(tolua_S,1,0);
+ int a_AddMinX = ((int) tolua_tonumber(tolua_S,2,0));
+ int a_SubMaxX = ((int) tolua_tonumber(tolua_S,3,0));
+ int a_AddMinY = ((int) tolua_tonumber(tolua_S,4,0));
+ int a_SubMaxY = ((int) tolua_tonumber(tolua_S,5,0));
+ int a_AddMinZ = ((int) tolua_tonumber(tolua_S,6,0));
+ int a_SubMaxZ = ((int) tolua_tonumber(tolua_S,7,0));
+#ifndef TOLUA_RELEASE
+ if (!self) tolua_error(tolua_S,"invalid 'self' in function 'Crop'", NULL);
+#endif
+ {
+ self->Crop(a_AddMinX,a_SubMaxX,a_AddMinY,a_SubMaxY,a_AddMinZ,a_SubMaxZ);
+ }
+ }
+ return 0;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Crop'.",&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)
@@ -21253,8 +21296,8 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_constant(tolua_S,"HOOK_CHUNK_AVAILABLE",cPluginManager::HOOK_CHUNK_AVAILABLE);
tolua_constant(tolua_S,"HOOK_CHUNK_GENERATED",cPluginManager::HOOK_CHUNK_GENERATED);
tolua_constant(tolua_S,"HOOK_CHUNK_GENERATING",cPluginManager::HOOK_CHUNK_GENERATING);
- tolua_constant(tolua_S,"HOOK_CHUNK_UNLOADING",cPluginManager::HOOK_CHUNK_UNLOADING);
tolua_constant(tolua_S,"HOOK_CHUNK_UNLOADED",cPluginManager::HOOK_CHUNK_UNLOADED);
+ tolua_constant(tolua_S,"HOOK_CHUNK_UNLOADING",cPluginManager::HOOK_CHUNK_UNLOADING);
tolua_constant(tolua_S,"HOOK_COLLECTING_PICKUP",cPluginManager::HOOK_COLLECTING_PICKUP);
tolua_constant(tolua_S,"HOOK_CRAFTING_NO_RECIPE",cPluginManager::HOOK_CRAFTING_NO_RECIPE);
tolua_constant(tolua_S,"HOOK_DISCONNECT",cPluginManager::HOOK_DISCONNECT);
@@ -21697,6 +21740,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"Write",tolua_AllToLua_cBlockArea_Write00);
tolua_function(tolua_S,"Write",tolua_AllToLua_cBlockArea_Write01);
tolua_function(tolua_S,"DumpToRawFile",tolua_AllToLua_cBlockArea_DumpToRawFile00);
+ tolua_function(tolua_S,"Crop",tolua_AllToLua_cBlockArea_Crop00);
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 aea53fef4..afbeaeaec 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/05/13 19:20:02.
+** Generated automatically by tolua++-1.0.92 on 02/06/13 17:53:01.
*/
/* Exported function */
diff --git a/source/BlockArea.cpp b/source/BlockArea.cpp
index 9253b4788..4f8de925c 100644
--- a/source/BlockArea.cpp
+++ b/source/BlockArea.cpp
@@ -188,6 +188,36 @@ void cBlockArea::DumpToRawFile(const AString & a_FileName)
+void cBlockArea::Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
+{
+ if (HasBlockTypes())
+ {
+ CropBlockTypes(a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
+ }
+ if (HasBlockMetas())
+ {
+ CropNibbles(m_BlockMetas, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
+ }
+ if (HasBlockLights())
+ {
+ CropNibbles(m_BlockLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
+ }
+ if (HasBlockSkyLights())
+ {
+ CropNibbles(m_BlockSkyLight, a_AddMinX, a_SubMaxX, a_AddMinY, a_SubMaxY, a_AddMinZ, a_SubMaxZ);
+ }
+ m_OriginX += a_AddMinX;
+ m_OriginY += a_AddMinY;
+ m_OriginZ += a_AddMinZ;
+ m_SizeX -= a_AddMinX + a_SubMaxX;
+ m_SizeY -= a_AddMinY + a_SubMaxY;
+ m_SizeZ -= a_AddMinZ + a_SubMaxZ;
+}
+
+
+
+
+
void cBlockArea::SetRelBlockType(int a_RelX, int a_RelY, int a_RelZ, BLOCKTYPE a_BlockType)
{
if (m_BlockTypes == NULL)
@@ -459,7 +489,7 @@ bool cBlockArea::SetSize(int a_SizeX, int a_SizeY, int a_SizeZ, int a_DataTypes)
int cBlockArea::MakeIndex(int a_RelX, int a_RelY, int a_RelZ) const
{
- return a_RelX + a_RelZ * m_SizeZ + a_RelY * m_SizeX * m_SizeZ;
+ return a_RelX + a_RelZ * m_SizeX + a_RelY * m_SizeX * m_SizeZ;
}
@@ -718,3 +748,54 @@ void cBlockArea::cChunkReader::BlockSkyLight(const NIBBLETYPE * a_BlockSkyLight)
+
+void cBlockArea::CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
+{
+ int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
+ int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
+ int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
+ BLOCKTYPE * NewBlockTypes = new BLOCKTYPE[NewSizeX * NewSizeY * NewSizeZ];
+ int idx = 0;
+ for (int y = 0; y < NewSizeY; y++)
+ {
+ for (int z = 0; z < NewSizeZ; z++)
+ {
+ for (int x = 0; x < NewSizeX; x++)
+ {
+ int OldIndex = MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ);
+ NewBlockTypes[idx++] = m_BlockTypes[OldIndex];
+ } // for x
+ } // for z
+ } // for y
+ delete m_BlockTypes;
+ m_BlockTypes = NewBlockTypes;
+}
+
+
+
+
+
+void cBlockArea::CropNibbles(NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ)
+{
+ int NewSizeX = GetSizeX() - a_AddMinX - a_SubMaxX;
+ int NewSizeY = GetSizeY() - a_AddMinY - a_SubMaxY;
+ int NewSizeZ = GetSizeZ() - a_AddMinZ - a_SubMaxZ;
+ NIBBLETYPE * NewNibbles = new NIBBLETYPE[NewSizeX * NewSizeY * NewSizeZ];
+ int idx = 0;
+ for (int y = 0; y < NewSizeY; y++)
+ {
+ for (int z = 0; z < NewSizeZ; z++)
+ {
+ for (int x = 0; x < NewSizeX; x++)
+ {
+ NewNibbles[idx++] = a_Array[MakeIndex(x + a_AddMinX, y + a_AddMinY, z + a_AddMinZ)];
+ } // for x
+ } // for z
+ } // for y
+ delete a_Array;
+ a_Array = NewNibbles;
+}
+
+
+
+
diff --git a/source/BlockArea.h b/source/BlockArea.h
index d9b21d933..797c37de6 100644
--- a/source/BlockArea.h
+++ b/source/BlockArea.h
@@ -59,6 +59,9 @@ public:
// 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
+ /// Crops the internal contents by the specified amount of blocks from each border.
+ void Crop(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
+
// 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);
@@ -135,6 +138,8 @@ protected:
virtual void BlockSkyLight(const NIBBLETYPE * a_BlockSkyLight) override;
} ;
+ typedef NIBBLETYPE * NIBBLEARRAY;
+
int m_OriginX;
int m_OriginY;
@@ -157,6 +162,10 @@ protected:
// Basic Getters:
NIBBLETYPE GetRelNibble(int a_RelX, int a_RelY, int a_RelZ, NIBBLETYPE * a_Array) const;
NIBBLETYPE GetNibble (int a_BlockX, int a_BlockY, int a_BlockZ, NIBBLETYPE * a_Array) const;
+
+ // Crop helpers:
+ void CropBlockTypes(int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
+ void CropNibbles (NIBBLEARRAY & a_Array, int a_AddMinX, int a_SubMaxX, int a_AddMinY, int a_SubMaxY, int a_AddMinZ, int a_SubMaxZ);
// tolua_begin
} ;