6 #include "tolua++/include/tolua++.h" 7 #include "../BlockArea.h" 9 #include "ManualBindings.h" 12 #include "../WorldStorage/SchematicFileSerializer.h" 33 return a_LuaState.
ApiParamError(
"Cannot read the bounds parameters, expected 6 numbers.");
35 return a_StartParam + 6;
43 return a_LuaState.
ApiParamError(
"Cannot read the bounds parameter, expected a cCuboid instance.");
46 return a_StartParam + 1;
55 return a_LuaState.
ApiParamError(
"Cannot read the bounds parameter, expected two Vector3i instances.");
59 return a_StartParam + 2;
81 return a_LuaState.
ApiParamError(
"Cannot read the %s, expected 3 numbers.", a_ParamName);
83 return a_StartParam + 3;
91 return a_LuaState.
ApiParamError(
"Cannot read the %s, expected a Vector3i instance.", a_ParamName);
94 return a_StartParam + 1;
126 return L.
ApiParamError(
"Invalid combination of baDataTypes specified (%d).", dataTypes);
130 if ((size.
x <= 0) || (size.
y <= 0) || (size.
z <= 0))
132 return L.
FApiParamError(
"Invalid sizes, must be greater than zero, got {0}", size);
135 self->Create(size, dataTypes);
169 NIBBLETYPE blockMeta = 0, blockLight = 0, blockSkyLight = 0x0f;
172 return L.
ApiParamError(
"Cannot read the datatypes or block type params");
174 L.
GetStackValues(nextIdx + 2, blockMeta, blockLight, blockSkyLight);
177 return L.
ApiParamError(
"Invalid baDataTypes combination (%d).", dataTypes);
182 bounds.
ClampX(0, self->GetSizeX());
183 bounds.
ClampY(0, self->GetSizeY());
184 bounds.
ClampZ(0, self->GetSizeZ());
187 self->FillRelCuboid(bounds, dataTypes, blockType, blockMeta, blockLight, blockSkyLight);
217 if (!self->IsValidCoords(coords))
220 coords, self->GetOrigin(),
self->GetOrigin() +
self->GetSize() -
Vector3i{1, 1, 1}
225 self->GetBlockTypeMeta(coords.
x, coords.
y, coords.
z, blockType, blockMeta);
226 L.
Push(blockType, blockMeta);
257 L.
Push(self->GetSizeX() - 1,
self->GetSizeY() - 1,
self->GetSizeZ() - 1);
286 if (!self->HasBlockTypes())
288 return L.
ApiParamError(
"The area doesn't contain baTypes datatype");
292 int minRelX, minRelY, minRelZ, maxRelX, maxRelY, maxRelZ;
293 self->GetNonAirCropRelCoords(minRelX, minRelY, minRelZ, maxRelX, maxRelY, maxRelZ, ignoreBlockType);
296 L.
Push(minRelX, minRelY, minRelZ, maxRelX, maxRelY, maxRelZ);
328 L.
Push(self->GetOriginX(),
self->GetOriginY(),
self->GetOriginZ());
356 if (!self->HasBlockTypes())
358 return L.
ApiParamError(
"The area doesn't contain baTypes datatype");
360 if (!self->HasBlockMetas())
362 return L.
ApiParamError(
"The area doesn't contain baMetas datatype");
367 if (!self->IsValidRelCoords(coords))
369 return L.
FApiParamError(
"The coords ({0}) are out of range (max {1}).",
370 coords, self->GetSize() -
Vector3i{1, 1, 1}
375 self->GetRelBlockTypeMeta(coords.
x, coords.
y, coords.
z, blockType, blockMeta);
376 L.
Push(blockType, blockMeta);
407 L.
Push(self->GetSizeX(),
self->GetSizeY(),
self->GetSizeZ());
499 if (world ==
nullptr)
501 return L.
ApiParamError(
"Invalid world instance. The world must be not nil.");
511 return L.
ApiParamError(
"Invalid baDataTypes combination (%d).", dataTypes);
518 FLOGWARNING(
"cBlockArea:Read(): MinBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
526 FLOGWARNING(
"cBlockArea:Read(): MinBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
534 FLOGWARNING(
"cBlockArea:Read(): MaxBlockY less than zero, adjusting to zero. Coords: {0} - {1}",
542 FLOGWARNING(
"cBlockArea:Read(): MaxBlockY more than chunk height, adjusting to chunk height. Coords: {0} - {1}",
550 L.
Push(self->Read(*world, bounds, dataTypes));
583 NIBBLETYPE blockMeta, blockLight, blockSkyLight;
584 L.
GetStackValues(idx, dataTypes, blockType, blockMeta, blockLight, blockSkyLight);
587 return L.
ApiParamError(
"Invalid baDataTypes combination (%d).", dataTypes);
589 if ((self->GetDataTypes() & dataTypes) != dataTypes)
591 return L.
ApiParamError(
"Requested datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x",
592 self->GetDataTypes(), dataTypes
597 self->RelLine(p1, p2, dataTypes, blockType, blockMeta, blockLight, blockSkyLight);
692 if (world ==
nullptr)
694 return L.
ApiParamError(
"Invalid world instance. The world must be not nil.");
708 return L.
ApiParamError(
"Invalid datatype combination (%d).", dataTypes);
710 if ((self->GetDataTypes() & dataTypes) != dataTypes)
712 return L.
ApiParamError(
"Requesting datatypes not present in the cBlockArea. Got only 0x%02x, requested 0x%02x",
713 self->GetDataTypes(), dataTypes
725 LOGWARNING(
"cBlockArea:Write(): MinBlockY less than zero, adjusting to zero");
731 LOGWARNING(
"cBlockArea:Write(): MinBlockY + m_SizeY more than chunk height, adjusting to chunk height");
739 L.
Push(self->Write(*world, coords, dataTypes));
743 L.
Push(self->Write(*world, coords));
760 DataType (
cBlockArea::*Fn)(int, int, int)
const 779 if ((self->GetDataTypes() & DataTypeFlag) == 0)
781 return L.
ApiParamError(
"The area doesn't contain the datatype (%d).", DataTypeFlag);
787 if (!self->IsValidCoords(coords))
789 return L.
FApiParamError(
"The coords ({0}) are out of range ({1} - {2}).",
790 coords, self->GetOrigin(),
self->GetOrigin() +
self->GetSize() -
Vector3i{1, 1, 1}
795 L.
Push((self->*Fn)(coords.
x, coords.
y, coords.
z));
811 DataType (
cBlockArea::*Fn)(int, int, int)
const 830 if ((self->GetDataTypes() & DataTypeFlag) == 0)
832 return L.
ApiParamError(
"The area doesn't contain the datatype (%d).", DataTypeFlag);
838 if (!self->IsValidRelCoords(coords))
840 return L.
ApiParamError(
"The coords ({0}) are out of range ({1}).",
841 coords, self->GetSize()
846 L.
Push((self->*Fn)(coords.
x, coords.
y, coords.
z));
862 void (
cBlockArea::*Fn)(int, int, int, DataType)
881 if ((self->GetDataTypes() & DataTypeFlag) == 0)
883 return L.
ApiParamError(
"The area doesn't contain the datatype (%d).", DataTypeFlag);
889 if (!self->IsValidCoords(coords))
891 return L.
FApiParamError(
"The coords ({0}) are out of range ({1} - {2}).",
892 coords, self->GetOrigin(),
self->GetOrigin() +
self->GetSize() -
Vector3i{1, 1, 1}
899 (
self->*Fn)(coords.
x, coords.
y, coords.
z, data);
915 void (
cBlockArea::*Fn)(int, int, int, DataType)
934 if ((self->GetDataTypes() & DataTypeFlag) == 0)
936 return L.
ApiParamError(
"The area doesn't contain the datatype (%d).", DataTypeFlag);
942 if (!self->IsValidRelCoords(coords))
944 return L.
FApiParamError(
"The coords ({0}) are out of range ({1}).",
945 coords, self->GetSize()
952 (
self->*Fn)(coords.
x, coords.
y, coords.
z, data);
977 if (!self->HasBlockTypes() || !
self->HasBlockMetas())
979 return L.
ApiParamError(
"The area doesn't contain the datatypes baTypes and baMetas.");
985 if (!self->IsValidCoords(coords))
987 return L.
FApiParamError(
"The coords ({0}) are out of range ({1} - {2}).",
988 coords, self->GetOrigin(),
self->GetOrigin() +
self->GetSize() -
Vector3i{1, 1, 1}
996 return L.
ApiParamError(
"Bad number for block type or meta type.");
1000 self->SetBlockTypeMeta(coords.
x, coords.
y, coords.
z, block, meta);
1025 if (!self->HasBlockTypes() || !
self->HasBlockMetas())
1027 return L.
ApiParamError(
"The area doesn't contain the baTypes or baMetas datatypes (0x%02x).", self->GetDataTypes());
1033 if (!self->IsValidRelCoords(coords))
1035 return L.
FApiParamError(
"The coords ({0}) are out of range ({1}).",
1036 coords, self->GetSize()
1044 return L.
ApiParamError(
"Bad number for block type or meta type.");
1048 self->SetRelBlockTypeMeta(coords.
x, coords.
y, coords.
z, block, meta);
1056 void cManualBindings::BindBlockArea(lua_State * a_LuaState)
1058 tolua_beginmodule(a_LuaState,
nullptr);
1059 tolua_beginmodule(a_LuaState,
"cBlockArea");
1061 tolua_function(a_LuaState,
"DoWithBlockEntityAt", DoWithXYZ<cBlockArea, cBlockEntity, &cBlockArea::DoWithBlockEntityAt, &cBlockArea::IsValidCoords>);
1062 tolua_function(a_LuaState,
"DoWithBlockEntityRelAt", DoWithXYZ<cBlockArea, cBlockEntity, &cBlockArea::DoWithBlockEntityRelAt, &cBlockArea::IsValidRelCoords>);
1064 tolua_function(a_LuaState,
"ForEachBlockEntity", ForEach< cBlockArea, cBlockEntity, &cBlockArea::ForEachBlockEntity>);
1065 tolua_function(a_LuaState,
"GetBlockLight", GetBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::GetRelBlockLight>);
1066 tolua_function(a_LuaState,
"GetBlockMeta", GetBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::GetRelBlockMeta>);
1067 tolua_function(a_LuaState,
"GetBlockSkyLight", GetBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::GetRelBlockSkyLight>);
1068 tolua_function(a_LuaState,
"GetBlockType", GetBlock<BLOCKTYPE, cBlockArea::baTypes, &cBlockArea::GetRelBlockType>);
1073 tolua_function(a_LuaState,
"GetRelBlockLight", GetRelBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::GetRelBlockLight>);
1074 tolua_function(a_LuaState,
"GetRelBlockMeta", GetRelBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::GetRelBlockMeta>);
1075 tolua_function(a_LuaState,
"GetRelBlockSkyLight", GetRelBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::GetRelBlockSkyLight>);
1076 tolua_function(a_LuaState,
"GetRelBlockType", GetRelBlock<BLOCKTYPE, cBlockArea::baTypes, &cBlockArea::GetRelBlockType>);
1085 tolua_function(a_LuaState,
"SetBlockType", SetBlock<BLOCKTYPE, cBlockArea::baTypes, &cBlockArea::SetRelBlockType>);
1086 tolua_function(a_LuaState,
"SetBlockMeta", SetBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::SetRelBlockMeta>);
1087 tolua_function(a_LuaState,
"SetBlockLight", SetBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::SetRelBlockLight>);
1088 tolua_function(a_LuaState,
"SetBlockSkyLight", SetBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::SetRelBlockSkyLight>);
1090 tolua_function(a_LuaState,
"SetRelBlockType", SetRelBlock<BLOCKTYPE, cBlockArea::baTypes, &cBlockArea::SetRelBlockType>);
1091 tolua_function(a_LuaState,
"SetRelBlockMeta", SetRelBlock<NIBBLETYPE, cBlockArea::baMetas, &cBlockArea::SetRelBlockMeta>);
1092 tolua_function(a_LuaState,
"SetRelBlockLight", SetRelBlock<NIBBLETYPE, cBlockArea::baLight, &cBlockArea::SetRelBlockLight>);
1093 tolua_function(a_LuaState,
"SetRelBlockSkyLight", SetRelBlock<NIBBLETYPE, cBlockArea::baSkyLight, &cBlockArea::SetRelBlockSkyLight>);
1096 tolua_endmodule(a_LuaState);
1097 tolua_endmodule(a_LuaState);
bool CheckParamString(int a_StartParam, int a_EndParam=-1)
Returns true if the specified parameters on the stack are strings; also logs warning if not...
static int tolua_cBlockArea_LoadFromSchematicFile(lua_State *a_LuaState)
static int tolua_cBlockArea_SetBlockTypeMeta(lua_State *a_LuaState)
static int readCuboidOverloadParams(cLuaState &a_LuaState, int a_StartParam, cCuboid &a_Cuboid)
Reads params that together form a Cuboid.
static int tolua_cBlockArea_GetSize(lua_State *a_LuaState)
static bool SaveToSchematicString(const cBlockArea &a_BlockArea, AString &a_Out)
Saves the area into a string containing the .schematic file data.
unsigned char BLOCKTYPE
The datatype used by blockdata.
int FApiParamError(const char *a_MsgFormat, const Args &...a_Args)
Formats and prints the message using python-style format specifiers, but prefixed with the current fu...
static bool LoadFromSchematicFile(cBlockArea &a_BlockArea, const AString &a_FileName)
Loads an area from a .schematic file.
static int tolua_cBlockArea_SetRelBlockTypeMeta(lua_State *a_LuaState)
static int tolua_cBlockArea_Create(lua_State *a_LuaState)
Binding for the cBlockArea::Create() functions.
bool CheckParamSelf(const char *a_SelfClassName)
Returns true if the first parameter is an instance of the expected class name.
void LogStackTrace(int a_StartingDepth=0)
Logs all items in the current stack trace to the server console.
bool GetStackValue(int a_StackPos, AString &a_Value)
unsigned char NIBBLETYPE
The datatype used by nibbledata (meta, light, skylight)
static int tolua_cBlockArea_GetBlockTypeMeta(lua_State *a_LuaState)
Encapsulates a Lua state and provides some syntactic sugar for common operations. ...
static int tolua_cBlockArea_GetCoordRange(lua_State *a_LuaState)
bool CheckParamUserType(int a_StartParam, const char *a_UserType, int a_EndParam=-1)
Returns true if the specified parameters on the stack are of the specified usertype; also logs warnin...
static int SetBlock(lua_State *a_LuaState)
Templated bindings for the SetBlock___() functions.
bool CheckParamEnd(int a_Param)
Returns true if the specified parameter on the stack is nil (indicating an end-of-parameters) ...
static int tolua_cBlockArea_RelLine(lua_State *a_LuaState)
Bindings for the cBlockArea:RelLine() functions.
static int tolua_cBlockArea_Write(lua_State *a_LuaState)
Bindings for the cBlockArea:Write() functions.
static bool SaveToSchematicFile(const cBlockArea &a_BlockArea, const AString &a_FileName)
Saves the area into a .schematic file.
static int tolua_cBlockArea_GetOrigin(lua_State *a_LuaState)
void ClampX(int a_MinX, int a_MaxX)
Clamps both X coords to the specified range.
static int readVector3iOverloadParams(cLuaState &a_LuaState, int a_StartParam, Vector3i &a_Coords, const char *a_ParamName)
Reads params that together form a Vector3i.
void LOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
static int tolua_cBlockArea_GetNonAirCropRelCoords(lua_State *a_LuaState)
void FLOGWARNING(const char *a_Format, fmt::ArgList a_ArgList)
static int tolua_cBlockArea_Read(lua_State *a_LuaState)
Bindings for the cBlockArea:Read() functions.
static bool LoadFromSchematicString(cBlockArea &a_BlockArea, const AString &a_SchematicData)
Loads an area from a string containing the .schematic file data.
void ClampZ(int a_MinZ, int a_MaxZ)
Clamps both Z coords to the specified range.
static int tolua_cBlockArea_SaveToSchematicFile(lua_State *a_LuaState)
bool IsParamNumber(int a_Param)
static int tolua_cBlockArea_FillRelCuboid(lua_State *a_LuaState)
Bindings for the cBlockArea:FillRelCuboid() functions.
static int GetBlock(lua_State *a_LuaState)
Templated bindings for the GetBlock___() functions.
static int tolua_cBlockArea_SaveToSchematicString(lua_State *a_LuaState)
bool IsParamUserType(int a_Param, AString a_UserType)
static int tolua_cBlockArea_LoadFromSchematicString(lua_State *a_LuaState)
void ClampY(int a_MinY, int a_MaxY)
Clamps both Y coords to the specified range.
bool GetStackValues(int a_StartStackPos, Arg1 &&a_Arg1, Args &&...args)
Retrieves a list of values from the Lua stack, starting at the specified index.
static bool IsValidDataTypeCombination(int a_DataTypes)
Returns true if the datatype combination is valid.
void Push(Arg1 &&a_Arg1, Arg2 &&a_Arg2, Args &&...a_Args)
Pushes multiple arguments onto the Lua stack.
static int SetRelBlock(lua_State *a_LuaState)
Templated bindings for the SetRelBlock___() functions.
static int tolua_cBlockArea_GetRelBlockTypeMeta(lua_State *a_LuaState)
static int GetRelBlock(lua_State *a_LuaState)
Templated bindings for the GetRelBlock___() functions.
int ApiParamError(fmt::StringRef a_Msg)
Prints the message, prefixed with the current function name, then logs the stack contents and raises ...