1
0
Fork 0

Show repairing recipes in craft guide

This commit is contained in:
Wuzzy 2017-02-14 16:35:25 +01:00
parent 3bb5ab67d6
commit ea583a2d70
2 changed files with 32 additions and 6 deletions

View File

@ -2,10 +2,34 @@ mcl_craftguide = {}
local craftguide, datas, mt = {}, {}, minetest local craftguide, datas, mt = {}, {}, minetest
local progressive_mode = mt.setting_getbool("craftguide_progressive_mode") local progressive_mode = mt.setting_getbool("craftguide_progressive_mode")
local get_recipe, get_recipes = mt.get_craft_recipe, mt.get_all_craft_recipes local get_recipe = mt.get_craft_recipe
local get_result, show_formspec = mt.get_craft_result, mt.show_formspec local get_result, show_formspec = mt.get_craft_result, mt.show_formspec
local reg_items = mt.registered_items local reg_items = mt.registered_items
local get_recipes = function(query_item)
local recipes = mt.get_all_craft_recipes(query_item)
-- Manually add repairing recipes (workaround, because get_all_craft_recipes
-- doesn't return repairing recipes)
if minetest.get_modpath("mcl_core") then
local def = minetest.registered_items[query_item]
if def.type == "tool" then
if recipes == nil then
recipes = {}
end
table.insert(recipes, {
type = "normal",
width = 0,
items = { [1] = query_item, [2] = query_item },
output = query_item,
-- Special marker for repairing recipes
_is_toolrepair = true,
})
end
end
return recipes
end
-- Lua 5.3 removed `table.maxn`, use this alternative in case of breakage: -- Lua 5.3 removed `table.maxn`, use this alternative in case of breakage:
-- https://github.com/kilbith/xdecor/blob/master/handlers/helpers.lua#L1 -- https://github.com/kilbith/xdecor/blob/master/handlers/helpers.lua#L1
local remove, maxn, sort = table.remove, table.maxn, table.sort local remove, maxn, sort = table.remove, table.maxn, table.sort
@ -302,8 +326,9 @@ function craftguide:get_init_items()
local items_list, counter = {}, 0 local items_list, counter = {}, 0
for name, def in pairs(reg_items) do for name, def in pairs(reg_items) do
local is_fuel = get_fueltime(name) > 0 local is_fuel = get_fueltime(name) > 0
local is_tool = def.type == "tool"
if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0) if (not def.groups.not_in_craft_guide or def.groups.not_in_craft_guide == 0)
and (get_recipe(name).items or is_fuel) and (get_recipe(name).items or is_fuel or is_tool)
and def.description and def.description ~= "" then and def.description and def.description ~= "" then
counter = counter + 1 counter = counter + 1
items_list[counter] = name items_list[counter] = name
@ -403,6 +428,7 @@ mt.register_on_player_receive_fields(function(player, formname, fields)
data.item = item data.item = item
data.recipe_num = 1 data.recipe_num = 1
data.recipes_item = recipes data.recipes_item = recipes
craftguide:get_formspec(player_name, is_fuel) craftguide:get_formspec(player_name, is_fuel)
end end
end end

View File

@ -58,7 +58,7 @@ minetest.register_tool("mcl_throwing:bow_0", {
description = "Bow", description = "Bow",
inventory_image = "mcl_throwing_bow_0.png", inventory_image = "mcl_throwing_bow_0.png",
stack_max = 1, stack_max = 1,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local wear = itemstack:get_wear() local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_1") itemstack:replace("mcl_throwing:bow_1")
@ -81,7 +81,7 @@ minetest.register_tool("mcl_throwing:bow_1", {
description = "Bow", description = "Bow",
inventory_image = "mcl_throwing_bow_1.png", inventory_image = "mcl_throwing_bow_1.png",
stack_max = 1, stack_max = 1,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local wear = itemstack:get_wear() local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow_2") itemstack:replace("mcl_throwing:bow_2")
@ -104,7 +104,7 @@ minetest.register_tool("mcl_throwing:bow_2", {
description = "Bow", description = "Bow",
inventory_image = "mcl_throwing_bow_2.png", inventory_image = "mcl_throwing_bow_2.png",
stack_max = 1, stack_max = 1,
groups = {not_in_creative_inventory=1}, groups = {not_in_creative_inventory=1, not_in_craft_guide=1},
on_use = function(itemstack, user, pointed_thing) on_use = function(itemstack, user, pointed_thing)
local wear = itemstack:get_wear() local wear = itemstack:get_wear()
itemstack:replace("mcl_throwing:bow") itemstack:replace("mcl_throwing:bow")