mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Rework object attachment handling to fix bugs (#14825)
This commit is contained in:
parent
a0e33ba9ea
commit
85e717fcd1
17 changed files with 245 additions and 172 deletions
|
@ -37,11 +37,12 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
#include "server/serverinventorymgr.h"
|
||||
#include "server/unit_sao.h"
|
||||
|
||||
using object_t = ServerActiveObject::object_t;
|
||||
|
||||
/*
|
||||
ObjectRef
|
||||
*/
|
||||
|
||||
|
||||
ServerActiveObject* ObjectRef::getobject(ObjectRef *ref)
|
||||
{
|
||||
ServerActiveObject *sao = ref->m_object;
|
||||
|
@ -99,9 +100,6 @@ int ObjectRef::l_remove(lua_State *L)
|
|||
if (sao->getType() == ACTIVEOBJECT_TYPE_PLAYER)
|
||||
return 0;
|
||||
|
||||
sao->clearChildAttachments();
|
||||
sao->clearParentAttachment();
|
||||
|
||||
verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
|
||||
sao->markForRemoval();
|
||||
return 0;
|
||||
|
@ -724,25 +722,17 @@ int ObjectRef::l_set_attach(lua_State *L)
|
|||
if (sao == parent)
|
||||
throw LuaError("ObjectRef::set_attach: attaching object to itself is not allowed.");
|
||||
|
||||
int parent_id;
|
||||
std::string bone;
|
||||
v3f position;
|
||||
v3f rotation;
|
||||
bool force_visible;
|
||||
|
||||
sao->getAttachment(&parent_id, &bone, &position, &rotation, &force_visible);
|
||||
if (parent_id) {
|
||||
ServerActiveObject *old_parent = env->getActiveObject(parent_id);
|
||||
old_parent->removeAttachmentChild(sao->getId());
|
||||
}
|
||||
|
||||
bone = readParam<std::string>(L, 3, "");
|
||||
position = readParam<v3f>(L, 4, v3f(0, 0, 0));
|
||||
rotation = readParam<v3f>(L, 5, v3f(0, 0, 0));
|
||||
force_visible = readParam<bool>(L, 6, false);
|
||||
|
||||
sao->setAttachment(parent->getId(), bone, position, rotation, force_visible);
|
||||
parent->addAttachmentChild(sao->getId());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -755,7 +745,7 @@ int ObjectRef::l_get_attach(lua_State *L)
|
|||
if (sao == nullptr)
|
||||
return 0;
|
||||
|
||||
int parent_id;
|
||||
object_t parent_id;
|
||||
std::string bone;
|
||||
v3f position;
|
||||
v3f rotation;
|
||||
|
@ -783,11 +773,11 @@ int ObjectRef::l_get_children(lua_State *L)
|
|||
if (sao == nullptr)
|
||||
return 0;
|
||||
|
||||
const std::unordered_set<int> child_ids = sao->getAttachmentChildIds();
|
||||
const auto &child_ids = sao->getAttachmentChildIds();
|
||||
int i = 0;
|
||||
|
||||
lua_createtable(L, child_ids.size(), 0);
|
||||
for (const int id : child_ids) {
|
||||
for (const object_t id : child_ids) {
|
||||
ServerActiveObject *child = env->getActiveObject(id);
|
||||
getScriptApiBase(L)->objectrefGetOrCreate(L, child);
|
||||
lua_rawseti(L, -2, ++i);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue