summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Pioch <lukas@zgow.de>2017-06-26 09:02:06 +0200
committerMattes D <github@xoft.cz>2017-06-26 09:02:06 +0200
commit9c25520b6981b5a30274c8f21ee44735eb6e201b (patch)
treee0d483a0fa6f3dfcd8a7b59e575037d196056583
parentAdded check if datatype is present in block area (#3811) (diff)
downloadcuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar.gz
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar.bz2
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar.lz
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar.xz
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.tar.zst
cuberite-9c25520b6981b5a30274c8f21ee44735eb6e201b.zip
-rw-r--r--Server/Plugins/APIDump/Classes/BlockArea.lua33
-rw-r--r--src/Bindings/ManualBindings_BlockArea.cpp103
2 files changed, 124 insertions, 12 deletions
diff --git a/Server/Plugins/APIDump/Classes/BlockArea.lua b/Server/Plugins/APIDump/Classes/BlockArea.lua
index af6422aa5..e513a0094 100644
--- a/Server/Plugins/APIDump/Classes/BlockArea.lua
+++ b/Server/Plugins/APIDump/Classes/BlockArea.lua
@@ -162,7 +162,7 @@ return
},
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
},
Notes = "Initializes this BlockArea to an empty area of the specified size and origin of {0, 0, 0}. Any previous contents are lost.",
@@ -186,7 +186,7 @@ return
},
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
},
Notes = "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.",
@@ -374,7 +374,7 @@ return
{
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
{
Name = "BlockType",
@@ -410,7 +410,7 @@ return
},
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
{
Name = "BlockType",
@@ -463,7 +463,7 @@ return
},
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
{
Name = "BlockType",
@@ -1053,7 +1053,9 @@ return
},
Returns =
{
- Type = "boolean",
+ {
+ Type = "boolean",
+ },
},
Notes = "Returns true if the specified absolute coords are within the area.",
},
@@ -1067,7 +1069,9 @@ return
},
Returns =
{
- Type = "boolean",
+ {
+ Type = "boolean",
+ },
},
Notes = "Returns true if the specified absolute coords are within the area.",
},
@@ -1075,6 +1079,7 @@ return
IsValidDataTypeCombination =
{
+ IsStatic = true,
Params =
{
{
@@ -1084,7 +1089,9 @@ return
},
Returns =
{
- Type = "boolean",
+ {
+ Type = "boolean",
+ },
},
Notes = "Returns true if the specified combination of datatypes (ba* constants added together) is valid. Most combinations are valid, but for example baBlockEntities without baTypes is an invalid combination.",
}, -- IsValidDataTypeCombination
@@ -1109,7 +1116,9 @@ return
},
Returns =
{
- Type = "boolean",
+ {
+ Type = "boolean",
+ }
},
Notes = "Returns true if the specified relative coords are within the area.",
},
@@ -1123,7 +1132,9 @@ return
},
Returns =
{
- Type = "boolean",
+ {
+ Type = "boolean",
+ }
},
Notes = "Returns true if the specified relative coords are within the area.",
},
@@ -1485,7 +1496,7 @@ return
},
{
Name = "DataTypes",
- Type = "string",
+ Type = "number",
},
{
Name = "BlockType",
diff --git a/src/Bindings/ManualBindings_BlockArea.cpp b/src/Bindings/ManualBindings_BlockArea.cpp
index 33fbdfdc2..506c84072 100644
--- a/src/Bindings/ManualBindings_BlockArea.cpp
+++ b/src/Bindings/ManualBindings_BlockArea.cpp
@@ -841,7 +841,7 @@ static int GetRelBlock(lua_State * a_LuaState)
// Get the block info:
L.Push((self->*Fn)(coords.x, coords.y, coords.z));
- return 0;
+ return 1;
}
@@ -957,6 +957,105 @@ static int SetRelBlock(lua_State * a_LuaState)
+static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
+{
+ // Check the common params:
+ cLuaState L(a_LuaState);
+ if (!L.CheckParamSelf("cBlockArea"))
+ {
+ return 0;
+ }
+
+ // Read the common params:
+ cBlockArea * self;
+ if (!L.GetStackValues(1, self))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "Cannot read the 'self' param.");
+ }
+
+ // Check if block types and metas are present:
+ if (!self->HasBlockTypes() || !self->HasBlockMetas())
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "The area doesn't contain the datatypes baTypes and baMetas.");
+ }
+
+ // Read the overloaded params:
+ Vector3i coords;
+ auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
+ if (!self->IsValidCoords(coords))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "The coords ({%d, %d, %d}) are out of range ({%d, %d, %d} - {%d, %d, %d}).",
+ coords.x, coords.y, coords.z,
+ self->GetOriginX(), self->GetOriginY(), self->GetOriginZ(),
+ self->GetOriginX() + self->GetSizeX() - 1, self->GetOriginY() + self->GetSizeY() - 1, self->GetOriginZ() + self->GetSizeZ() - 1
+ );
+ }
+
+ BLOCKTYPE block;
+ NIBBLETYPE meta;
+ if (!L.GetStackValues(idx, block, meta))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "Bad number for block type or meta type.");
+ }
+
+ // Set block type and meta:
+ self->SetBlockTypeMeta(coords.x, coords.y, coords.z, block, meta);
+ return 0;
+}
+
+
+
+
+
+static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
+{
+ // Check the common params:
+ cLuaState L(a_LuaState);
+ if (!L.CheckParamSelf("cBlockArea"))
+ {
+ return 0;
+ }
+
+ // Read the common params:
+ cBlockArea * self;
+ if (!L.GetStackValues(1, self))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "Cannot read the 'self' param.");
+ }
+
+ // Check if block types and metas are present:
+ if (!self->HasBlockTypes() || !self->HasBlockMetas())
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "The area doesn't contain the datatypes baTypes and baMetas.");
+ }
+
+ // Read the overloaded params:
+ Vector3i coords;
+ auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
+ if (!self->IsValidRelCoords(coords))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "The coords ({%d, %d, %d}) are out of range ({%d, %d, %d}).",
+ coords.x, coords.y, coords.z,
+ self->GetSizeX(), self->GetSizeY(), self->GetSizeZ()
+ );
+ }
+
+ BLOCKTYPE block;
+ NIBBLETYPE meta;
+ if (!L.GetStackValues(idx, block, meta))
+ {
+ return cManualBindings::ApiParamError(a_LuaState, "Bad number for block type or meta type.");
+ }
+
+ // Set block type and meta:
+ self->SetRelBlockTypeMeta(coords.x, coords.y, coords.z, block, meta);
+ return 0;
+}
+
+
+
+
+
void cManualBindings::BindBlockArea(lua_State * a_LuaState)
{
tolua_beginmodule(a_LuaState, nullptr);
@@ -990,10 +1089,12 @@ void cManualBindings::BindBlockArea(lua_State * a_LuaState)
tolua_function(a_LuaState, "SetBlockMeta", SetBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::SetRelBlockMeta>);
tolua_function(a_LuaState, "SetBlockLight", SetBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::SetRelBlockLight>);
tolua_function(a_LuaState, "SetBlockSkyLight", SetBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::SetRelBlockSkyLight>);
+ tolua_function(a_LuaState, "SetBlockTypeMeta", tolua_cBlockArea_SetBlockTypeMeta);
tolua_function(a_LuaState, "SetRelBlockType", SetRelBlock<BLOCKTYPE, cBlockArea::baTypes, &cBlockArea::SetRelBlockType>);
tolua_function(a_LuaState, "SetRelBlockMeta", SetRelBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::SetRelBlockMeta>);
tolua_function(a_LuaState, "SetRelBlockLight", SetRelBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::SetRelBlockLight>);
tolua_function(a_LuaState, "SetRelBlockSkyLight", SetRelBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::SetRelBlockSkyLight>);
+ tolua_function(a_LuaState, "SetRelBlockTypeMeta", tolua_cBlockArea_SetRelBlockTypeMeta);
tolua_function(a_LuaState, "Write", tolua_cBlockArea_Write);
tolua_endmodule(a_LuaState);
tolua_endmodule(a_LuaState);