Update player inventories when item is replaced with chat command

master
Jordan Irwin 2021-07-12 22:11:00 -07:00
parent f8fd1506eb
commit 9592b1df73
2 changed files with 20 additions and 3 deletions

View File

@ -1,5 +1,9 @@
TODO:
- update world file when chat commands are used
- update player inventories when items are replaced
- update player inventories when items are replaced:
- bags
- 3d_armor
- update storage inventories when items are replaced
- update player inventories on login
- fix top nodes disappearing with /replace_node command

View File

@ -190,13 +190,26 @@ local function replace_item(src, tgt)
end
core.register_alias(src, tgt)
-- update player inventories
for _, player in ipairs(core.get_connected_players()) do
local pinv = player:get_inventory()
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)
end
end
end
return true
end
--- Replaces an item.
--
-- FIXME: inventory icons not updated
--
-- @chatcmd replace_item
-- @param old_item Technical name of item to replace.
-- @param new_item Technical name of item to be used in place.