1
0
mirror of https://codeberg.org/minenux/minetest-mod-xdecor synced 2023-10-20 21:43:39 -07:00

Work Table : get rid of some metadatas

This commit is contained in:
jp 2015-12-21 00:13:43 +01:00
parent b4b8af0f5e
commit de26ae52b2

View File

@ -34,14 +34,13 @@ 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) 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 floor = math.floor local floor = math.floor
pagenum = floor(pagenum) or 0 pagenum = floor(pagenum) or 0
local inventory_size = meta:get_int("inventory_size") local inventory_size = #meta:to_table().inventory.inv_items_list or 0
local recipe_num = meta:get_int("recipe_num") local recipe_num = meta:get_int("recipe_num")
local filter = meta:get_string("filter") or ""
local pagemax = floor((inventory_size - 1) / (8*4) + 1) or 0 local pagemax = floor((inventory_size - 1) / (8*4) + 1) or 0
local craft, dye_color, flower_color = {}, "", "" local craft, dye_color, flower_color = {}, "", ""
@ -167,7 +166,6 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname)
"label[0,7.5;"..stackname:sub(1,30).."]" "label[0,7.5;"..stackname:sub(1,30).."]"
end end
meta:set_int("start_i", start_i)
meta:set_string("formspec", formspec) meta:set_string("formspec", formspec)
end end
@ -188,7 +186,6 @@ function worktable.craftguide_update(pos, filter)
inv:set_size("inv_items_list", #inv_items_list) inv:set_size("inv_items_list", #inv_items_list)
inv:set_list("inv_items_list", inv_items_list) inv:set_list("inv_items_list", inv_items_list)
meta:set_int("inventory_size", #inv_items_list)
end end
function worktable.crafting(pos) function worktable.crafting(pos)
@ -264,8 +261,10 @@ end
function worktable.fields(pos, _, fields, sender) function worktable.fields(pos, _, fields, sender)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local start_i = meta:get_int("start_i") or 0 local formspec = meta:to_table().fields.formspec
local inventory_size = meta:get_int("inventory_size") local filter = formspec:match("filter;;([%w_:]+)") or ""
local start_i = tonumber(formspec:match("inv_items_list;.*;(%d+)%]")) or 0
local inventory_size = #meta:to_table().inventory.inv_items_list or 0
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 = meta:get_int("recipe_num") local recipe_num = meta:get_int("recipe_num")
@ -281,7 +280,7 @@ function worktable.fields(pos, _, fields, sender)
end end
worktable.crafting(pos) worktable.crafting(pos)
elseif fields.craftguide then elseif fields.craftguide then
worktable.craft_output_recipe(pos, 0, 1, nil) worktable.craft_output_recipe(pos, 0, 1, nil, "")
elseif fields.alternate then elseif fields.alternate then
inv:set_list("craft_output_recipe", {}) inv:set_list("craft_output_recipe", {})
if recipe_num >= #minetest.get_all_craft_recipes(inputstack) then if recipe_num >= #minetest.get_all_craft_recipes(inputstack) then
@ -289,19 +288,17 @@ function worktable.fields(pos, _, fields, sender)
else else
meta:set_int("recipe_num", recipe_num + 1) meta:set_int("recipe_num", recipe_num + 1)
end end
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, inputstack, 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) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, filter)
elseif fields.search then elseif fields.search then
meta:set_string("filter", fields.filter:lower())
worktable.craftguide_update(pos, fields.filter:lower()) worktable.craftguide_update(pos, fields.filter:lower())
worktable.craft_output_recipe(pos, 0, 1, nil) worktable.craft_output_recipe(pos, 0, 1, nil, fields.filter:lower())
elseif fields.clearfilter then elseif fields.clearfilter then
meta:set_string("filter", "")
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, "")
elseif fields.prev or fields.next then elseif fields.prev or fields.next then
if fields.prev or start_i >= inventory_size then if fields.prev or start_i >= inventory_size then
start_i = start_i - 8*4 start_i = start_i - 8*4
@ -312,7 +309,7 @@ function worktable.fields(pos, _, fields, sender)
start_i = 0 start_i = 0
end end
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, nil, filter)
end end
meta:set_int("recipe_num", 1) meta:set_int("recipe_num", 1)
@ -383,14 +380,16 @@ function worktable.move(pos, from_list, from_index, to_list, to_index, count, _)
local inv = minetest.get_meta(pos):get_inventory() local inv = minetest.get_meta(pos):get_inventory()
local stackname = inv:get_stack(from_list, from_index):get_name() local stackname = inv:get_stack(from_list, from_index):get_name()
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local start_i = meta:get_int("start_i") local formspec = meta:to_table().fields.formspec
local filter = formspec:match("filter;;([%w_:]+)") or ""
local start_i = tonumber(formspec:match("inv_items_list;.*;(%d+)%]")) or 0
if from_list == "storage" and to_list == "storage" then if from_list == "storage" and to_list == "storage" then
return count return count
elseif inv:is_empty("item_craft_input") and from_list == "inv_items_list" and elseif inv:is_empty("item_craft_input") and from_list == "inv_items_list" and
to_list == "item_craft_input" then to_list == "item_craft_input" then
--print(dump(minetest.get_all_craft_recipes(stackname))) --print(dump(minetest.get_all_craft_recipes(stackname)))
worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, stackname) worktable.craft_output_recipe(pos, start_i, start_i / (8*4) + 1, stackname, 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)
@ -511,7 +510,7 @@ minetest.register_abm({
-- Wear : 0-65535 | 0 = new condition. -- Wear : 0-65535 | 0 = new condition.
tool:add_wear(-500) tool:add_wear(-500)
hammer:add_wear(800) hammer:add_wear(700)
inv:set_stack("tool", 1, tool) inv:set_stack("tool", 1, tool)
inv:set_stack("hammer", 1, hammer) inv:set_stack("hammer", 1, hammer)