Skip to content

API Materials

Piggo41 edited this page Oct 12, 2026 · 5 revisions

Materials

Lua API / Materials

Block materials are named constants. This page covers custom tool and armor materials.

On this page

betamoon.materials.tools:add(definition)

Registers a reusable tool material and returns an opaque material handle accepted by tool declarations.

local alloy = betamoon.materials.tools:add {
    key = "mymod:tool_material/alloy", harvestLevel = 2,
    durability = 600, efficiency = 6, damage = 2
}
Field Type Requirement
key string Required material name.
harvestLevel integer Required harvest level.
durability integer Required maximum uses.
efficiency number Required mining efficiency.
damage integer Required attack-damage contribution.

betamoon.materials.armor:add(definition)

Registers a reusable armor material and returns an opaque material handle accepted by armor declarations.

local alloy = betamoon.materials.armor:add { key = "mymod:armor_material/alloy_armor", protection = 2 }
Field Type Requirement
key string Required material name.
protection integer Required nonnegative armor material value.

Material lookup

betamoon.materials.tools:get(key)

Returns a material previously declared in this script environment, using case-insensitive, trimmed lookup. If not declared locally, returns the supplied key string so a native material name can be passed onward.

local iron = betamoon.materials.tools:get("iron")

An unknown string is not validated by this lookup; a consuming tool declaration can reject it.

betamoon.materials.tools:getRequired(key)

Returns the locally declared material handle or raises a Lua error if missing. It does not resolve undeclared native material names.

local alloy = betamoon.materials.tools:getRequired("ALLOY")

betamoon.materials.armor:get(key)

Same local lookup/fallback-string behavior as tool material get, for armor materials.

local iron = betamoon.materials.armor:get("iron")

betamoon.materials.armor:getRequired(key)

Returns a locally declared armor material handle; missing declarations raise a Lua error.

local alloy = betamoon.materials.armor:getRequired("ALLOY_ARMOR")

Material handles and lifetime

Native material identities are retained across reload. Redeclaring an existing material with different defining properties requires restart. Export/import handles when another script needs a custom material.

Clone this wiki locally