mirror of
https://notabug.org/TenPlus1/protector.git
synced 2025-01-08 13:57:38 +01:00
code tidy and intllib update
This commit is contained in:
parent
3b5e728b7d
commit
8dea715303
@ -569,24 +569,25 @@ 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 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
|
||||
|
||||
-- copy contents of players inventory to chest
|
||||
for i, v in pairs (player_inv:get_list("main") or {}) do
|
||||
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)
|
||||
|
||||
@ -600,17 +601,17 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
elseif fields.todn then
|
||||
|
||||
-- copy contents of chest to players inventory
|
||||
for i, v in pairs (chest_inv:get_list('main') or {}) do
|
||||
for i, v in ipairs(chest_inv:get_list("main") or {}) do
|
||||
|
||||
if player_inv:room_for_item("main", v) then
|
||||
|
||||
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)
|
||||
chest_inv:add_item("main", v)
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -628,8 +629,6 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
-- Protected Chest recipes
|
||||
|
16
init.lua
16
init.lua
@ -23,20 +23,12 @@ local S
|
||||
if minetest.get_modpath("intllib") then
|
||||
S = intllib.Getter()
|
||||
else
|
||||
S = function(s, a, ...)
|
||||
if a == nil then
|
||||
return s
|
||||
end
|
||||
a = {a, ...}
|
||||
return s:gsub("(@?)@(%(?)(%d+)(%)?)",
|
||||
function(e, o, n, c)
|
||||
if e == ""then
|
||||
return a[tonumber(n)] .. (o == "" and c or "")
|
||||
else
|
||||
return "@" .. o .. n .. c
|
||||
end
|
||||
S = function(s, a, ...) a = {a, ...}
|
||||
return s:gsub("@(%d+)", function(n)
|
||||
return a[tonumber(n)]
|
||||
end)
|
||||
end
|
||||
|
||||
end
|
||||
protector.intllib = S
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user