unified_inventory support for custom recipes

This commit is contained in:
Evert Prants 2018-12-13 12:19:08 +02:00
parent b853f52bd6
commit 8daed7e05e
Signed by: evert
GPG Key ID: 1688DA83D222D0B5
3 changed files with 39 additions and 0 deletions

View File

@ -1,3 +1,4 @@
local have_ui = minetest.get_modpath("unified_inventory")
elepm.craft = {} elepm.craft = {}
elepm.craft.types = {} elepm.craft.types = {}
@ -10,6 +11,14 @@ function elepm.register_craft_type(name, def)
gui_name = def.gui_name, gui_name = def.gui_name,
} }
if have_ui and unified_inventory.register_craft_type then
unified_inventory.register_craft_type(name, {
description = def.description or name,
width = def.inputs or 2,
height = 1,
})
end
elepm.craft[name] = {} elepm.craft[name] = {}
end end
@ -54,6 +63,34 @@ function elepm.register_craft(craftdef)
time = time time = time
} }
if have_ui then
local spec = {}
for item, count in pairs(recipe.recipe) do
spec[#spec+1] = ItemStack(item .. " " .. count)
end
if type(recipe.output) == "table" then
for _,itm in pairs(recipe.output) do
local itmst = ItemStack(itm)
unified_inventory.register_craft({
type = craftdef.type,
output = itmst,
items = spec,
width = 0,
})
end
return
end
unified_inventory.register_craft({
type = craftdef.type,
output = recipe.output,
items = spec,
width = 0,
})
end
table.insert(elepm.craft[ctype], recipe) table.insert(elepm.craft[ctype], recipe)
end end

View File

@ -1 +1,2 @@
elepower_dynamics elepower_dynamics
unified_inventory?

View File

@ -1,3 +1,4 @@
name = elepower_machines name = elepower_machines
description = Elepower machinery! description = Elepower machinery!
depends = elepower_dynamics depends = elepower_dynamics
optional_depends = unified_inventory