Checks players’ inventory for undiscovered recipes

When the player joins, check their inventory — this
will unlock recipes even if this mod is run for the
first time in a pre-existing world.
This commit is contained in:
Jaidyn Ann 2024-08-13 21:56:56 -05:00
parent 7b1c884406
commit ccc3ea7b5d

View File

@ -540,6 +540,17 @@ minetest.register_on_craft(function(itemstack, player)
update_known_items(player, itemstack:get_name()) update_known_items(player, itemstack:get_name())
end) end)
-- Go over all items in the players inventory for undiscovered recipes.
function check_player_inventory(player)
local inv = player:get_inventory(player)
local items = inv:get_list("main")
if items then
for _,stack in pairs(items) do
update_known_items(player, stack:get_name())
end
end
end
-- Initialize player-data. -- Initialize player-data.
-- If saved data is found, load previous held-items and held-groups data. -- If saved data is found, load previous held-items and held-groups data.
function load_player_data(player) function load_player_data(player)
@ -601,6 +612,7 @@ end
minetest.register_on_joinplayer(function(player) minetest.register_on_joinplayer(function(player)
load_player_data(player) load_player_data(player)
init_player_known_items(player) init_player_known_items(player)
check_player_inventory(player)
-- Init displayed items. -- Init displayed items.
local data = player_data[player:get_player_name()] local data = player_data[player:get_player_name()]