mirror of
https://github.com/theFox6/microexpansion.git
synced 2024-11-25 16:43:44 +01:00
Improve recipe API
This commit is contained in:
parent
d58afdee89
commit
ce8269fb03
44
api.lua
44
api.lua
@ -7,36 +7,32 @@ function microexpansion.register_recipe(output, recipe)
|
|||||||
return n==math.floor(n)
|
return n==math.floor(n)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function getAmount()
|
local function get_amount(_)
|
||||||
if isint(recipe[2][1]) then
|
if isint(recipe[_][1]) then
|
||||||
local q = recipe[2][1]
|
return recipe[_][1]
|
||||||
recipe[2][1] = nil
|
|
||||||
return q
|
|
||||||
else return 1 end
|
else return 1 end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function register(amount, recipe)
|
local function get_type(_)
|
||||||
minetest.register_craft({
|
if type(recipe[_][2]) == "string" then
|
||||||
output = output.." "..amount,
|
return recipe[_][2]
|
||||||
recipe = recipe,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
local function single()
|
|
||||||
register(getAmount(), recipe[2])
|
|
||||||
end
|
|
||||||
|
|
||||||
local function multiple()
|
|
||||||
for i, item in ipairs(recipe) do
|
|
||||||
if i == 0 then return end
|
|
||||||
register(getAmount(), recipe[i])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Check type
|
local function register(_)
|
||||||
if recipe[1] == "single" then single()
|
local def = {
|
||||||
elseif recipe[1] == "multiple" then multiple()
|
type = get_type(_),
|
||||||
else return microexpansion.log("invalid recipe for definition "..output..". "..dump(recipe[2])) end
|
output = output.." "..tostring(get_amount(_)),
|
||||||
|
recipe = recipe[_][3] or recipe[_][2]
|
||||||
|
}
|
||||||
|
|
||||||
|
microexpansion.log("Recipe: "..dump(def))
|
||||||
|
minetest.register_craft(def)
|
||||||
|
end
|
||||||
|
|
||||||
|
for _, i in ipairs(recipe) do
|
||||||
|
register(_)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [local function] Choose description colour
|
-- [local function] Choose description colour
|
||||||
|
38
doc/api.md
38
doc/api.md
@ -4,39 +4,25 @@ The core API is composed of several functions to make registering new items, nod
|
|||||||
#### `register_recipe(output, def)`
|
#### `register_recipe(output, def)`
|
||||||
__Usage:__ `microexpansion.register_recipe(<output (string)>, <recipe (table)>)`
|
__Usage:__ `microexpansion.register_recipe(<output (string)>, <recipe (table)>)`
|
||||||
|
|
||||||
Though this may seem rather complex to understand, this is a very useful timesaving function when registering recipes. It allows registering multiple recipes at once in one table. The output must always remain the same as is specified as the first parameter, while the second parameter should be a table structured like one of the tables below.
|
Though this may seem rather complex to understand, this is a very useful timesaving function when registering recipes. It allows registering multiple recipes at once in one table. The output must always remain the same as is specified as the first parameter, while the second parameter should be a table structured like the table below.
|
||||||
|
|
||||||
__Single Recipe:__
|
__Example:__
|
||||||
```lua
|
```lua
|
||||||
microexpansion.register_recipe("default:steelblock", {
|
microexpansion.register_recipe("default:steelblock", {
|
||||||
"single",
|
{ 1, {
|
||||||
{ 1,
|
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
},
|
||||||
|
},
|
||||||
|
{ 1, "shapeless", {
|
||||||
|
"default:steel_ingot", "default:obsidian_shard", "default:steel_ingot",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
The above registers a single recipe for the item specified. The `1` specifies the output quantity.
|
The above registers a two recipees for the item specified. The `1` specifies the output quantity. `shapeless` causes the second recipe to be of the `shapeless` type. After the first one or two definitions (amount, type), the recipe can be specified as normal inside another sub-table. You can have as many recipe sub-tables as you want.
|
||||||
|
|
||||||
__Multiple Recipes:__
|
|
||||||
```lua
|
|
||||||
microexpansion.register_recipe("default:steelblock", {
|
|
||||||
"multiple",
|
|
||||||
{ 1,
|
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
|
||||||
},
|
|
||||||
{ 1,
|
|
||||||
{ "default:steel_ingot", "default:steel_ingot" },
|
|
||||||
{ "default:steel_ingot", "default:steel_ingot" },
|
|
||||||
}
|
|
||||||
})
|
|
||||||
```
|
|
||||||
|
|
||||||
The above registers multiple recipes for the item specified. The `1` specifies the output quantity.
|
|
||||||
|
|
||||||
#### `register_item(itemstring, def)`
|
#### `register_item(itemstring, def)`
|
||||||
__Usage:__ `microexpansion.register_item(<itemstring (string)>, <item definition (table)>`
|
__Usage:__ `microexpansion.register_item(<itemstring (string)>, <item definition (table)>`
|
||||||
|
@ -14,11 +14,11 @@ me.register_node("fuel_fired_generator", {
|
|||||||
"fuelgen_front",
|
"fuelgen_front",
|
||||||
},
|
},
|
||||||
recipe = {
|
recipe = {
|
||||||
"single",
|
{ 1, {
|
||||||
{ 1,
|
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" },
|
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||||
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
groups = { cracky = 1 },
|
groups = { cracky = 1 },
|
||||||
@ -38,11 +38,11 @@ me.register_node("super_smelter", {
|
|||||||
"super_smelter_front",
|
"super_smelter_front",
|
||||||
},
|
},
|
||||||
recipe = {
|
recipe = {
|
||||||
"single",
|
{ 1, {
|
||||||
{ 1,
|
{ "default:furnace", "default:furnace", "default:furnace" },
|
||||||
{ "default:furnace", "default:furnace", "default:furnace" },
|
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = { cracky = 1 },
|
groups = { cracky = 1 },
|
||||||
|
@ -9,9 +9,9 @@ local me = microexpansion
|
|||||||
me.register_item("steel_infused_obsidian_ingot", {
|
me.register_item("steel_infused_obsidian_ingot", {
|
||||||
description = "Steel Infused Obsidian Ingot",
|
description = "Steel Infused Obsidian Ingot",
|
||||||
recipe = {
|
recipe = {
|
||||||
"single",
|
{ 1, {
|
||||||
{ 1,
|
{ "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" },
|
||||||
{ "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" },
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
@ -20,11 +20,11 @@ me.register_item("steel_infused_obsidian_ingot", {
|
|||||||
me.register_item("machine_casing", {
|
me.register_item("machine_casing", {
|
||||||
description = "Machine Casing",
|
description = "Machine Casing",
|
||||||
recipe = {
|
recipe = {
|
||||||
"single",
|
{ 1, {
|
||||||
{ 1,
|
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
|
||||||
{"default:steel_ingot", "default:copper_ingot", "default:steel_ingot"},
|
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user