Craft guide : fix incorrect recipes made of group nodes

This commit is contained in:
jp 2015-12-30 18:53:58 +01:00
parent f4975389b8
commit f5956b969d
3 changed files with 69 additions and 96 deletions

View File

@ -17,7 +17,7 @@ minetest.register_craft({
}) })
minetest.register_craft({ minetest.register_craft({
output = "xdecor:bowl", output = "xdecor:bowl 3",
recipe = { recipe = {
{"group:wood", "", "group:wood"}, {"group:wood", "", "group:wood"},
{"", "group:wood", ""} {"", "group:wood", ""}

View File

@ -3,35 +3,34 @@ screwdriver = screwdriver or {}
function enchanting.formspec(pos, tooltype) function enchanting.formspec(pos, tooltype)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local formspec = "size[9,9;]".. local formspec = [[ size[9,9;]
default.gui_slots..default.get_hotbar_bg(0.5,4.5).. bgcolor[#080808BB;true]
"bgcolor[#080808BB;true]".. background[0,0;9,9;ench_ui.png]
"background[0,0;9,9;ench_ui.png]".. list[context;tool;0.9,2.9;1,1;]
"list[context;tool;0.9,2.9;1,1;]".. list[context;mese;2,2.9;1,1;]
"list[context;mese;2,2.9;1,1;]".. list[current_player;main;0.5,4.5;8,4;]
"list[current_player;main;0.5,4.5;8,4;]".. image[2,2.9;1,1;mese_layout.png]
"image[2,2.9;1,1;mese_layout.png]".. tooltip[sharp;Your sword kills faster]
"tooltip[sharp;Your sword kills faster]".. tooltip[durable;Your tool lasts longer]
"tooltip[durable;Your tool lasts longer]".. tooltip[fast;Your tool digs faster]
"tooltip[fast;Your tool digs faster]".. tooltip[strong;Your armor is more resistant]
"tooltip[strong;Your armor is more resistant]".. tooltip[speed;Your speed is increased] ]]
"tooltip[speed;Your speed is increased]"
if tooltype == "sword" then if tooltype == "sword" then
formspec = formspec.."image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]" formspec = formspec.."image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;Sharpness]"
elseif tooltype == "tool" then elseif tooltype == "tool" then
formspec = formspec.. formspec = formspec..
"image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]".. [[ image_button[3.9,0.85;4,0.92;bg_btn.png;fast;Efficiency]
"image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability]" image_button[3.9,1.77;4,1.12;bg_btn.png;durable;Durability] ]]
elseif tooltype == "armor" then elseif tooltype == "armor" then
formspec = formspec.."image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]" formspec = formspec.."image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]"
elseif tooltype == "boots" then elseif tooltype == "boots" then
formspec = formspec.. formspec = formspec..
"image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]".. [[ image_button[3.9,0.85;4,0.92;bg_btn.png;strong;Strength]
"image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed]" image_button[3.9,1.77;4,1.12;bg_btn.png;speed;Speed] ]]
end end
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec..default.gui_slots..default.get_hotbar_bg(0.5,4.5))
return formspec return formspec
end end

View File

@ -34,7 +34,7 @@ local def = { -- Nodebox name, yield, definition.
{"innerstair", 1, {{-.5,-.5,-.5,.5,0,.5},{-.5,0,0,.5,.5,.5},{-.5,0,-.5,0,.5,0}}} {"innerstair", 1, {{-.5,-.5,-.5,.5,0,.5},{-.5,0,0,.5,.5,.5},{-.5,0,-.5,0,.5,0}}}
} }
function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_num, group_num, filter) function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_num, filter)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local inventory_size = #meta:to_table().inventory.inv_items_list local inventory_size = #meta:to_table().inventory.inv_items_list
@ -127,20 +127,18 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
inv:set_size("craft_output_recipe", 1) inv:set_size("craft_output_recipe", 1)
end end
local craft, group_nodes = {}, {} local craft = {}
for k, def in pairs(stack_items) do for k, def in pairs(stack_items) do
craft[#craft+1] = def craft[#craft+1] = def
if def and def:find("^group:") then if def and def:find("^group:") then
if def:find("liquid$") then if def:find("liquid") then
def = "default:water_source" def = "default:water_source"
elseif def:find("vessel$") then
def = "vessels:glass_bottle"
elseif def:find("wool") then elseif def:find("wool") then
def = "wool:white" def = "wool:white"
elseif def:find("dye") then elseif def:find("dye") then
local dye_color = def:match(".*_([%w_]+)") local dye_color = def:match(".*_([%w_]+)")
def = "dye:"..dye_color def = "dye:"..dye_color
elseif def:find("^group:flower") then elseif def:find("flower") then
local flower_color = def:match(".*_([%w_]+)") local flower_color = def:match(".*_([%w_]+)")
if flower_color == "red" then if flower_color == "red" then
def = "flowers:rose" def = "flowers:rose"
@ -163,32 +161,24 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_
else else
for node, definition in pairs(minetest.registered_items) do for node, definition in pairs(minetest.registered_items) do
for group in pairs(definition.groups) do for group in pairs(definition.groups) do
if group == def:match("^group:([%w_]+)$") and not if group == def:match("^group:([%w_]+)$") then
minetest.serialize(group_nodes):match(node) and inv:set_stack("craft_output_recipe", k, node)
#group_nodes < 10 then
group_nodes[#group_nodes+1] = node
end end
end end
end end
def = group_nodes[group_num]
end end
end end
end end
inv:set_stack("craft_output_recipe", k, def) if not def:find("^group:") then
end inv:set_stack("craft_output_recipe", k, def)
end
if #group_nodes > 1 and items_num == 1 then
formspec = formspec..
"button[0,5.7;1.6,1;alternate_group;Alternate]"..
"label[0,5.2;Recipe "..group_num.." of "..#group_nodes.."]"
end end
formspec = formspec.. formspec = formspec..
"image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]".. "image[4,6.3;1,1;gui_furnace_arrow_bg.png^[transformR90]"..
"button[0,6.5;1.6,1;trash;Clear]".. "button[0,6.5;1.6,1;trash;Clear]"..
"label[0,7.5;"..stackname:sub(1, 30).."]" "label[0,7.5;"..stackname:sub(1,30).."]"
end end
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)
@ -215,54 +205,51 @@ end
function worktable.crafting(pos) function worktable.crafting(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local formspec = "size[8,7;]"..xbg.. local formspec = [[ size[8,7;]
default.get_hotbar_bg(0,3.3).. list[current_player;main;0,3.3;8,4;]
"list[current_player;main;0,3.3;8,4;]".. image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
"image[5,1;1,1;gui_furnace_arrow_bg.png^[transformR270]".. button[0,0;1.5,1;back;< Back]
"button[0,0;1.5,1;back;< Back]".. button[0,1;1.5,1;craftguide;Guide]
"button[0,1;1.5,1;craftguide;Guide]".. list[current_player;craft;2,0;3,3;]
"list[current_player;craft;2,0;3,3;]".. list[current_player;craftpreview;6,1;1,1;]
"list[current_player;craftpreview;6,1;1,1;]".. listring[current_player;main]
"listring[current_player;main]".. listring[current_player;craft] ]]
"listring[current_player;craft]"
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.3))
end end
function worktable.storage(pos) function worktable.storage(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local formspec = "size[8,7]"..xbg.. local formspec = [[ size[8,7]
default.get_hotbar_bg(0,3.25).. list[context;storage;0,1;8,2;]
"list[context;storage;0,1;8,2;]".. list[current_player;main;0,3.25;8,4;]
"list[current_player;main;0,3.25;8,4;]".. listring[context;storage]
"listring[context;storage]".. listring[current_player;main]
"listring[current_player;main]".. button[0,0;1.5,1;back;< Back] ]]
"button[0,0;1.5,1;back;< Back]"
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.25))
end end
function worktable.main(pos) function worktable.main(pos)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local formspec = "size[8,7;]"..xbg.. local formspec = [[ size[8,7;]
default.get_hotbar_bg(0,3.25).. label[0.9,1.23;Cut]
"label[0.9,1.23;Cut]".. label[0.9,2.23;Repair]
"label[0.9,2.23;Repair]".. box[-0.05,1;2.05,0.9;#555555]
"box[-0.05,1;2.05,0.9;#555555]".. box[-0.05,2;2.05,0.9;#555555]
"box[-0.05,2;2.05,0.9;#555555]".. image[3,1;1,1;gui_furnace_arrow_bg.png^[transformR270]
"image[3,1;1,1;gui_furnace_arrow_bg.png^[transformR270]".. image[0,1;1,1;worktable_saw.png]
"image[0,1;1,1;worktable_saw.png]".. image[0,2;1,1;worktable_anvil.png]
"image[0,2;1,1;worktable_anvil.png]".. image[3,2;1,1;hammer_layout.png]
"image[3,2;1,1;hammer_layout.png]".. list[context;input;2,1;1,1;]
"list[context;input;2,1;1,1;]".. list[context;tool;2,2;1,1;]
"list[context;tool;2,2;1,1;]".. list[context;hammer;3,2;1,1;]
"list[context;hammer;3,2;1,1;]".. list[context;forms;4,0;4,3;]
"list[context;forms;4,0;4,3;]".. list[current_player;main;0,3.25;8,4;]
"list[current_player;main;0,3.25;8,4;]".. button[0,0;2,1;craft;Crafting]
"button[0,0;2,1;craft;Crafting]".. button[2,0;2,1;storage;Storage] ]]
"button[2,0;2,1;storage;Storage]"
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec..xbg..default.get_hotbar_bg(0,3.25))
end end
function worktable.construct(pos) function worktable.construct(pos)
@ -300,37 +287,24 @@ function worktable.fields(pos, _, fields, sender)
worktable.crafting(pos) worktable.crafting(pos)
elseif fields.craftguide then elseif fields.craftguide then
if not meta:to_table().inventory.inv_items_list then return end -- legacy code if not meta:to_table().inventory.inv_items_list then return end -- legacy code
worktable.craft_output_recipe(pos, 0, 1, nil, 1, 1, "") worktable.craft_output_recipe(pos, 0, 1, nil, 1, "")
elseif fields.alternate then elseif fields.alternate then
inv:set_list("craft_output_recipe", {}) inv:set_list("craft_output_recipe", {})
local inputstack = inv:get_stack("item_craft_input", 1):get_name() local inputstack = inv:get_stack("item_craft_input", 1):get_name()
local recipe_num = tonumber(formspec:match("Recipe%s(%d+)")) or 1 local recipe_num = tonumber(formspec:match("Recipe%s(%d+)")) or 1
recipe_num = recipe_num + 1 recipe_num = recipe_num + 1
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, recipe_num, 1, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, recipe_num, filter)
elseif fields.alternate_group then
inv:set_list("craft_output_recipe", {})
local inputstack = inv:get_stack("item_craft_input", 1):get_name()
local group_num = tonumber(formspec:match("Recipe%s(%d+)")) or 1
local group_num_max = tonumber(formspec:match("Recipe.*of%s(%d+)")) or 1
if group_num >= group_num_max then
group_num = 1
else
group_num = group_num + 1
end
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, 1, group_num, filter)
elseif fields.trash or fields.search or fields.clearfilter or elseif fields.trash or fields.search or fields.clearfilter or
fields.prev or fields.next then fields.prev or fields.next then
if fields.trash then if fields.trash then
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, 1, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, filter)
elseif fields.search then elseif fields.search then
worktable.craftguide_update(pos, fields.filter:lower()) worktable.craftguide_update(pos, fields.filter:lower())
worktable.craft_output_recipe(pos, 0, 1, nil, 1, 1, fields.filter:lower()) worktable.craft_output_recipe(pos, 0, 1, nil, 1, fields.filter:lower())
elseif fields.clearfilter then elseif fields.clearfilter then
worktable.craftguide_update(pos, nil) worktable.craftguide_update(pos, nil)
worktable.craft_output_recipe(pos, 0, 1, nil, 1, 1, "") worktable.craft_output_recipe(pos, 0, 1, nil, 1, "")
elseif fields.prev or fields.next then elseif fields.prev or fields.next then
local inventory_size = #meta:to_table().inventory.inv_items_list local inventory_size = #meta:to_table().inventory.inv_items_list
@ -346,7 +320,7 @@ function worktable.fields(pos, _, fields, sender)
start_i = inventory_size - (inventory_size % (8*4)) start_i = inventory_size - (inventory_size % (8*4))
end end
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, 1, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, filter)
end end
inv:set_list("item_craft_input", {}) inv:set_list("item_craft_input", {})
@ -417,7 +391,7 @@ function worktable.move(pos, from_list, from_index, to_list, to_index, count, _)
local filter = formspec:match("filter;;([%w_:]+)") or "" local filter = formspec:match("filter;;([%w_:]+)") or ""
local start_i = tonumber(formspec:match("inv_items_list;.*;(%d+)%]")) or 0 local start_i = tonumber(formspec:match("inv_items_list;.*;(%d+)%]")) or 0
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, stackname, 1, 1, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, stackname, 1, filter)
minetest.after(0, function() minetest.after(0, function()
inv:set_stack(from_list, from_index, stackname) inv:set_stack(from_list, from_index, stackname)