From ccc3ea7b5d431da37a661945584390116d11ceef Mon Sep 17 00:00:00 2001 From: Jaidyn Ann <10477760+JadedCtrl@users.noreply.github.com> Date: Tue, 13 Aug 2024 21:56:56 -0500 Subject: [PATCH] =?UTF-8?q?Checks=20players=E2=80=99=20inventory=20for=20u?= =?UTF-8?q?ndiscovered=20recipes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- init.lua | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/init.lua b/init.lua index f4396ee..0bbc7b5 100644 --- a/init.lua +++ b/init.lua @@ -540,6 +540,17 @@ minetest.register_on_craft(function(itemstack, player) update_known_items(player, itemstack:get_name()) end) +-- Go over all items in the player’s 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. -- If saved data is found, load previous held-items and held-groups data. function load_player_data(player) @@ -601,6 +612,7 @@ end minetest.register_on_joinplayer(function(player) load_player_data(player) init_player_known_items(player) + check_player_inventory(player) -- Init displayed items. local data = player_data[player:get_player_name()]