diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2018-04-30 18:43:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-30 18:43:49 +0200 |
commit | ba91624d8c354bac49c35a449029b6712022d0cb (patch) | |
tree | 8a6423ab354888691927f852754f86816f9c90c5 /src/content_cao.cpp | |
parent | 0b5b32b026291d5bd8e47acebca10259a379fc1c (diff) | |
download | minetest-ba91624d8c354bac49c35a449029b6712022d0cb.tar.gz minetest-ba91624d8c354bac49c35a449029b6712022d0cb.tar.bz2 minetest-ba91624d8c354bac49c35a449029b6712022d0cb.zip |
Allow damage for attached objects, add attach/detach callbacks (#6786)
* Allow right-clicking on attached LuaEntities
Diffstat (limited to 'src/content_cao.cpp')
-rw-r--r-- | src/content_cao.cpp | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/content_cao.cpp b/src/content_cao.cpp index 4dde1b098..9344b3370 100644 --- a/src/content_cao.cpp +++ b/src/content_cao.cpp @@ -343,7 +343,7 @@ GenericCAO::~GenericCAO() bool GenericCAO::getSelectionBox(aabb3f *toset) const { if (!m_prop.is_visible || !m_is_visible || m_is_local_player - || !m_prop.pointable || getParent() != NULL) { + || !m_prop.pointable) { return false; } *toset = m_selection_box; @@ -430,6 +430,7 @@ void GenericCAO::removeFromScene(bool permanent) m_env->attachement_parent_ids[ci] = 0; } } + m_children.clear(); m_env->attachement_parent_ids[getId()] = 0; @@ -1409,17 +1410,18 @@ void GenericCAO::processMessage(const std::string &data) updateBonePosition(); } else if (cmd == GENERIC_CMD_ATTACH_TO) { - u16 parentID = readS16(is); - u16 oldparent = m_env->attachement_parent_ids[getId()]; - if (oldparent) { - m_children.erase(std::remove(m_children.begin(), m_children.end(), - getId()), m_children.end()); - } - m_env->attachement_parent_ids[getId()] = parentID; - GenericCAO *parentobj = m_env->getGenericCAO(parentID); + u16 parent_id = readS16(is); + u16 &old_parent_id = m_env->attachement_parent_ids[getId()]; + if (parent_id != old_parent_id) { + if (GenericCAO *old_parent = m_env->getGenericCAO(old_parent_id)) { + old_parent->m_children.erase(std::remove( + m_children.begin(), m_children.end(), + getId()), m_children.end()); + } + if (GenericCAO *new_parent = m_env->getGenericCAO(parent_id)) + new_parent->m_children.push_back(getId()); - if (parentobj) { - parentobj->m_children.push_back(getId()); + old_parent_id = parent_id; } m_attachment_bone = deSerializeString(is); |