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)
|
||||
end
|
||||
|
||||
local function getAmount()
|
||||
if isint(recipe[2][1]) then
|
||||
local q = recipe[2][1]
|
||||
recipe[2][1] = nil
|
||||
return q
|
||||
local function get_amount(_)
|
||||
if isint(recipe[_][1]) then
|
||||
return recipe[_][1]
|
||||
else return 1 end
|
||||
end
|
||||
|
||||
local function register(amount, recipe)
|
||||
minetest.register_craft({
|
||||
output = output.." "..amount,
|
||||
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])
|
||||
local function get_type(_)
|
||||
if type(recipe[_][2]) == "string" then
|
||||
return recipe[_][2]
|
||||
end
|
||||
end
|
||||
|
||||
-- Check type
|
||||
if recipe[1] == "single" then single()
|
||||
elseif recipe[1] == "multiple" then multiple()
|
||||
else return microexpansion.log("invalid recipe for definition "..output..". "..dump(recipe[2])) end
|
||||
local function register(_)
|
||||
local def = {
|
||||
type = get_type(_),
|
||||
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
|
||||
|
||||
-- [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)`
|
||||
__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
|
||||
microexpansion.register_recipe("default:steelblock", {
|
||||
"single",
|
||||
{ 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", "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.
|
||||
|
||||
__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.
|
||||
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.
|
||||
|
||||
#### `register_item(itemstring, def)`
|
||||
__Usage:__ `microexpansion.register_item(<itemstring (string)>, <item definition (table)>`
|
||||
|
@ -14,11 +14,11 @@ me.register_node("fuel_fired_generator", {
|
||||
"fuelgen_front",
|
||||
},
|
||||
recipe = {
|
||||
"single",
|
||||
{ 1,
|
||||
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" },
|
||||
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ 1, {
|
||||
{ "default:steel_ingot", "default:furnace", "default:steel_ingot" },
|
||||
{"default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
}
|
||||
},
|
||||
groups = { cracky = 1 },
|
||||
@ -38,11 +38,11 @@ me.register_node("super_smelter", {
|
||||
"super_smelter_front",
|
||||
},
|
||||
recipe = {
|
||||
"single",
|
||||
{ 1,
|
||||
{ "default:furnace", "default:furnace", "default:furnace" },
|
||||
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
{ 1, {
|
||||
{ "default:furnace", "default:furnace", "default:furnace" },
|
||||
{ "default:steel_ingot", "microexpansion:machine_casing", "default:steel_ingot" },
|
||||
{ "default:steel_ingot", "default:steel_ingot", "default:steel_ingot" },
|
||||
},
|
||||
},
|
||||
},
|
||||
groups = { cracky = 1 },
|
||||
|
@ -9,9 +9,9 @@ local me = microexpansion
|
||||
me.register_item("steel_infused_obsidian_ingot", {
|
||||
description = "Steel Infused Obsidian Ingot",
|
||||
recipe = {
|
||||
"single",
|
||||
{ 1,
|
||||
{ "default:steel_ingot", "default:obsidian_shard", "default:steel_ingot" },
|
||||
{ 1, {
|
||||
{ "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", {
|
||||
description = "Machine Casing",
|
||||
recipe = {
|
||||
"single",
|
||||
{ 1,
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:copper_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", "default:copper_ingot", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user