mirror of
https://github.com/minetest-mods/craftguide.git
synced 2024-12-13 18:20:17 +01:00
craftguide can show repairable tools
This commit is contained in:
parent
19b8e28afb
commit
00a88a320a
29
init.lua
29
init.lua
@ -8,12 +8,15 @@ local recipes_cache = {}
|
|||||||
local usages_cache = {}
|
local usages_cache = {}
|
||||||
local fuel_cache = {}
|
local fuel_cache = {}
|
||||||
|
|
||||||
|
local toolrepair
|
||||||
|
|
||||||
local progressive_mode = core.settings:get_bool("craftguide_progressive_mode")
|
local progressive_mode = core.settings:get_bool("craftguide_progressive_mode")
|
||||||
local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G, "sfinv")
|
local sfinv_only = core.settings:get_bool("craftguide_sfinv_only") and rawget(_G, "sfinv")
|
||||||
|
|
||||||
local log = core.log
|
local log = core.log
|
||||||
local after = core.after
|
local after = core.after
|
||||||
local colorize = core.colorize
|
local colorize = core.colorize
|
||||||
|
local reg_tools = core.registered_tools
|
||||||
local reg_items = core.registered_items
|
local reg_items = core.registered_items
|
||||||
local show_formspec = core.show_formspec
|
local show_formspec = core.show_formspec
|
||||||
local globalstep = core.register_globalstep
|
local globalstep = core.register_globalstep
|
||||||
@ -411,13 +414,18 @@ local function groups_to_items(groups, get_all)
|
|||||||
return #names > 0 and concat(names, ",") or ""
|
return #names > 0 and concat(names, ",") or ""
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function not_repairable(tool)
|
||||||
|
local def = reg_tools[tool]
|
||||||
|
return toolrepair and def and def.groups and def.groups.disable_repair == 1
|
||||||
|
end
|
||||||
|
|
||||||
local function get_description(item, def)
|
local function get_description(item, def)
|
||||||
return def and def.description or
|
return def and def.description or
|
||||||
(def and match(item, ":.*"):gsub("%W%l", upper):sub(2):gsub("_", " ") or
|
(def and match(item, ":.*"):gsub("%W%l", upper):sub(2):gsub("_", " ") or
|
||||||
S("Unknown Item (@1)", item))
|
S("Unknown Item (@1)", item))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_tooltip(item, burntime, groups, cooktime, replace)
|
local function get_tooltip(item, burntime, norepair, groups, cooktime, replace)
|
||||||
local tooltip
|
local tooltip
|
||||||
|
|
||||||
if groups then
|
if groups then
|
||||||
@ -433,6 +441,10 @@ local function get_tooltip(item, burntime, groups, cooktime, replace)
|
|||||||
else
|
else
|
||||||
local def = reg_items[item]
|
local def = reg_items[item]
|
||||||
tooltip = get_description(item, def)
|
tooltip = get_description(item, def)
|
||||||
|
|
||||||
|
if norepair then
|
||||||
|
tooltip = tooltip .. "\n" .. S("This tool cannot be repaired")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if cooktime then
|
if cooktime then
|
||||||
@ -541,7 +553,8 @@ local function get_recipe_fs(data)
|
|||||||
local burntime = fuel_cache[item] and fuel_cache[item].burntime
|
local burntime = fuel_cache[item] and fuel_cache[item].burntime
|
||||||
|
|
||||||
if groups or cooktime or burntime or replace then
|
if groups or cooktime or burntime or replace then
|
||||||
fs[#fs + 1] = get_tooltip(item, burntime, groups, cooktime, replace)
|
fs[#fs + 1] = get_tooltip(
|
||||||
|
item, burntime, nil, groups, cooktime, replace)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -586,9 +599,12 @@ local function get_recipe_fs(data)
|
|||||||
output_X, YOFFSET + (sfinv_only and 0.7 or 0),
|
output_X, YOFFSET + (sfinv_only and 0.7 or 0),
|
||||||
1.1, 1.1, recipe.output, ESC(output_name), "")
|
1.1, 1.1, recipe.output, ESC(output_name), "")
|
||||||
|
|
||||||
if burntime then
|
local norepair = not_repairable(recipe.output)
|
||||||
fs[#fs + 1] = get_tooltip(output_name, burntime)
|
|
||||||
|
|
||||||
|
if burntime or norepair then
|
||||||
|
fs[#fs + 1] = get_tooltip(output_name, burntime, norepair)
|
||||||
|
|
||||||
|
if burntime then
|
||||||
fs[#fs + 1] = fmt(FMT.image,
|
fs[#fs + 1] = fmt(FMT.image,
|
||||||
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1),
|
output_X + 1, YOFFSET + (sfinv_only and 0.7 or 0.1),
|
||||||
0.6, 0.4, PNG.arrow)
|
0.6, 0.4, PNG.arrow)
|
||||||
@ -598,6 +614,7 @@ local function get_recipe_fs(data)
|
|||||||
0.6, 0.6, PNG.fire)
|
0.6, 0.6, PNG.fire)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
return concat(fs)
|
return concat(fs)
|
||||||
end
|
end
|
||||||
@ -793,6 +810,10 @@ local old_register_craft = core.register_craft
|
|||||||
core.register_craft = function(recipe)
|
core.register_craft = function(recipe)
|
||||||
old_register_craft(recipe)
|
old_register_craft(recipe)
|
||||||
|
|
||||||
|
if recipe.type == "toolrepair" then
|
||||||
|
toolrepair = recipe.additional_wear ~= 0
|
||||||
|
end
|
||||||
|
|
||||||
local output = recipe.output or
|
local output = recipe.output or
|
||||||
(is_str(recipe.recipe) and recipe.recipe or "")
|
(is_str(recipe.recipe) and recipe.recipe or "")
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@ Recipe @1 of @2=Recette @1 de @2
|
|||||||
Burning time: @1=Temps de combustion : @1
|
Burning time: @1=Temps de combustion : @1
|
||||||
Cooking time: @1=Temps de cuisson : @1
|
Cooking time: @1=Temps de cuisson : @1
|
||||||
Replaced by @1 on crafting=Remplacé par @1 lors de la fabrication
|
Replaced by @1 on crafting=Remplacé par @1 lors de la fabrication
|
||||||
|
This tool cannot be repaired=Cet outil ne peut être réparé
|
||||||
Any item belonging to the group(s): @1=Tout item appartenant au(x) groupe(s) : @1
|
Any item belonging to the group(s): @1=Tout item appartenant au(x) groupe(s) : @1
|
||||||
Recipe's too big to be displayed (@1x@2)=La recette est trop grande pour être affichée (@1x@2)
|
Recipe's too big to be displayed (@1x@2)=La recette est trop grande pour être affichée (@1x@2)
|
||||||
Shapeless=Sans forme
|
Shapeless=Sans forme
|
||||||
|
@ -8,6 +8,7 @@ Recipe @1 of @2=
|
|||||||
Burning time: @1=
|
Burning time: @1=
|
||||||
Cooking time: @1=
|
Cooking time: @1=
|
||||||
Replaced by @1 on crafting=
|
Replaced by @1 on crafting=
|
||||||
|
This tool cannot be repaired=
|
||||||
Any item belonging to the group(s): @1=
|
Any item belonging to the group(s): @1=
|
||||||
Recipe's too big to be displayed (@1x@2)=
|
Recipe's too big to be displayed (@1x@2)=
|
||||||
Shapeless=
|
Shapeless=
|
||||||
|
Loading…
Reference in New Issue
Block a user