From 7745e1ad311cc280b7fc7aecdf73cd0890a5e5a4 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Sun, 11 Jun 2017 14:16:22 +0200 Subject: [PATCH] Drop armor stand's armor when it got destroyed --- .../minetest-3d_armor/3d_armor_stand/init.lua | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 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 2ce084528..634d9c739 100644 --- a/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua +++ b/mods/ITEMS/minetest-3d_armor/3d_armor_stand/init.lua @@ -68,6 +68,19 @@ local function update_entity(pos) end end +-- Drop all armor of the armor stand on the ground +local drop_armor = function(pos) + local meta = minetest.get_meta(pos) + local inv = meta:get_inventory() + for _, element in pairs(elements) do + local stack = inv:get_stack("armor_"..element, 1) + if not stack:is_empty() then + local p = {x=pos.x+math.random(0, 10)/10-0.5, y=pos.y, z=pos.z+math.random(0, 10)/10-0.5} + minetest.add_item(p, stack) + end + end +end + -- FIXME: The armor stand should be an entity minetest.register_node("3d_armor_stand:armor_stand", { description = "Armor Stand", @@ -98,16 +111,8 @@ minetest.register_node("3d_armor_stand:armor_stand", { inv:set_size("armor_"..element, 1) end end, - can_dig = function(pos, player) - local meta = minetest.get_meta(pos) - local inv = meta:get_inventory() - for _, element in pairs(elements) do - if not inv:is_empty("armor_"..element) then - return false - end - end - return true - end, + -- Drop all armor on the ground when it got destroyed + on_destruct = drop_armor, on_rightclick = function(pos, node, clicker, itemstack, pointed_thing) -- Check if player wields armor local name = itemstack:get_name()