Craft guide : show only items which have a recipe

This commit is contained in:
jp 2015-12-01 16:50:27 +01:00
parent 0189532095
commit 00f1ea298e
2 changed files with 32 additions and 19 deletions

View File

@ -82,6 +82,7 @@ local function allowed(tool)
if t then return true end if t then return true end
end end
end end
return false return false
end end
@ -94,6 +95,7 @@ function enchanting.put(_, listname, _, stack, _)
elseif listname == "tool" and not allowed(toolname) then elseif listname == "tool" and not allowed(toolname) then
return 0 return 0
end end
return 1 return 1
end end
@ -123,7 +125,9 @@ xdecor.register("enchantment_table", {
allow_metadata_inventory_put = enchanting.put, allow_metadata_inventory_put = enchanting.put,
allow_metadata_inventory_move = function(...) return 0 end, allow_metadata_inventory_move = function(...) return 0 end,
on_metadata_inventory_take = function(pos, listname, _, _, _) on_metadata_inventory_take = function(pos, listname, _, _, _)
if listname == "tool" then enchanting.formspec(pos, nil) end if listname == "tool" then
enchanting.formspec(pos, nil)
end
end end
}) })

View File

@ -113,6 +113,7 @@ function worktable.craft_output_recipe(pos, start_i, pagenum, stackname)
def = "default:"..def:sub(7, string.len(def)) def = "default:"..def:sub(7, string.len(def))
end end
end end
inv:set_stack("craft_output_recipe", k, def) inv:set_stack("craft_output_recipe", k, def)
end end
@ -131,9 +132,9 @@ function worktable.craftguide_update(pos, filter)
local inv_items_list = {} local inv_items_list = {}
for name, def in pairs(minetest.registered_items) do for name, def in pairs(minetest.registered_items) do
if not (def.groups.not_in_creative_inventory == 1) and def.name ~= "unknown" if not (def.groups.not_in_creative_inventory == 1) and
and def.description and def.description ~= "" then minetest.get_craft_recipe(name).items and
def.description and def.description ~= "" then
if filter and def.name:find(filter) then if filter and def.name:find(filter) then
inv_items_list[#inv_items_list+1] = name inv_items_list[#inv_items_list+1] = name
elseif filter == "all" then elseif filter == "all" then
@ -196,6 +197,7 @@ function worktable.main(pos)
"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)
return formspec return formspec
end end
@ -226,11 +228,9 @@ function worktable.fields(pos, _, fields, sender)
if fields.storage then if fields.storage then
worktable.storage(pos) worktable.storage(pos)
elseif fields.craft then
worktable.crafting(pos)
elseif fields.back then elseif fields.back then
worktable.main(pos) worktable.main(pos)
elseif fields.backcraft then elseif fields.backcraft or fields.craft then
worktable.crafting(pos) worktable.crafting(pos)
elseif fields.craft_output_recipe then elseif fields.craft_output_recipe then
worktable.craft_output_recipe(pos, 0, 1) worktable.craft_output_recipe(pos, 0, 1)
@ -256,6 +256,7 @@ function worktable.fields(pos, _, fields, sender)
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)
end end
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
@ -270,9 +271,12 @@ end
function worktable.contains(table, element) function worktable.contains(table, element)
if table then if table then
for _, value in pairs(table) do for _, value in pairs(table) do
if value == element then return true end if value == element then
return true
end end
end end
end
return false return false
end end
@ -283,15 +287,16 @@ function worktable.put(_, listname, _, stack, _)
local tdef = minetest.registered_tools[stn] local tdef = minetest.registered_tools[stn]
local twear = stack:get_wear() local twear = stack:get_wear()
if listname == "input" and if listname == "input" and worktable.contains(nodes[mod], node) then
worktable.contains(nodes[mod], node) then return count return count
elseif listname == "hammer" and elseif listname == "hammer" and stn == "xdecor:hammer" then
stn == "xdecor:hammer" then return 1 return 1
elseif listname == "tool" and tdef and twear > 0 then elseif listname == "tool" and tdef and twear > 0 then
return 1 return 1
elseif listname == "storage" then elseif listname == "storage" then
return count return count
end end
return 0 return 0
end end
@ -311,6 +316,7 @@ function worktable.take(pos, listname, _, stack, player)
listname == "craft_output_recipe" then listname == "craft_output_recipe" then
return 0 return 0
end end
return stack:get_count() return stack:get_count()
end end
@ -322,9 +328,8 @@ function worktable.move(pos, from_list, from_index, to_list, to_index, count, _)
if from_list == "storage" and to_list == "storage" then if from_list == "storage" and to_list == "storage" then
return count return count
end elseif inv:is_empty("item_craft_input") and from_list == "inv_items_list" and
if minetest.get_craft_recipe(stackname).items and inv:is_empty("item_craft_input") and to_list == "item_craft_input" then
from_list == "inv_items_list" and to_list == "item_craft_input" then
--print(dump(minetest.get_craft_recipe(stackname))) --print(dump(minetest.get_craft_recipe(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)
@ -334,6 +339,7 @@ function worktable.move(pos, from_list, from_index, to_list, to_index, count, _)
return 1 return 1
end end
return 0 return 0
end end
@ -350,6 +356,7 @@ local function update_inventory(inv, inputstack)
if not worktable.contains(nodes[mod], node) then return end if not worktable.contains(nodes[mod], node) then return end
output[#output+1] = mat.."_"..n[1].." "..count output[#output+1] = mat.."_"..n[1].." "..count
end end
inv:set_list("forms", output) inv:set_list("forms", output)
end end
@ -434,7 +441,9 @@ minetest.register_abm({
local hammer = inv:get_stack("hammer", 1) local hammer = inv:get_stack("hammer", 1)
local wear = tool:get_wear() local wear = tool:get_wear()
if tool:is_empty() or hammer:is_empty() or wear == 0 then return end if tool:is_empty() or hammer:is_empty() or wear == 0 then
return
end
-- Wear : 0-65535 | 0 = new condition. -- Wear : 0-65535 | 0 = new condition.
tool:add_wear(-500) tool:add_wear(-500)