From c5eb3fa4ebc5711d3a62fb4741bc427392b10aec Mon Sep 17 00:00:00 2001 From: teknomunk Date: Sat, 23 Nov 2024 18:11:44 -0600 Subject: [PATCH] Make arrows (and all their derivatives) preserve collectable and entity properties across world unload/load --- mods/ITEMS/mcl_bows/arrow.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 33a110b05..c159eec5f 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -43,7 +43,7 @@ local arrow_entity = { _fire_damage_resistant = true, _save_fields = { - "last_pos", "startpos", "damage", "is_critical", "stuck", "stuckin", "stuckin_player", "time_in_air", "vl_projectile", + "last_pos", "startpos", "damage", "is_critical", "stuck", "stuckin", "stuckin_player", "time_in_air", "vl_projectile", "collectable" }, _damage=1, -- Damage on impact @@ -159,6 +159,9 @@ local arrow_entity = { out[field] = self["_"..field] end + -- Preserve entity properties + out.properties = self.object:get_properties() + return minetest.serialize(out) end, on_activate = function(self, staticdata, dtime_s) @@ -168,6 +171,12 @@ local arrow_entity = { local data = minetest.deserialize(staticdata) if not data then return end + -- Restore entity properties + if data.properties then + self.object:set_properties(data.properties) + data.properties = nil + end + -- Restore arrow state local save_fields = self._save_fields for i = 1,#save_fields do