Craft guide : fix regression causing alternative recipes being updated on the whole server

This commit is contained in:
jp 2015-12-29 01:04:32 +01:00
parent 9c16002db6
commit a309f95c36

View File

@ -34,10 +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}}}
} }
local group_num = 1 function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, recipe_num, group_num, filter)
local recipe_num = 1
function worktable.craft_output_recipe(pos, start_i, pagenum, stackname, 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
@ -303,15 +300,18 @@ 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, "") worktable.craft_output_recipe(pos, 0, 1, nil, 1, 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
recipe_num = recipe_num + 1 recipe_num = recipe_num + 1
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, recipe_num, 1, filter)
elseif fields.alternate_group then elseif fields.alternate_group 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 group_num = tonumber(formspec:match("Recipe%s(%d+)")) or 1
local group_num_max = tonumber(formspec:match("Recipe.*of%s(%d+)")) or 1 local group_num_max = tonumber(formspec:match("Recipe.*of%s(%d+)")) or 1
if group_num >= group_num_max then if group_num >= group_num_max then
@ -320,17 +320,17 @@ function worktable.fields(pos, _, fields, sender)
group_num = group_num + 1 group_num = group_num + 1
end end
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, filter) 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, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, 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, fields.filter:lower()) worktable.craft_output_recipe(pos, 0, 1, nil, 1, 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, "") worktable.craft_output_recipe(pos, 0, 1, nil, 1, 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,12 +346,9 @@ 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, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, 1, 1, filter)
end end
recipe_num = 1
group_num = 1
inv:set_list("item_craft_input", {}) inv:set_list("item_craft_input", {})
inv:set_list("craft_output_recipe", {}) inv:set_list("craft_output_recipe", {})
end end
@ -420,7 +417,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, filter) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, stackname, 1, 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)