diff options
author | TenPlus1 <kinsellaja@yahoo.com> | 2017-03-17 10:05:42 +0000 |
---|---|---|
committer | TenPlus1 <kinsellaja@yahoo.com> | 2017-03-17 10:05:42 +0000 |
commit | 8dea715303a2d800ff638716c62436a86177b30f (patch) | |
tree | a2b07bd8bcf49e07a11bd38384fd4a1c09259729 /doors_chest.lua | |
parent | 3b5e728b7dcf7eefd2010c91413473a545725adc (diff) |
code tidy and intllib update
Diffstat (limited to 'doors_chest.lua')
-rw-r--r-- | doors_chest.lua | 75 |
1 files changed, 37 insertions, 38 deletions
diff --git a/doors_chest.lua b/doors_chest.lua index c7ba8de..89aaf54 100644 --- a/doors_chest.lua +++ b/doors_chest.lua @@ -569,67 +569,66 @@ minetest.register_node("protector:chest", { minetest.register_on_player_receive_fields(function(player, formname, fields) - if string.sub(formname, 0, string.len("protector:chest_")) == "protector:chest_" then + if string.sub(formname, 0, string.len("protector:chest_")) ~= "protector:chest_" then + return + end - local pos_s = string.sub(formname,string.len("protector:chest_") + 1) - local pos = minetest.string_to_pos(pos_s) - local meta = minetest.get_meta(pos) - local chest_inv = meta:get_inventory() - local player_inv = player:get_inventory() - local leftover + local pos_s = string.sub(formname,string.len("protector:chest_") + 1) + local pos = minetest.string_to_pos(pos_s) + local meta = minetest.get_meta(pos) ; if not meta then return end + local chest_inv = meta:get_inventory() ; if not chest_inv then return end + local player_inv = player:get_inventory() + local leftover - if fields.toup then + if fields.toup then - -- copy contents of players inventory to chest - for i, v in pairs (player_inv:get_list("main") or {}) do + -- copy contents of players inventory to chest + for i, v in ipairs(player_inv:get_list("main") or {}) do - if chest_inv - and chest_inv:room_for_item('main', v) then + if chest_inv:room_for_item("main", v) then - leftover = chest_inv:add_item('main', v) + leftover = chest_inv:add_item("main", v) - player_inv:remove_item("main", v) + player_inv:remove_item("main", v) - if leftover - and not leftover:is_empty() then - player_inv:add_item("main", v) - end + if leftover + and not leftover:is_empty() then + player_inv:add_item("main", v) end end + end - elseif fields.todn then + elseif fields.todn then - -- copy contents of chest to players inventory - for i, v in pairs (chest_inv:get_list('main') or {}) do + -- copy contents of chest to players inventory + for i, v in ipairs(chest_inv:get_list("main") or {}) do - if player_inv:room_for_item("main", v) then + if player_inv:room_for_item("main", v) then - leftover = player_inv:add_item("main", v) + leftover = player_inv:add_item("main", v) - chest_inv:remove_item('main', v) + chest_inv:remove_item("main", v) - if leftover - and not leftover:is_empty() then - chest_inv:add_item('main', v) - end + if leftover + and not leftover:is_empty() then + chest_inv:add_item("main", v) end end + end - elseif fields.chestname then + elseif fields.chestname then - -- change chest infotext to display name - if fields.chestname ~= "" then + -- change chest infotext to display name + if fields.chestname ~= "" then - meta:set_string("name", fields.chestname) - meta:set_string("infotext", + meta:set_string("name", fields.chestname) + meta:set_string("infotext", S("Protected Chest (@1)", fields.chestname)) - else - meta:set_string("infotext", S("Protected Chest")) - end - + else + meta:set_string("infotext", S("Protected Chest")) end - end + end end) -- Protected Chest recipes |