From e332c64d2ada9aa5c09f8bb591c7adf17b1632c6 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 18 Feb 2019 23:55:18 +0100 Subject: [PATCH] Respawn armor entity of armor stand on load --- .../minetest-3d_armor/3d_armor_stand/init.lua | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua b/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua index 76dcec55e4..02eb0bcbdf 100644 --- a/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua +++ b/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua @@ -125,6 +125,12 @@ minetest.register_node("3d_armor_stand:armor_stand", { minetest.record_protection_violation(pos, protname) return itemstack end + + local inv = minetest.get_inventory({type = "node", pos = pos}) + if not inv then + return itemstack + end + -- Check if player wields armor local name = itemstack:get_name() local list @@ -135,11 +141,8 @@ minetest.register_node("3d_armor_stand:armor_stand", { break end end - -- If player wields armor, put it on armor stand - local inv = minetest.get_inventory({type = "node", pos = pos}) local wielditem = clicker:get_wielded_item() - if not inv then return itemstack end if list then -- ... but only if the slot is free local single_item = ItemStack(itemstack) @@ -172,11 +175,12 @@ minetest.register_node("3d_armor_stand:armor_stand", { if taken then stand_armor:take_item() inv:set_stack("armor_" .. elements[e], 1, stand_armor) - update_entity(pos) end + update_entity(pos) return clicker:get_wielded_item() end end + update_entity(pos) return itemstack end, after_place_node = function(pos) @@ -264,6 +268,17 @@ minetest.register_entity("3d_armor_stand:armor_entity", { end, }) +-- FIXME: Armor helper entity can get destroyed by /clearobjects +minetest.register_lbm({ + label = "Respawn armor stand entities", + name = "3d_armor_stand:respawn_entities", + nodenames = {"3d_armor_stand:armor_stand"}, + run_at_every_load = true, + action = function(pos, node) + update_entity(pos, node) + end, +}) + if minetest.get_modpath("doc_identifier") ~= nil then doc.sub.identifier.register_object("3d_armor_stand:armor_entity", "nodes", "3d_armor_stand:armor_stand") end