X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Fscript%2Fcpp_api%2Fs_node.cpp;h=029cb6308c4386cf619823f4481066e71225cda7;hb=ec9f1575121e3b064b919bca7efddfa8b0fc4e65;hp=23c8f43b97b908080a8b61076ebc4b3fa6327c0e;hpb=d04d8aba7029a2501854a2838fd282b81358a54e;p=minetest.git diff --git a/src/script/cpp_api/s_node.cpp b/src/script/cpp_api/s_node.cpp index 23c8f43b9..029cb6308 100644 --- a/src/script/cpp_api/s_node.cpp +++ b/src/script/cpp_api/s_node.cpp @@ -27,6 +27,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/pointedthing.h" +// Should be ordered exactly like enum NodeDrawType in nodedef.h struct EnumString ScriptApiNode::es_DrawType[] = { {NDT_NORMAL, "normal"}, @@ -34,18 +35,19 @@ struct EnumString ScriptApiNode::es_DrawType[] = {NDT_LIQUID, "liquid"}, {NDT_FLOWINGLIQUID, "flowingliquid"}, {NDT_GLASSLIKE, "glasslike"}, - {NDT_GLASSLIKE_FRAMED, "glasslike_framed"}, - {NDT_GLASSLIKE_FRAMED_OPTIONAL, "glasslike_framed_optional"}, {NDT_ALLFACES, "allfaces"}, {NDT_ALLFACES_OPTIONAL, "allfaces_optional"}, {NDT_TORCHLIKE, "torchlike"}, {NDT_SIGNLIKE, "signlike"}, {NDT_PLANTLIKE, "plantlike"}, - {NDT_FIRELIKE, "firelike"}, {NDT_FENCELIKE, "fencelike"}, {NDT_RAILLIKE, "raillike"}, {NDT_NODEBOX, "nodebox"}, + {NDT_GLASSLIKE_FRAMED, "glasslike_framed"}, + {NDT_FIRELIKE, "firelike"}, + {NDT_GLASSLIKE_FRAMED_OPTIONAL, "glasslike_framed_optional"}, {NDT_MESH, "mesh"}, + {NDT_PLANTLIKE_ROOTED, "plantlike_rooted"}, {0, NULL}, }; @@ -62,6 +64,8 @@ struct EnumString ScriptApiNode::es_ContentParamType2[] = {CPT2_COLOR, "color"}, {CPT2_COLORED_FACEDIR, "colorfacedir"}, {CPT2_COLORED_WALLMOUNTED, "colorwallmounted"}, + {CPT2_GLASSLIKE_LIQUID_LEVEL, "glasslikeliquidlevel"}, + {CPT2_COLORED_DEGROTATE, "colordegrotate"}, {0, NULL}, }; @@ -90,23 +94,25 @@ struct EnumString ScriptApiNode::es_NodeBoxType[] = {0, NULL}, }; -ScriptApiNode::ScriptApiNode() { -} - -ScriptApiNode::~ScriptApiNode() { -} +struct EnumString ScriptApiNode::es_TextureAlphaMode[] = + { + {ALPHAMODE_OPAQUE, "opaque"}, + {ALPHAMODE_CLIP, "clip"}, + {ALPHAMODE_BLEND, "blend"}, + {0, NULL}, + }; bool ScriptApiNode::node_on_punch(v3s16 p, MapNode node, - ServerActiveObject *puncher, PointedThing pointed) + ServerActiveObject *puncher, const PointedThing &pointed) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_punch")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_punch", &p)) return false; // Call function @@ -126,19 +132,24 @@ bool ScriptApiNode::node_on_dig(v3s16 p, MapNode node, int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_dig")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_dig", &p)) return false; // Call function push_v3s16(L, p); pushnode(L, node, ndef); objectrefGetOrCreate(L, digger); - PCALL_RES(lua_pcall(L, 3, 0, error_handler)); - lua_pop(L, 1); // Pop error handler - return true; + PCALL_RES(lua_pcall(L, 3, 1, error_handler)); + + // nil is treated as true for backwards compat + bool result = lua_isnil(L, -1) || lua_toboolean(L, -1); + + lua_pop(L, 2); // Pop error handler and result + + return result; } void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) @@ -147,10 +158,10 @@ void ScriptApiNode::node_on_construct(v3s16 p, MapNode node) int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_construct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_construct", &p)) return; // Call function @@ -165,10 +176,10 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node) int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_destruct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_destruct", &p)) return; // Call function @@ -177,16 +188,37 @@ void ScriptApiNode::node_on_destruct(v3s16 p, MapNode node) lua_pop(L, 1); // Pop error handler } +bool ScriptApiNode::node_on_flood(v3s16 p, MapNode node, MapNode newnode) +{ + SCRIPTAPI_PRECHECKHEADER + + int error_handler = PUSH_ERROR_HANDLER(L); + + const NodeDefManager *ndef = getServer()->ndef(); + + // Push callback function on stack + if (!getItemCallback(ndef->get(node).name.c_str(), "on_flood", &p)) + return false; + + // Call function + push_v3s16(L, p); + pushnode(L, node, ndef); + pushnode(L, newnode, ndef); + PCALL_RES(lua_pcall(L, 3, 1, error_handler)); + lua_remove(L, error_handler); + return readParam(L, -1, false); +} + void ScriptApiNode::node_after_destruct(v3s16 p, MapNode node) { SCRIPTAPI_PRECHECKHEADER int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "after_destruct")) + if (!getItemCallback(ndef->get(node).name.c_str(), "after_destruct", &p)) return; // Call function @@ -202,10 +234,10 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime) int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_timer")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_timer", &p)) return false; // Call function @@ -213,7 +245,7 @@ bool ScriptApiNode::node_on_timer(v3s16 p, MapNode node, f32 dtime) lua_pushnumber(L,dtime); PCALL_RES(lua_pcall(L, 2, 1, error_handler)); lua_remove(L, error_handler); - return (bool) lua_isboolean(L, -1) && (bool) lua_toboolean(L, -1) == true; + return readParam(L, -1, false); } void ScriptApiNode::node_on_receive_fields(v3s16 p, @@ -225,15 +257,15 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p, int error_handler = PUSH_ERROR_HANDLER(L); - INodeDefManager *ndef = getServer()->ndef(); + const NodeDefManager *ndef = getServer()->ndef(); // If node doesn't exist, we don't know what callback to call - MapNode node = getEnv()->getMap().getNodeNoEx(p); + MapNode node = getEnv()->getMap().getNode(p); if (node.getContent() == CONTENT_IGNORE) return; // Push callback function on stack - if (!getItemCallback(ndef->get(node).name.c_str(), "on_receive_fields")) + if (!getItemCallback(ndef->get(node).name.c_str(), "on_receive_fields", &p)) return; // Call function @@ -241,7 +273,7 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p, lua_pushstring(L, formname.c_str()); // formname lua_newtable(L); // fields StringMap::const_iterator it; - for (it = fields.begin(); it != fields.end(); it++) { + for (it = fields.begin(); it != fields.end(); ++it) { const std::string &name = it->first; const std::string &value = it->second; lua_pushstring(L, name.c_str()); @@ -252,27 +284,3 @@ void ScriptApiNode::node_on_receive_fields(v3s16 p, PCALL_RES(lua_pcall(L, 4, 0, error_handler)); lua_pop(L, 1); // Pop error handler } - -void ScriptApiNode::node_falling_update(v3s16 p) -{ - SCRIPTAPI_PRECHECKHEADER - - int error_handler = PUSH_ERROR_HANDLER(L); - - lua_getglobal(L, "nodeupdate"); - push_v3s16(L, p); - PCALL_RES(lua_pcall(L, 1, 0, error_handler)); - lua_pop(L, 1); // Pop error handler -} - -void ScriptApiNode::node_falling_update_single(v3s16 p) -{ - SCRIPTAPI_PRECHECKHEADER - - int error_handler = PUSH_ERROR_HANDLER(L); - - lua_getglobal(L, "nodeupdate_single"); - push_v3s16(L, p); - PCALL_RES(lua_pcall(L, 1, 0, error_handler)); - lua_pop(L, 1); // Pop error handler -}