Lua API: Mod API Overview

Introduction

You can create a mod using this function:

openminer.mod_loader:register_mod("mod_name")

Mod name should match this regex: ^[a-zA-Z0-9_]+$

Everytime you define an id for a mod element, this name will be prepended to it. For example, myitem will become mymod:myitem.

The name can't be group because this namespace is already used by the engine.

Example

local mod = openminer.mod_loader:register_mod("mymod")

mod:block {
    id = "myblock",
    name = "My Block",
    tiles = "myblock.png",
}

mod:item {
    id = "myitem",
    name = "My Item",
    tiles = "myitem.png",
}

mod:crafting_recipe {
    result = {
        id = "mymod:myblock",
        amount = 1
    },

    pattern = {
        "###",
        "# #",
        "###"
    },

    keys = {["#"] = "default:cobblestone"}
}

mod:smelting_recipe {
    input = {id = "mymod:myitem", amount = 1},
    output = {id = "mymod:myblock", amount = 1}
}

Functions

id

Returns the string ID of the mod.

path

Returns the path of the mod, relative to current working directory.

Note: In callbacks like on_block_activated, the mod object may be invalid. You'll need to create a local variable at the beginning of the file:

local modpath = mod:path()

Registration functions

block

Defines a block from a table, see this page for more information.

biome

Defines a biome from a table, see this page for more information.

dimension

Defines a dimension from a table, see this page for more information.

item

Defines an item from a table, see this page for more information.

recipe

Defines a recipe from a table, see this page for more information.

sky

Defines a sky type from a table, see this page for more information.

tree

Defines a tree type from a table, see this page for more information.