summaryrefslogtreecommitdiffstats
path: root/src/Bindings/ManualBindings_World.cpp
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-06-06 18:24:24 +0200
committerTiger Wang <ziwei.tiger@outlook.com>2021-06-28 22:54:21 +0200
commit81f63b6a09a3cd6c75568efae0fd596f734fcc1c (patch)
tree395e0f4611de830ba0727461a75af6b6d270a1ab /src/Bindings/ManualBindings_World.cpp
parentProtocol: use dedicated packet for 1 block change (diff)
downloadcuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar.gz
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar.bz2
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar.lz
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar.xz
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.tar.zst
cuberite-81f63b6a09a3cd6c75568efae0fd596f734fcc1c.zip
Diffstat (limited to 'src/Bindings/ManualBindings_World.cpp')
-rw-r--r--src/Bindings/ManualBindings_World.cpp63
1 files changed, 61 insertions, 2 deletions
diff --git a/src/Bindings/ManualBindings_World.cpp b/src/Bindings/ManualBindings_World.cpp
index c3588c914..25164f958 100644
--- a/src/Bindings/ManualBindings_World.cpp
+++ b/src/Bindings/ManualBindings_World.cpp
@@ -1427,9 +1427,9 @@ static int tolua_cWorld_QueueTask(lua_State * tolua_S)
static int tolua_cWorld_SetBlock(lua_State * tolua_S)
{
/* Function signature:
- World:SetBlock(BlockX, BlockY, BlockZ)
+ World:SetBlock(BlockX, BlockY, BlockZ, BlockType, BlockMeta)
--or--
- World:SetBlock(Position)
+ World:SetBlock(Position, BlockType, BlockMeta)
*/
cLuaState L(tolua_S);
@@ -1483,6 +1483,64 @@ static int tolua_cWorld_SetBlock(lua_State * tolua_S)
+static int tolua_cWorld_SetBlockMeta(lua_State * tolua_S)
+{
+ /* Function signature:
+ World:SetBlockMeta(BlockX, BlockY, BlockZ, BlockMeta)
+ --or--
+ World:SetBlockMeta(Position, BlockMeta)
+ */
+
+ cLuaState L(tolua_S);
+ int OffsetIndex;
+ if (
+ !L.CheckParamSelf("cWorld") ||
+ !CheckParamVectorOr3Numbers(L, "Vector3<int>", 2, OffsetIndex) ||
+ !L.CheckParamNumber(OffsetIndex) ||
+ !L.CheckParamEnd(OffsetIndex + 1)
+ )
+ {
+ return 0;
+ }
+
+ if (OffsetIndex != 3) // Not the vector overload
+ {
+ L.LogStackTrace();
+ LOGWARN("SetBlockMeta with 3 position arguments is deprecated, use vector-parametered version instead.");
+ }
+
+ cWorld * World;
+ Vector3i Position;
+ NIBBLETYPE Meta;
+
+ // Read the params:
+ if (
+ !L.GetStackValue(1, World) ||
+ !GetStackVectorOr3Numbers(L, 2, Position) ||
+ !L.GetStackValue(OffsetIndex, Meta)
+ )
+ {
+ return 0;
+ }
+
+ if (World == nullptr)
+ {
+ return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'self'");
+ }
+
+ if (!cChunkDef::IsValidHeight(Position.y))
+ {
+ return cManualBindings::lua_do_error(tolua_S, "Error in function call '#funcname#': Invalid 'position'");
+ }
+
+ World->SetBlockMeta(Position, Meta);
+ return 0;
+}
+
+
+
+
+
static int tolua_cWorld_SetSignLines(lua_State * tolua_S)
{
// Exported manually, because tolua would generate useless additional return values (a_Line1 .. a_Line4)
@@ -1725,6 +1783,7 @@ void cManualBindings::BindWorld(lua_State * tolua_S)
tolua_function(tolua_S, "QueueTask", tolua_cWorld_QueueTask);
tolua_function(tolua_S, "ScheduleTask", tolua_cWorld_ScheduleTask);
tolua_function(tolua_S, "SetBlock", tolua_cWorld_SetBlock);
+ tolua_function(tolua_S, "SetBlockMeta", tolua_cWorld_SetBlockMeta);
tolua_function(tolua_S, "SetSignLines", tolua_cWorld_SetSignLines);
tolua_function(tolua_S, "SetTimeOfDay", tolua_cWorld_SetTimeOfDay);
tolua_function(tolua_S, "SpawnSplitExperienceOrbs", tolua_cWorld_SpawnSplitExperienceOrbs);