Skip to content

Commit 72535d3

Browse files
red-001nerzhul
authored andcommittedJan 21, 2017
Detach the player from entities on death. (#5077)
1 parent 0eede97 commit 72535d3

File tree

5 files changed

+16
-14
lines changed

5 files changed

+16
-14
lines changed
 

‎src/content_sao.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ void UnitSAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
203203
*rotation = m_attachment_rotation;
204204
}
205205

206+
void UnitSAO::detachFromParent()
207+
{
208+
ServerActiveObject *parent = NULL;
209+
if (m_attachment_parent_id)
210+
parent = m_env->getActiveObject(m_attachment_parent_id);
211+
setAttachment(NULL, "", v3f(0, 0, 0), v3f(0, 0, 0));
212+
if (parent != NULL)
213+
parent->removeAttachmentChild(m_id);
214+
}
215+
206216
void UnitSAO::addAttachmentChild(int child_id)
207217
{
208218
m_attachment_child_ids.insert(child_id);

‎src/content_sao.h

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class UnitSAO: public ServerActiveObject
4949
void setBonePosition(const std::string &bone, v3f position, v3f rotation);
5050
void getBonePosition(const std::string &bone, v3f *position, v3f *rotation);
5151
void setAttachment(int parent_id, const std::string &bone, v3f position, v3f rotation);
52+
void detachFromParent();
5253
void getAttachment(int *parent_id, std::string *bone, v3f *position, v3f *rotation);
5354
void addAttachmentChild(int child_id);
5455
void removeAttachmentChild(int child_id);

‎src/script/lua_api/l_object.cpp

+1-14
Original file line numberDiff line numberDiff line change
@@ -710,20 +710,7 @@ int ObjectRef::l_set_detach(lua_State *L)
710710
ServerActiveObject *co = getobject(ref);
711711
if (co == NULL)
712712
return 0;
713-
714-
int parent_id = 0;
715-
std::string bone = "";
716-
v3f position;
717-
v3f rotation;
718-
co->getAttachment(&parent_id, &bone, &position, &rotation);
719-
ServerActiveObject *parent = NULL;
720-
if (parent_id)
721-
parent = env->getActiveObject(parent_id);
722-
723-
// Do it
724-
co->setAttachment(0, "", v3f(0,0,0), v3f(0,0,0));
725-
if (parent != NULL)
726-
parent->removeAttachmentChild(co->getId());
713+
co->detachFromParent();
727714
return 0;
728715
}
729716

‎src/server.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,8 @@ void Server::DiePlayer(u16 peer_id)
25602560
if (!playersao)
25612561
return;
25622562

2563+
playersao->detachFromParent();
2564+
25632565
infostream << "Server::DiePlayer(): Player "
25642566
<< playersao->getPlayer()->getName()
25652567
<< " dies" << std::endl;

‎src/serverobject.h

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ class ServerActiveObject : public ActiveObject
166166
{}
167167
virtual void removeAttachmentChild(int child_id)
168168
{}
169+
virtual void detachFromParent()
170+
{}
169171
virtual const UNORDERED_SET<int> &getAttachmentChildIds()
170172
{ static const UNORDERED_SET<int> rv; return rv; }
171173
virtual ObjectProperties* accessObjectProperties()

0 commit comments

Comments
 (0)
Please sign in to comment.