aboutsummaryrefslogtreecommitdiff
path: root/src/scriptapi.cpp
diff options
context:
space:
mode:
authorPerttu Ahola <celeron55@gmail.com>2013-01-02 23:17:52 +0200
committerPerttu Ahola <celeron55@gmail.com>2013-01-02 23:18:14 +0200
commit2c472a66d1d605eefb167f51529c287f868ffa9b (patch)
tree8096b69ac4810fa083a7a823457af01995cd1418 /src/scriptapi.cpp
parent69bd803a3221bf02672431390e672b0510695254 (diff)
downloadhax-minetest-server-2c472a66d1d605eefb167f51529c287f868ffa9b.tar.gz
hax-minetest-server-2c472a66d1d605eefb167f51529c287f868ffa9b.zip
Add ServerEnvironment::setNode()/removeNode() to allow setting nodes from the C++ side with proper script-defined initialization/destruction
Diffstat (limited to 'src/scriptapi.cpp')
-rw-r--r--src/scriptapi.cpp29
1 files changed, 2 insertions, 27 deletions
diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp
index a79622db3..04f741ad3 100644
--- a/src/scriptapi.cpp
+++ b/src/scriptapi.cpp
@@ -3540,20 +3540,7 @@ private:
v3s16 pos = read_v3s16(L, 2);
MapNode n = readnode(L, 3, ndef);
// Do it
- MapNode n_old = env->getMap().getNodeNoEx(pos);
- // Call destructor
- if(ndef->get(n_old).has_on_destruct)
- scriptapi_node_on_destruct(L, pos, n_old);
- // Replace node
- bool succeeded = env->getMap().addNodeWithEvent(pos, n);
- if(succeeded){
- // Call post-destructor
- if(ndef->get(n_old).has_after_destruct)
- scriptapi_node_after_destruct(L, pos, n_old);
- // Call constructor
- if(ndef->get(n).has_on_construct)
- scriptapi_node_on_construct(L, pos, n);
- }
+ bool succeeded = env->setNode(pos, n);
lua_pushboolean(L, succeeded);
return 1;
}
@@ -3574,20 +3561,8 @@ private:
// parameters
v3s16 pos = read_v3s16(L, 2);
// Do it
- MapNode n_old = env->getMap().getNodeNoEx(pos);
- // Call destructor
- if(ndef->get(n_old).has_on_destruct)
- scriptapi_node_on_destruct(L, pos, n_old);
- // Replace with air
- // This is slightly optimized compared to addNodeWithEvent(air)
- bool succeeded = env->getMap().removeNodeWithEvent(pos);
- if(succeeded){
- // Call post-destructor
- if(ndef->get(n_old).has_after_destruct)
- scriptapi_node_after_destruct(L, pos, n_old);
- }
+ bool succeeded = env->removeNode(pos);
lua_pushboolean(L, succeeded);
- // Air doesn't require constructor
return 1;
}