From f879be1e1b4af3bfca396b98b66c2ec5016d12b4 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Tue, 13 Jun 2017 02:48:42 +0200 Subject: [PATCH] Fair but primitive craftguide progressive mode --- mods/HELP/mcl_craftguide/depends.txt | 1 + mods/HELP/mcl_craftguide/init.lua | 24 +++++++++++++++++------- settingtypes.txt | 2 +- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/mods/HELP/mcl_craftguide/depends.txt b/mods/HELP/mcl_craftguide/depends.txt index cbf7e57d42..de1a2085e2 100644 --- a/mods/HELP/mcl_craftguide/depends.txt +++ b/mods/HELP/mcl_craftguide/depends.txt @@ -1,3 +1,4 @@ mcl_core mcl_compass mcl_clock +doc diff --git a/mods/HELP/mcl_craftguide/init.lua b/mods/HELP/mcl_craftguide/init.lua index 56482fcafe..b677d7a676 100644 --- a/mods/HELP/mcl_craftguide/init.lua +++ b/mods/HELP/mcl_craftguide/init.lua @@ -370,7 +370,19 @@ local function item_in_inv(inv, item) return inv:contains_item("main", item) end -function craftguide:recipe_in_inv(inv, item_name, recipes_f) +-- Returns true if player knows the item. Used for progressive mode (EXPERIMENTAL). +local function knows_item(playername, item) + local has_item = doc.entry_exists("nodes", item) and doc.entry_revealed(playername, "nodes", item) + if not has_item then + has_item = doc.entry_exists("tools", item) and doc.entry_revealed(playername, "tools", item) + end + if not has_item then + has_item = doc.entry_exists("craftitems", item) and doc.entry_revealed(playername, "craftitems", item) + end + return has_item +end + +function craftguide:recipe_in_inv(inv, item_name, recipes_f, playername) local recipes = recipes_f or get_recipes(item_name) or {} local show_item_recipes = {} @@ -386,7 +398,7 @@ function craftguide:recipe_in_inv(inv, item_name, recipes_f) end end end - if group_in_inv or item_in_inv(inv, item) then + if group_in_inv or item_in_inv(inv, item) or knows_item(playername, item) then show_item_recipes[i] = true end end @@ -435,7 +447,7 @@ function craftguide:get_filter_items(data, player) filtered_list[counter] = item end elseif progressive_mode then - local _, has_item = self:recipe_in_inv(inv, item) + local _, has_item = self:recipe_in_inv(inv, item, nil, player:get_player_name()) if has_item then counter = counter + 1 filtered_list[counter] = item @@ -504,12 +516,10 @@ mt.register_on_player_receive_fields(function(player, formname, fields) if progressive_mode then local inv = player:get_inventory() - local _, has_item = - craftguide:recipe_in_inv(inv, item) + local _, has_item = craftguide:recipe_in_inv(inv, item, nil, player:get_player_name()) if not has_item then return end - recipes = craftguide:recipe_in_inv( - inv, item, recipes) + recipes = craftguide:recipe_in_inv(inv, item, recipes, player_name) end data.item = item diff --git a/settingtypes.txt b/settingtypes.txt index b39f2f7b21..3f351300a2 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -45,7 +45,7 @@ enable_bed_respawn (Respawn at bed) bool true enable_bed_night_skip (Skip night when sleeping) bool true # If enabled, the recipe book will only show recipes which require one -# item which the player has currently in possession. +# item which you have already discovered. # If disabled, the recipe book shows all crafting recipes. # This setting is experimental and may be changed in later versions. # Feedback is appreciated.