forked from MineClone5/MineClone5
Simplify armor stack handling w/ armor stand
This commit is contained in:
parent
3fe49f49fc
commit
175890fb15
|
@ -137,21 +137,33 @@ minetest.register_node("3d_armor_stand:armor_stand", {
|
||||||
inv:add_item(list, single_item)
|
inv:add_item(list, single_item)
|
||||||
update_entity(pos)
|
update_entity(pos)
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
|
return itmstack
|
||||||
end
|
end
|
||||||
return itemstack
|
end
|
||||||
elseif wielditem:get_name() == "" then
|
|
||||||
-- If player does not wield anything, take the first available armor from the armor stand
|
-- Take armor from stand if player has a free hand or wields the same armor type (if stackable)
|
||||||
-- and give it to the player
|
for e=1, #elements do
|
||||||
for e=1, #elements do
|
local stand_armor = inv:get_stack("armor_" .. elements[e], 1)
|
||||||
local stand_armor = inv:get_stack("armor_" .. elements[e], 1)
|
if not stand_armor:is_empty() then
|
||||||
if not stand_armor:is_empty() then
|
local pinv = clicker:get_inventory()
|
||||||
local pinv = clicker:get_inventory()
|
local taken = false
|
||||||
|
-- Empty hand
|
||||||
|
if wielditem:get_name() == "" then
|
||||||
pinv:set_stack("main", clicker:get_wield_index(), stand_armor)
|
pinv:set_stack("main", clicker:get_wield_index(), stand_armor)
|
||||||
|
taken = true
|
||||||
|
-- Stackable armor type (if not already full). This is the case for e.g. mob heads.
|
||||||
|
-- This is done purely for convenience.
|
||||||
|
elseif (wielditem:get_name() == stand_armor:get_name() and wielditem:get_count() < wielditem:get_stack_max()) then
|
||||||
|
wielditem:set_count(wielditem:get_count()+1)
|
||||||
|
pinv:set_stack("main", clicker:get_wield_index(), wielditem)
|
||||||
|
taken = true
|
||||||
|
end
|
||||||
|
if taken then
|
||||||
stand_armor:take_item()
|
stand_armor:take_item()
|
||||||
inv:set_stack("armor_" .. elements[e], 1, stand_armor)
|
inv:set_stack("armor_" .. elements[e], 1, stand_armor)
|
||||||
update_entity(pos)
|
update_entity(pos)
|
||||||
return clicker:get_wielded_item()
|
|
||||||
end
|
end
|
||||||
|
return clicker:get_wielded_item()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
|
|
Loading…
Reference in New Issue