diff options
author | TeTpaAka <TeTpaAka@users.noreply.github.com> | 2015-07-03 12:31:34 +0200 |
---|---|---|
committer | est31 <MTest31@outlook.com> | 2015-07-18 07:41:43 +0200 |
commit | 8d03301138c0e82728d61b957ea47a5a4061633a (patch) | |
tree | bafa658a24d90ec5381f3a21e93803dc0165a1b5 /src/script | |
parent | 9c76f379acb12246fb1e282661e67b9da4cdcb62 (diff) | |
download | minetest-8d03301138c0e82728d61b957ea47a5a4061633a.tar.gz minetest-8d03301138c0e82728d61b957ea47a5a4061633a.tar.bz2 minetest-8d03301138c0e82728d61b957ea47a5a4061633a.zip |
Fix invisible player when the attached entity is removed
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/lua_api/l_object.cpp | 62 |
1 files changed, 52 insertions, 10 deletions
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp index e407ef162..96fb0c579 100644 --- a/src/script/lua_api/l_object.cpp +++ b/src/script/lua_api/l_object.cpp @@ -132,10 +132,22 @@ int ObjectRef::gc_object(lua_State *L) { int ObjectRef::l_remove(lua_State *L) { NO_MAP_LOCK_REQUIRED; + GET_ENV_PTR; + ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if(co == NULL) return 0; - if(co->getType() == ACTIVEOBJECT_TYPE_PLAYER) return 0; + if (co == NULL) + return 0; + if (co->getType() == ACTIVEOBJECT_TYPE_PLAYER) + return 0; + + std::set<int> child_ids = co->getAttachmentChildIds(); + std::set<int>::iterator it; + for (it = child_ids.begin(); it != child_ids.end(); ++it) { + ServerActiveObject *child = env->getActiveObject(*it); + child->setAttachment(0, "", v3f(0, 0, 0), v3f(0, 0, 0)); + } + verbosestream<<"ObjectRef::l_remove(): id="<<co->getId()<<std::endl; co->m_removed = true; return 0; @@ -630,23 +642,38 @@ int ObjectRef::l_get_bone_position(lua_State *L) int ObjectRef::l_set_attach(lua_State *L) { NO_MAP_LOCK_REQUIRED; + GET_ENV_PTR; + ObjectRef *ref = checkobject(L, 1); ObjectRef *parent_ref = checkobject(L, 2); ServerActiveObject *co = getobject(ref); ServerActiveObject *parent = getobject(parent_ref); - if(co == NULL) return 0; - if(parent == NULL) return 0; + if (co == NULL) + return 0; + if (parent == NULL) + return 0; // Do it + int parent_id = 0; std::string bone = ""; - if(!lua_isnil(L, 3)) - bone = lua_tostring(L, 3); v3f position = v3f(0, 0, 0); - if(!lua_isnil(L, 4)) - position = read_v3f(L, 4); v3f rotation = v3f(0, 0, 0); - if(!lua_isnil(L, 5)) + co->getAttachment(&parent_id, &bone, &position, &rotation); + if (parent_id) { + ServerActiveObject *old_parent = env->getActiveObject(parent_id); + old_parent->removeAttachmentChild(co->getId()); + } + + bone = ""; + if (!lua_isnil(L, 3)) + bone = lua_tostring(L, 3); + position = v3f(0, 0, 0); + if (!lua_isnil(L, 4)) + position = read_v3f(L, 4); + rotation = v3f(0, 0, 0); + if (!lua_isnil(L, 5)) rotation = read_v3f(L, 5); co->setAttachment(parent->getId(), bone, position, rotation); + parent->addAttachmentChild(co->getId()); return 0; } @@ -682,11 +709,26 @@ int ObjectRef::l_get_attach(lua_State *L) int ObjectRef::l_set_detach(lua_State *L) { NO_MAP_LOCK_REQUIRED; + GET_ENV_PTR; + ObjectRef *ref = checkobject(L, 1); ServerActiveObject *co = getobject(ref); - if(co == NULL) return 0; + if (co == NULL) + return 0; + + int parent_id = 0; + std::string bone = ""; + v3f position; + v3f rotation; + co->getAttachment(&parent_id, &bone, &position, &rotation); + ServerActiveObject *parent = NULL; + if (parent_id) + parent = env->getActiveObject(parent_id); + // Do it co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0)); + if (parent != NULL) + parent->removeAttachmentChild(co->getId()); return 0; } |