recipe with json
parent
c1682fd6dc
commit
b80bc136a1
|
@ -344,35 +344,76 @@ minerdream.register_craftitems=function(tdef,cdef)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
local parse_recipe_element=function(tdef,recipe_item)
|
||||
local out=nil
|
||||
local found=true
|
||||
if recipe_item ~= nil then
|
||||
if recipe_item ~= "" then
|
||||
if tdef[recipe_item] ~= nil then
|
||||
out = tdef[recipe_item].node_name or tdef[recipe_item].item_name
|
||||
end
|
||||
if string.match(recipe_item,"@") then
|
||||
local sw=string.split(recipe_item,"@")
|
||||
if minerdream.items[sw[1]] ~= nil then
|
||||
local ti=minerdream.items[sw[1]]
|
||||
if ti[sw[2]] ~= nil then
|
||||
out=ti[sw[2]].node_name or ti[sw[2]].item_name
|
||||
end
|
||||
if out == nil then
|
||||
found = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return out,found
|
||||
end
|
||||
|
||||
minerdream.register_crafts=function(tdef,cdef)
|
||||
if cdef ~= nil then
|
||||
for _,ccdef in pairs(cdef) do
|
||||
if ccdef.output ~= nil and ccdef.recipe ~= nil then
|
||||
local bcraft=true
|
||||
-- analyse, if recipe refers to items in definition
|
||||
for k,v in pairs(ccdef.recipe) do
|
||||
if type(v) == "table" then
|
||||
for l,w in pairs(v) do
|
||||
if tdef[w] ~= nil then
|
||||
if tdef[w].node_name ~= nil then
|
||||
ccdef.recipe[k][l]=tdef[w].node_name
|
||||
if type(ccdef.recipe)=="table" then
|
||||
for k,v in pairs(ccdef.recipe) do
|
||||
if type(v) == "table" then
|
||||
for l,w in pairs(v) do
|
||||
local pre,pref=parse_recipe_element(tdef,w)
|
||||
if pref then
|
||||
if pre~=nil then
|
||||
ccdef.recipe[k][l]=pre
|
||||
end
|
||||
else
|
||||
bcraft = false
|
||||
end
|
||||
end
|
||||
if string.match(w,"@") then
|
||||
local sw=string.split(w,"@")
|
||||
if minerdream.items[sw[1]] ~= nil then
|
||||
local ti=minerdream.items[sw[1]]
|
||||
if ti[sw[2]] ~= nil then
|
||||
local ni=ti[sw[2]].node_name or ti[sw[2]].item_name
|
||||
if ni ~= nil then
|
||||
ccdef.recipe[k][l]=ni
|
||||
end
|
||||
end
|
||||
else
|
||||
bcraft = false
|
||||
table.insert(minerdream.delayed_crafts,cdef)
|
||||
end
|
||||
if type(v) == "string" then
|
||||
local pre,pref=parse_recipe_element(tdef,v)
|
||||
if pref then
|
||||
if pre~=nil then
|
||||
ccdef.recipe[k]=pre
|
||||
end
|
||||
end end end end
|
||||
else
|
||||
bcraft = false
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
if type(ccdef.recipe)=="string" then
|
||||
local pre,pref=parse_recipe_element(tdef,ccdef.recipe)
|
||||
if pref then
|
||||
if pre ~= nil then
|
||||
ccdef.recipe={pre}
|
||||
end
|
||||
else bcraft=false end
|
||||
end
|
||||
local pre,pref=parse_recipe_element(tdef,ccdef.output)
|
||||
if pref then
|
||||
if pre ~= nil then ccdef.output=pre end
|
||||
else bcraft = false end
|
||||
if bcraft then
|
||||
minetest.register_craft(ccdef)
|
||||
else
|
||||
|
|
|
@ -47,14 +47,20 @@
|
|||
},
|
||||
"crafts":{
|
||||
"dust16":{
|
||||
"output":"minerdream:cryolith_dust_part16 16",
|
||||
"output":"minerdream:cryolith_dust_part9 9",
|
||||
"recipe":[["dust"]]
|
||||
},
|
||||
"dust162d":{
|
||||
"output":"dust",
|
||||
"recipe":[["minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9"],
|
||||
["minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9"],
|
||||
["minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9","minerdream:cryolith_dust_part9"]]
|
||||
}
|
||||
},
|
||||
"craftitems":{
|
||||
"cryolith_dust_part16":{
|
||||
"cryolith_dust_part9":{
|
||||
"stackmax":200,
|
||||
"description":"16th part dust of cryolite",
|
||||
"description":"9th part dust of cryolite",
|
||||
"inventory_image":"minerdream_cryolite_dust_part16.png"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue