mirror of
https://github.com/minetest/minetest_game.git
synced 2024-12-23 07:10:19 +01:00
Creative: Cache inventory items on load
This commit is contained in:
parent
a52622669f
commit
532013a032
@ -1,4 +1,19 @@
|
|||||||
local player_inventory = {}
|
local player_inventory = {}
|
||||||
|
local inventory_cache = {}
|
||||||
|
|
||||||
|
local function init_creative_cache(items)
|
||||||
|
inventory_cache[items] = {}
|
||||||
|
local i_cache = inventory_cache[items]
|
||||||
|
|
||||||
|
for name, def in pairs(items) do
|
||||||
|
if def.groups.not_in_creative_inventory ~= 1 and
|
||||||
|
def.description and def.description ~= "" then
|
||||||
|
i_cache[name] = def
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.sort(i_cache)
|
||||||
|
return i_cache
|
||||||
|
end
|
||||||
|
|
||||||
function creative.init_creative_inventory(player)
|
function creative.init_creative_inventory(player)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
@ -45,11 +60,11 @@ function creative.update_creative_inventory(player_name, tab_content)
|
|||||||
creative.init_creative_inventory(minetest.get_player_by_name(player_name))
|
creative.init_creative_inventory(minetest.get_player_by_name(player_name))
|
||||||
local player_inv = minetest.get_inventory({type = "detached", name = "creative_" .. player_name})
|
local player_inv = minetest.get_inventory({type = "detached", name = "creative_" .. player_name})
|
||||||
|
|
||||||
for name, def in pairs(tab_content) do
|
local items = inventory_cache[tab_content] or init_creative_cache(tab_content)
|
||||||
if not (def.groups.not_in_creative_inventory == 1) and
|
|
||||||
def.description and def.description ~= "" and
|
for name, def in pairs(items) do
|
||||||
(def.name:find(inv.filter, 1, true) or
|
if def.name:find(inv.filter, 1, true) or
|
||||||
def.description:lower():find(inv.filter, 1, true)) then
|
def.description:lower():find(inv.filter, 1, true) then
|
||||||
creative_list[#creative_list+1] = name
|
creative_list[#creative_list+1] = name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -161,10 +176,6 @@ function creative.register_tab(name, title, items)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
minetest.register_on_joinplayer(function(player)
|
|
||||||
creative.update_creative_inventory(player:get_player_name(), minetest.registered_items)
|
|
||||||
end)
|
|
||||||
|
|
||||||
creative.register_tab("all", "All", minetest.registered_items)
|
creative.register_tab("all", "All", minetest.registered_items)
|
||||||
creative.register_tab("nodes", "Nodes", minetest.registered_nodes)
|
creative.register_tab("nodes", "Nodes", minetest.registered_nodes)
|
||||||
creative.register_tab("tools", "Tools", minetest.registered_tools)
|
creative.register_tab("tools", "Tools", minetest.registered_tools)
|
||||||
|
Loading…
Reference in New Issue
Block a user