summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings_BlockArea.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/Bindings/ManualBindings_BlockArea.cpp')
-rw-r--r--src/Bindings/ManualBindings_BlockArea.cpp141
1 files changed, 73 insertions, 68 deletions
diff --git a/src/Bindings/ManualBindings_BlockArea.cpp b/src/Bindings/ManualBindings_BlockArea.cpp
index f3f929c53..9958ec3af 100644
--- a/src/Bindings/ManualBindings_BlockArea.cpp
+++ b/src/Bindings/ManualBindings_BlockArea.cpp
@@ -30,7 +30,7 @@ static int readCuboidOverloadParams(cLuaState & a_LuaState, int a_StartParam, cC
// Assume the 6-number version:
if (!a_LuaState.GetStackValues(a_StartParam, a_Cuboid.p1.x, a_Cuboid.p2.x, a_Cuboid.p1.y, a_Cuboid.p2.y, a_Cuboid.p1.z, a_Cuboid.p2.z))
{
- return a_LuaState.ApiParamError("Cannot read the bounds parameters, expected 6 numbers.");
+ return a_LuaState.ApiParamError("Cannot read the bounds parameters, expected 6 numbers");
}
return a_StartParam + 6;
}
@@ -40,7 +40,7 @@ static int readCuboidOverloadParams(cLuaState & a_LuaState, int a_StartParam, cC
cCuboid * c;
if (!a_LuaState.GetStackValues(a_StartParam, c))
{
- return a_LuaState.ApiParamError("Cannot read the bounds parameter, expected a cCuboid instance.");
+ return a_LuaState.ApiParamError("Cannot read the bounds parameter, expected a cCuboid instance");
}
a_Cuboid = *c;
return a_StartParam + 1;
@@ -52,7 +52,7 @@ static int readCuboidOverloadParams(cLuaState & a_LuaState, int a_StartParam, cC
Vector3i * p2;
if (!a_LuaState.GetStackValues(a_StartParam, p1, p2))
{
- return a_LuaState.ApiParamError("Cannot read the bounds parameter, expected two Vector3i instances.");
+ return a_LuaState.ApiParamError("Cannot read the bounds parameter, expected two Vector3i instances");
}
a_Cuboid.p1 = *p1;
a_Cuboid.p2 = *p2;
@@ -78,7 +78,7 @@ static int readVector3iOverloadParams(cLuaState & a_LuaState, int a_StartParam,
// Assume the 3-number version:
if (!a_LuaState.GetStackValues(a_StartParam, a_Coords.x, a_Coords.y, a_Coords.z))
{
- return a_LuaState.ApiParamError("Cannot read the %s, expected 3 numbers.", a_ParamName);
+ return a_LuaState.ApiParamError("Cannot read the %s, expected 3 numbers", a_ParamName);
}
return a_StartParam + 3;
}
@@ -88,7 +88,7 @@ static int readVector3iOverloadParams(cLuaState & a_LuaState, int a_StartParam,
Vector3i * c;
if (!a_LuaState.GetStackValues(a_StartParam, c))
{
- return a_LuaState.ApiParamError("Cannot read the %s, expected a Vector3i instance.", a_ParamName);
+ return a_LuaState.ApiParamError("Cannot read the %s, expected a Vector3i instance", a_ParamName);
}
a_Coords = *c;
return a_StartParam + 1;
@@ -110,11 +110,11 @@ static int tolua_cBlockArea_Create(lua_State * a_LuaState)
cBlockArea * self = nullptr;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read self.");
+ return L.ApiParamError("Cannot read self");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
int dataTypes = cBlockArea::baTypes | cBlockArea::baMetas | cBlockArea::baBlockEntities;
@@ -123,7 +123,7 @@ static int tolua_cBlockArea_Create(lua_State * a_LuaState)
L.GetStackValue(dataTypesIdx, dataTypes);
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
- return L.ApiParamError("Invalid combination of baDataTypes specified (%d).", dataTypes);
+ return L.ApiParamError("Invalid combination of baDataTypes specified (%d)", dataTypes);
}
// Create the area:
@@ -154,16 +154,27 @@ static int tolua_cBlockArea_FillRelCuboid(lua_State * a_LuaState)
cBlockArea * self = nullptr;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read self.");
+ return L.ApiParamError("Cannot read self");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
// Check and get the overloaded params:
cCuboid bounds;
auto nextIdx = readCuboidOverloadParams(L, 2, bounds);
+ bounds.Sort();
+ if (!(self->IsValidRelCoords(bounds.p1) && self->IsValidRelCoords(bounds.p2)))
+ {
+ return L.FApiParamError(
+ "The bounds ({0} - {1}) are out of range ({2} - {3})",
+ bounds.p1,
+ bounds.p2,
+ Vector3i(0, 0, 0),
+ (self->GetSize() - Vector3i{1, 1, 1})
+ );
+ }
int dataTypes = cBlockArea::baTypes | cBlockArea::baMetas | cBlockArea::baBlockEntities;
BLOCKTYPE blockType;
NIBBLETYPE blockMeta = 0, blockLight = 0, blockSkyLight = 0x0f;
@@ -174,15 +185,9 @@ static int tolua_cBlockArea_FillRelCuboid(lua_State * a_LuaState)
L.GetStackValues(nextIdx + 2, blockMeta, blockLight, blockSkyLight); // These values are optional
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
- return L.ApiParamError("Invalid baDataTypes combination (%d).", dataTypes);
+ return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes);
}
- // Check the coords, shift if needed:
- bounds.Sort();
- bounds.ClampX(0, self->GetSizeX());
- bounds.ClampY(0, self->GetSizeY());
- bounds.ClampZ(0, self->GetSizeZ());
-
// Do the actual Fill:
self->FillRelCuboid(bounds, dataTypes, blockType, blockMeta, blockLight, blockSkyLight);
return 0;
@@ -209,14 +214,14 @@ static int tolua_cBlockArea_GetBlockTypeMeta(lua_State * a_LuaState)
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
Vector3i coords;
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.FApiParamError("Coords ({0}) out of range ({1} - {2}).",
+ return L.FApiParamError("Coords ({0}) out of range ({1} - {2})",
coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -247,11 +252,11 @@ static int tolua_cBlockArea_GetCoordRange(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' parameter.");
+ return L.ApiParamError("Cannot read the 'self' parameter");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
L.Push(self->GetSizeX() - 1, self->GetSizeY() - 1, self->GetSizeZ() - 1);
@@ -317,11 +322,11 @@ static int tolua_cBlockArea_GetOrigin(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' parameter.");
+ return L.ApiParamError("Cannot read the 'self' parameter");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
// Push the three origin coords:
@@ -347,11 +352,11 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' parameter.");
+ return L.ApiParamError("Cannot read the 'self' parameter");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
if (!self->HasBlockTypes())
{
@@ -366,8 +371,8 @@ static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range (max {1}).",
- coords, self->GetSize() - Vector3i{1, 1, 1}
+ return L.FApiParamError("The coords ({0}) are out of range (max {1})",
+ coords, (self->GetSize() - Vector3i{1, 1, 1})
);
}
BLOCKTYPE blockType;
@@ -397,11 +402,11 @@ static int tolua_cBlockArea_GetSize(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' parameter.");
+ return L.ApiParamError("Cannot read the 'self' parameter");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
L.Push(self->GetSizeX(), self->GetSizeY(), self->GetSizeZ());
@@ -429,11 +434,11 @@ static int tolua_cBlockArea_LoadFromSchematicFile(lua_State * a_LuaState)
AString fileName;
if (!L.GetStackValues(1, self, fileName))
{
- return L.ApiParamError("Cannot read the parameters.");
+ return L.ApiParamError("Cannot read the parameters");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
L.Push(cSchematicFileSerializer::LoadFromSchematicFile(*self, fileName));
@@ -461,11 +466,11 @@ static int tolua_cBlockArea_LoadFromSchematicString(lua_State * a_LuaState)
AString data;
if (!L.GetStackValues(1, self, data))
{
- return L.ApiParamError("Cannot read the parameters.");
+ return L.ApiParamError("Cannot read the parameters");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
L.Push(cSchematicFileSerializer::LoadFromSchematicString(*self, data));
@@ -494,11 +499,11 @@ static int tolua_cBlockArea_Read(lua_State * a_LuaState)
cWorld * world = nullptr;
if (!L.GetStackValues(1, self, world))
{
- return L.ApiParamError("Cannot read self or world.");
+ return L.ApiParamError("Cannot read self or world");
}
if (world == nullptr)
{
- return L.ApiParamError("Invalid world instance. The world must be not nil.");
+ return L.ApiParamError("Invalid world instance. The world must be not nil");
}
// Check and get the overloaded params:
@@ -508,7 +513,7 @@ static int tolua_cBlockArea_Read(lua_State * a_LuaState)
L.GetStackValues(dataTypesIdx, dataTypes);
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
- return L.ApiParamError("Invalid baDataTypes combination (%d).", dataTypes);
+ return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes);
}
// Check the coords, shift if needed:
@@ -570,7 +575,7 @@ static int tolua_cBlockArea_RelLine(lua_State * a_LuaState)
cBlockArea * self = nullptr;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read self.");
+ return L.ApiParamError("Cannot read self");
}
// Check and get the overloaded params:
@@ -584,7 +589,7 @@ static int tolua_cBlockArea_RelLine(lua_State * a_LuaState)
L.GetStackValues(idx, dataTypes, blockType, blockMeta, blockLight, blockSkyLight);
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
- return L.ApiParamError("Invalid baDataTypes combination (%d).", dataTypes);
+ return L.ApiParamError("Invalid baDataTypes combination (%d)", dataTypes);
}
if ((self->GetDataTypes() & dataTypes) != dataTypes)
{
@@ -619,11 +624,11 @@ static int tolua_cBlockArea_SaveToSchematicFile(lua_State * a_LuaState)
AString fileName;
if (!L.GetStackValues(1, self, fileName))
{
- return L.ApiParamError("Cannot read the parameters.");
+ return L.ApiParamError("Cannot read the parameters");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
L.Push(cSchematicFileSerializer::SaveToSchematicFile(*self, fileName));
@@ -649,11 +654,11 @@ static int tolua_cBlockArea_SaveToSchematicString(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' parameter.");
+ return L.ApiParamError("Cannot read the 'self' parameter");
}
if (self == nullptr)
{
- return L.ApiParamError("Invalid 'self', must not be nil.");
+ return L.ApiParamError("Invalid 'self', must not be nil");
}
AString data;
@@ -687,11 +692,11 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState)
cWorld * world = nullptr;
if (!L.GetStackValues(1, self, world))
{
- return L.ApiParamError("Cannot read self or world.");
+ return L.ApiParamError("Cannot read self or world");
}
if (world == nullptr)
{
- return L.ApiParamError("Invalid world instance. The world must be not nil.");
+ return L.ApiParamError("Invalid world instance. The world must be not nil");
}
// Check and get the overloaded params:
@@ -705,7 +710,7 @@ static int tolua_cBlockArea_Write(lua_State * a_LuaState)
{
if (!cBlockArea::IsValidDataTypeCombination(dataTypes))
{
- return L.ApiParamError("Invalid datatype combination (%d).", dataTypes);
+ return L.ApiParamError("Invalid datatype combination (%d)", dataTypes);
}
if ((self->GetDataTypes() & dataTypes) != dataTypes)
{
@@ -772,13 +777,13 @@ static int GetBlock(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check the datatype's presence:
if ((self->GetDataTypes() & DataTypeFlag) == 0)
{
- return L.ApiParamError("The area doesn't contain the datatype (%d).", DataTypeFlag);
+ return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag);
}
// Read the overloaded params:
@@ -786,7 +791,7 @@ static int GetBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})",
coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -823,13 +828,13 @@ static int GetRelBlock(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check the datatype's presence:
if ((self->GetDataTypes() & DataTypeFlag) == 0)
{
- return L.ApiParamError("The area doesn't contain the datatype (%d).", DataTypeFlag);
+ return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag);
}
// Read the overloaded params:
@@ -837,8 +842,8 @@ static int GetRelBlock(lua_State * a_LuaState)
readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.ApiParamError("The coords ({0}) are out of range ({1}).",
- coords, self->GetSize()
+ return L.ApiParamError("The coords ({0}) are out of range ({1})",
+ coords, (self->GetSize() - Vector3i(1, 1, 1))
);
}
@@ -874,13 +879,13 @@ static int SetBlock(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check the datatype's presence:
if ((self->GetDataTypes() & DataTypeFlag) == 0)
{
- return L.ApiParamError("The area doesn't contain the datatype (%d).", DataTypeFlag);
+ return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag);
}
// Read the overloaded params:
@@ -888,7 +893,7 @@ static int SetBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})",
coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -927,13 +932,13 @@ static int SetRelBlock(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check the datatype's presence:
if ((self->GetDataTypes() & DataTypeFlag) == 0)
{
- return L.ApiParamError("The area doesn't contain the datatype (%d).", DataTypeFlag);
+ return L.ApiParamError("The area doesn't contain the datatype (%d)", DataTypeFlag);
}
// Read the overloaded params:
@@ -941,8 +946,8 @@ static int SetRelBlock(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range ({1}).",
- coords, self->GetSize()
+ return L.FApiParamError("The coords ({0}) are out of range ({1})",
+ coords, (self->GetSize() - Vector3i(1, 1, 1))
);
}
DataType data;
@@ -970,13 +975,13 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check if block types and metas are present:
if (!self->HasBlockTypes() || !self->HasBlockMetas())
{
- return L.ApiParamError("The area doesn't contain the datatypes baTypes and baMetas.");
+ return L.ApiParamError("The area doesn't contain the datatypes baTypes and baMetas");
}
// Read the overloaded params:
@@ -984,7 +989,7 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range ({1} - {2}).",
+ return L.FApiParamError("The coords ({0}) are out of range ({1} - {2})",
coords, self->GetOrigin(), self->GetOrigin() + self->GetSize() - Vector3i{1, 1, 1}
);
}
@@ -993,7 +998,7 @@ static int tolua_cBlockArea_SetBlockTypeMeta(lua_State * a_LuaState)
NIBBLETYPE meta;
if (!L.GetStackValues(idx, block, meta))
{
- return L.ApiParamError("Bad number for block type or meta type.");
+ return L.ApiParamError("Bad number for block type or meta type");
}
// Set block type and meta:
@@ -1018,13 +1023,13 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
cBlockArea * self;
if (!L.GetStackValues(1, self))
{
- return L.ApiParamError("Cannot read the 'self' param.");
+ return L.ApiParamError("Cannot read the 'self' param");
}
// Check if block types and metas are present:
if (!self->HasBlockTypes() || !self->HasBlockMetas())
{
- return L.ApiParamError("The area doesn't contain the baTypes or baMetas datatypes (0x%02x).", self->GetDataTypes());
+ return L.ApiParamError("The area doesn't contain the baTypes or baMetas datatypes (0x%02x)", self->GetDataTypes());
}
// Read the overloaded params:
@@ -1032,8 +1037,8 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
auto idx = readVector3iOverloadParams(L, 2, coords, "coords");
if (!self->IsValidRelCoords(coords))
{
- return L.FApiParamError("The coords ({0}) are out of range ({1}).",
- coords, self->GetSize()
+ return L.FApiParamError("The coords ({0}) are out of range ({1})",
+ coords, (self->GetSize() - Vector3i(1, 1, 1))
);
}
@@ -1041,7 +1046,7 @@ static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State * a_LuaState)
NIBBLETYPE meta;
if (!L.GetStackValues(idx, block, meta))
{
- return L.ApiParamError("Bad number for block type or meta type.");
+ return L.ApiParamError("Bad number for block type or meta type");
}
// Set block type and meta: