mirror of
https://github.com/theFox6/microexpansion.git
synced 2024-12-26 15:37:37 +01:00
Add ore definition registration API
This commit is contained in:
parent
1638d081eb
commit
e33131a695
29
api.lua
29
api.lua
@ -33,6 +33,19 @@ function microexpansion.register_recipe(output, recipe)
|
||||
end
|
||||
end
|
||||
|
||||
-- [function] Register oredef
|
||||
function microexpansion.register_oredef(ore, def)
|
||||
local function register(_)
|
||||
local def = def[_]
|
||||
def.ore = "microexpansion:"..ore
|
||||
minetest.register_ore(def)
|
||||
end
|
||||
|
||||
for _, i in ipairs(def) do
|
||||
register(_)
|
||||
end
|
||||
end
|
||||
|
||||
-- [local function] Choose description colour
|
||||
local function desc_colour(status, desc)
|
||||
if status == "unstable" then
|
||||
@ -77,17 +90,27 @@ function microexpansion.register_node(itemstring, def)
|
||||
-- Update texture
|
||||
if auto_complete ~= false then
|
||||
for _,i in ipairs(def.tiles) do
|
||||
def.tiles[_] = BASENAME.."_"..i..".png"
|
||||
local prefix = ""
|
||||
if def.type == "ore" then
|
||||
prefix = "ore_"
|
||||
end
|
||||
|
||||
def.tiles[_] = BASENAME.."_"..prefix..i..".png"
|
||||
end
|
||||
end
|
||||
-- Colour description
|
||||
def.description = desc_colour(def.status, def.description)
|
||||
|
||||
-- register craftitem
|
||||
-- Register craftitem
|
||||
minetest.register_node(BASENAME..":"..itemstring, def)
|
||||
|
||||
-- if recipe, register recipe
|
||||
-- if recipe, Register recipe
|
||||
if def.recipe then
|
||||
microexpansion.register_recipe(BASENAME..":"..itemstring, def.recipe)
|
||||
end
|
||||
|
||||
-- if oredef, Register oredef
|
||||
if def.oredef then
|
||||
microexpansion.register_oredef(BASENAME..":"..itemstring, def.oredef)
|
||||
end
|
||||
end
|
||||
|
28
doc/api.md
28
doc/api.md
@ -22,14 +22,36 @@ microexpansion.register_recipe("default:steelblock", {
|
||||
})
|
||||
```
|
||||
|
||||
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.
|
||||
The above registers a two recipes 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_oredef(ore, def)`
|
||||
__Usage:__ `microexpansion.register_oredef(<ore itemstring (string)>, <definition (table)>`
|
||||
|
||||
This custom API allows registering multiple ore definitions for a single node in one table. The table structure is quite simple, each definition is placed in an annonymous table in which the normal ore definitions are placed (excluding the ore itemstring). See below for a basic example.
|
||||
|
||||
```lua
|
||||
microexpansion.register_oredef("microexpansion:incranium", {
|
||||
{
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
},
|
||||
...
|
||||
})
|
||||
```
|
||||
|
||||
See the [wiki documentation](http://dev.minetest.net/minetest.register_ore) for more information about the accepted or parameters.
|
||||
|
||||
#### `register_item(itemstring, def)`
|
||||
__Usage:__ `microexpansion.register_item(<itemstring (string)>, <item definition (table)>`
|
||||
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `inventory_image` parameter is modified to enforce the naming style adding `microexpansion_` to the beginning of the specified path, and `.png` to the end. If not `inventory_image` is provided, the itemstring is used and then undergoes the above modification. This allows shortening and even removing the `inventory_image` code, while passing everything else (aside from `usedfor`) on to `minetest.register_craftitem`. One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red.
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `inventory_image` parameter is modified to enforce the naming style adding `microexpansion_` to the beginning of the specified path, and `.png` to the end. If not `inventory_image` is provided, the itemstring is used and then undergoes the above modification. This allows shortening and even removing the `inventory_image` code, while passing everything else (aside from `usedfor`) on to `minetest.register_craftitem`. One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red. The recipe can be automatically registered and defined right in the item definition with the `recipe` table. See `microexpansion.register_recipe` for more information.
|
||||
|
||||
#### `register_node(itemstring, def)`
|
||||
__Usage:__ `microexpansion.register_node(<itemstring (string)>, <item definition (table)>`
|
||||
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `tiles` table is modified so as to simplify the definition when registering the node. Each texture in the `tiles` table has `microexpansion_` added to the beginning and `.png` to the end. This means that rather than specifying something like `microexpansion_chest_top.png`, only `chest_top` is required. __Note:__ the texture path "autocomplete" functionality can be disabled by settings `auto_complete` to `false` in the definition (useful if using textures from another mod). One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red.
|
||||
This API function accepts the same parameters in the definition table as does `minetest.register_craftitem`, however, it makes several modifications to the parameters before passing them on. A new parameter, `usedfor`, is introduced, which if provided is appened on a new line in grey to the item description, a good way to specify what the item does or include more information about it. The `tiles` table is modified so as to simplify the definition when registering the node. Each texture in the `tiles` table has `microexpansion_` added to the beginning and `.png` to the end. This means that rather than specifying something like `microexpansion_chest_top.png`, only `chest_top` is required. __Note:__ the texture path "autocomplete" functionality can be disabled by settings `auto_complete` to `false` in the definition (useful if using textures from another mod). One final extra parameter is `status`, which if set to `no` the description is red, if set to `unstable` the description is `orange`, and if anything else the description is red. The recipe can be automatically registered and defined right in the item definition with the `recipe` table. See `microexpansion.register_recipe` for more information. You can also automatically register ore definitions for the current node with `microexpansion.register_oredef`.
|
@ -1,44 +1,43 @@
|
||||
-- ores/init.lua
|
||||
|
||||
local me = microexpansion
|
||||
|
||||
-- [register] Incranium Ore
|
||||
minetest.register_node("microexpansion:incranium", {
|
||||
me.register_node("incranium", {
|
||||
description = "Incranium Ore",
|
||||
tiles = { "incranium_ore.png" },
|
||||
tiles = { "incranium" },
|
||||
is_ground_content = true,
|
||||
drop = "microexpansion:incranium",
|
||||
groups = { cracky=3, stone=1 },
|
||||
type = "ore",
|
||||
oredef = {
|
||||
{
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
-- [ore] Register Incranium Ore
|
||||
minetest.register_ore({
|
||||
ore_type = "blob",
|
||||
ore = "microexpansion:incranium",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
})
|
||||
|
||||
|
||||
-- "Supernatet", pronounced "Super-nat-et" is Latin for "float", this ore will
|
||||
-- float up if there are no blocks above it, so be careful!
|
||||
-- Supernatet ore will be used to craft wings of flight
|
||||
minetest.register_node("microexpansion:supernatet", {
|
||||
me.register_node("supernatet", {
|
||||
description = "Supernatant Ore",
|
||||
tiles = { "supernatet_ore.png" },
|
||||
tiles = { "supernatet" },
|
||||
is_ground_content = true,
|
||||
drop = "microexpansion:supernatet",
|
||||
type = "ore",
|
||||
groups = { cracky=3, stone=1 },
|
||||
})
|
||||
|
||||
-- [ore] Register Supernatet Ore
|
||||
minetest.register_ore({
|
||||
ore_type = "blob",
|
||||
ore = "microexpansion:supernatet_ore",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
oredef = {
|
||||
ore_type = "blob",
|
||||
wherein = "default:stone",
|
||||
clust_scarcity = 4*4*4,
|
||||
clust_num_ores = 4,
|
||||
clust_size = 3,
|
||||
y_min = -300,
|
||||
y_max = -90,
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user