added furnace recipes to crafting guide

This commit is contained in:
cale 2016-10-20 19:00:14 +02:00
parent 8edc4b4cf1
commit 1f4697cc72
3 changed files with 35 additions and 8 deletions

View File

@ -1,2 +1,3 @@
default
quests
furnace

View File

@ -41,6 +41,21 @@ function crafting_guide.get_formspec(crafts,back_button)
return str
end
function crafting_guide.get_furnace_formspec(recipe,back_button)
local str = crafting_guide.form
if back_button then
str = crafting_guide.form_back
end
str = str .. "label[0,0;Furnace:]"
str = str .. "item_image_button[0,1;1,1;" .. recipe.input .. ";" .. recipe.input .. ";]"
str = str .. "item_image_button[1,1;1,1;" .. recipe.pattern .. ";" .. recipe.pattern .. ";]"
str = str .. "item_image_button[2,1;1,1;" .. recipe.output .. ";" .. recipe.output .. ";]"
return str
end
function crafting_guide.get_item_formspec(page, player)
page = page or 0
local str = crafting_guide.form_items
@ -61,7 +76,7 @@ function crafting_guide.get_item_formspec(page, player)
table.sort(items)
for _,name in ipairs(items) do
if (minetest.get_all_craft_recipes(name) or creative_priv) and
if ((minetest.get_all_craft_recipes(name) or furnace.get_recipe(name)) or creative_priv) and
i < (8*6)*(page+1) then
if i > (8*6)*(page)-1 then
str = str .. "item_image_button["..x..","..y..";1,1;"..name..";"..name..";]"
@ -146,6 +161,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
local crafts = minetest.get_all_craft_recipes(i)
if crafts then
minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true))
elseif furnace.get_recipe(i) then
minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_furnace_formspec(furnace.get_recipe(i),true))
end
end
end
@ -165,13 +182,13 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
for i,j in pairs(fields) do
local crafts = minetest.get_all_craft_recipes(i)
local has_creative_priv = minetest.get_player_privs(player:get_player_name()).creative
if crafts or has_creative_priv then
if has_creative_priv then
player:get_inventory():add_item("main", i .. " 99")
print("[crafting_guide] give " .. player:get_player_name() .. " " .. i .. " 99")
else
minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true))
end
if has_creative_priv then
player:get_inventory():add_item("main", i .. " 99")
print("[crafting_guide] give " .. player:get_player_name() .. " " .. i .. " 99")
elseif crafts then
minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_formspec(crafts,true))
elseif furnace.get_recipe(i) then
minetest.show_formspec(player:get_player_name(), "crafting_guide:book", crafting_guide.get_furnace_formspec(furnace.get_recipe(i),true))
end
end
end

View File

@ -5,6 +5,15 @@ function furnace.register_recipe(def)
table.insert(furnace.recipes, def)
end
function furnace.get_recipe(item)
for i,recipe in ipairs(furnace.recipes) do
if recipe.output == item then
return recipe
end
end
return nil
end
local furnace_form = "size[8,9]"
local furnace_form = furnace_form..default.gui_colors
local furnace_form = furnace_form..default.gui_bg