-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
registered item list with unknown node marker
- Loading branch information
1 parent
ae8f855
commit af9973f
Showing
4 changed files
with
64 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
mtui.register_on_command("get_item_list", function() | ||
return mtui.items | ||
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
|
||
local function check_registered_items() | ||
mtui.items = minetest.deserialize(mtui.mod_storage:get_string("registered_items")) or {} | ||
|
||
-- assemble node-list from registered lbm's | ||
local lbm_nodes = {} | ||
for _, lbm in ipairs(minetest.registered_lbms) do | ||
if type(lbm.nodenames) == "string" then | ||
-- duh, list as string | ||
lbm_nodes[lbm.nodenames] = true | ||
else | ||
-- proper list, add all regardless if they are a "group:*" | ||
for _, nodename in ipairs(lbm.nodenames) do | ||
lbm_nodes[nodename] = true | ||
end | ||
end | ||
end | ||
|
||
-- mark all currently registered items | ||
for name in pairs(minetest.registered_items) do | ||
mtui.items[name] = true | ||
end | ||
|
||
-- check for items that don't exist anymore | ||
for name in pairs(mtui.items) do | ||
if not minetest.registered_items[name] and | ||
not minetest.registered_aliases[name] and | ||
not lbm_nodes[name] then | ||
-- item does not exist anymore, mark it as such | ||
mtui.items[name] = false | ||
end | ||
end | ||
|
||
-- save current list back | ||
mtui.mod_storage:set_string("registered_items", minetest.serialize(mtui.items)) | ||
end | ||
|
||
-- execute check after mods loaded and other things are set up | ||
minetest.register_on_mods_loaded(function() | ||
minetest.after(0, check_registered_items) | ||
end) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
mtt.register("items", function(callback) | ||
assert(mtui.items) | ||
|
||
local count = 0 | ||
for _ in pairs(mtui.items) do | ||
count = count + 1 | ||
end | ||
|
||
assert(count > 0) | ||
callback() | ||
end) |