1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-12-17 12:35:21 +01:00

Rework object attachment handling to fix bugs (#14825)

This commit is contained in:
sfan5
2024-08-12 15:32:18 +02:00
committed by GitHub
parent a0e33ba9ea
commit 85e717fcd1
17 changed files with 245 additions and 172 deletions

View File

@@ -77,16 +77,17 @@ public:
// Attachments
ServerActiveObject *getParent() const;
inline bool isAttached() const { return getParent(); }
void setAttachment(int parent_id, const std::string &bone, v3f position,
inline bool isAttached() const { return m_attachment_parent_id != 0; }
void setAttachment(object_t parent_id, const std::string &bone, v3f position,
v3f rotation, bool force_visible);
void getAttachment(int *parent_id, std::string *bone, v3f *position,
void getAttachment(object_t *parent_id, std::string *bone, v3f *position,
v3f *rotation, bool *force_visible) const;
void clearChildAttachments();
void clearParentAttachment();
void addAttachmentChild(int child_id);
void removeAttachmentChild(int child_id);
const std::unordered_set<int> &getAttachmentChildIds() const;
void clearChildAttachments() override;
void addAttachmentChild(object_t child_id) override;
void removeAttachmentChild(object_t child_id) override;
const std::unordered_set<object_t> &getAttachmentChildIds() const {
return m_attachment_child_ids;
}
// Object properties
ObjectProperties *accessObjectProperties();
@@ -121,14 +122,28 @@ protected:
// Stores position and rotation for each bone name
std::unordered_map<std::string, BoneOverride> m_bone_override;
int m_attachment_parent_id = 0;
object_t m_attachment_parent_id = 0;
void clearAnyAttachments();
virtual void onMarkedForDeactivation() {
ServerActiveObject::onMarkedForDeactivation();
clearAnyAttachments();
}
virtual void onMarkedForRemoval() {
ServerActiveObject::onMarkedForRemoval();
clearAnyAttachments();
}
private:
void onAttach(int parent_id);
void onDetach(int parent_id);
void onAttach(ServerActiveObject *parent);
void onDetach(ServerActiveObject *parent);
std::string generatePunchCommand(u16 result_hp) const;
// Used to detect nested calls to setAttachments(), which can happen due to
// Lua callbacks
u8 m_attachment_call_counter = 0;
// Armor groups
bool m_armor_groups_sent = false;
@@ -144,7 +159,7 @@ private:
bool m_bone_override_sent = false;
// Attachments
std::unordered_set<int> m_attachment_child_ids;
std::unordered_set<object_t> m_attachment_child_ids;
std::string m_attachment_bone = "";
v3f m_attachment_position;
v3f m_attachment_rotation;