mirror of
https://codeberg.org/AntumLuanti/mod-cleaner.git
synced 2025-03-15 04:41:22 +00:00
Support updating items in cornernote's bags mod with chat command...
Homepage: http://cornernote.github.io/minetest-bags/ Git repo: https://github.com/cornernote/minetest-bags
This commit is contained in:
parent
9592b1df73
commit
e81ed836dc
2 changed files with 22 additions and 7 deletions
1
TODO.txt
1
TODO.txt
|
@ -2,7 +2,6 @@
|
|||
TODO:
|
||||
- update world file when chat commands are used
|
||||
- update player inventories when items are replaced:
|
||||
- bags
|
||||
- 3d_armor
|
||||
- update storage inventories when items are replaced
|
||||
- update player inventories on login
|
||||
|
|
28
chat.lua
28
chat.lua
|
@ -180,6 +180,22 @@ core.register_chatcommand(cmd_repo.node.cmd_rem, {
|
|||
end,
|
||||
})
|
||||
|
||||
local function update_list(inv, listname, src, tgt)
|
||||
local list = inv:get_list(listname)
|
||||
if not list then
|
||||
cleaner.log("warning", "unknown player list: " .. listname)
|
||||
return
|
||||
end
|
||||
|
||||
for idx, stack in pairs(list) do
|
||||
if stack:get_name() == src then
|
||||
local new_stack = ItemStack(tgt)
|
||||
new_stack:set_count(stack:get_count())
|
||||
inv:set_stack(listname, idx, new_stack)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function replace_item(src, tgt)
|
||||
if not core.registered_items[tgt] then
|
||||
return false, S('Cannot use unknown item "@1" as replacement.', tgt)
|
||||
|
@ -191,16 +207,16 @@ local function replace_item(src, tgt)
|
|||
|
||||
core.register_alias(src, tgt)
|
||||
|
||||
local bags = core.get_modpath("bags") ~= nil
|
||||
|
||||
-- update player inventories
|
||||
for _, player in ipairs(core.get_connected_players()) do
|
||||
local pinv = player:get_inventory()
|
||||
update_list(pinv, "main", src, tgt)
|
||||
|
||||
for idx, stack in pairs(pinv:get_list("main")) do
|
||||
if stack:get_name() == src then
|
||||
local new_stack = ItemStack(tgt)
|
||||
new_stack:set_count(stack:get_count())
|
||||
|
||||
pinv:set_stack("main", idx, new_stack)
|
||||
if bags then
|
||||
for i = 1, 4 do
|
||||
update_list(pinv, "bag" .. i .. "contents", src, tgt)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue