Topic api
3D Armor API
Tables
ArmorDef | Armor definition table used for registering armor. |
ArmorDef.groups | Groups table. |
ArmorDef.armor_groups | Armor groups table. |
ArmorDef.damage_groups | Damage groups table. |
Methods
Armor Callbacks Registration
armor:register_on_update (func) | Registers a callback for when player visuals are update. |
armor:register_on_equip (func) | Registers a callback for when armor is equipped. |
armor:register_on_unequip (func) | Registers a callback for when armor is unequipped. |
armor:register_on_damage (func) | Registers a callback for when armor is damaged. |
armor:register_on_destroy (func) | Registers a callback for when armor is destroyed. |
Tables
- ArmorDef
-
Armor definition table used for registering armor.
Fields:
- description string Human-readable name/description.
- inventory_image string Image filename used for icon.
- groups table See: ArmorDef.groups
- armor_groups table See: ArmorDef.armor_groups
- damage_groups table See: ArmorDef.damage_groups
See also:
Usage:
local def = { description = "Wood Helmet", inventory_image = "3d_armor_inv_helmet_wood.png", groups = {armor_head=1, armor_heal=0, armor_use=2000, flammable=1}, armor_groups = {fleshy=5}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, }
- ArmorDef.groups
-
Groups table.
General groups defining item behavior.
Some commonly used groups: armor_<type>, armor_heal, armor_use
Fields:
- armor_type int The armor type. "head", "torso", "hands", "shield", etc. (Note: replace "type" with actual type).
- armor_heal int Healing value of armor when equipped.
- armor_use int Amount of uses/damage before armor "breaks".
See also:
Usage:
groups = { armor_head = 1, armor_heal = 5, armor_use = 2000, flammable = 1, }
- ArmorDef.armor_groups
-
Armor groups table.
Groups that this item is effective against when taking damage.
Some commonly used groups: fleshy
Usage:
armor_groups = { fleshy = 5, }
- ArmorDef.damage_groups
-
Damage groups table.
Groups that this item is effective on when used as a weapon/tool.
Some commonly used groups: cracky, snappy, choppy, crumbly, level
See also:
Usage:
damage_groups = { cracky = 3, snappy = 2, choppy = 3, crumbly = 2, level = 1, }
Methods
- armor:register_armor (name, def)
-
Registers a new armor item.
Parameters:
- name string Armor item technical name (ex: "3d_armor:helmet_gold").
- def ArmorDef Armor definition table.
Usage:
armor:register_armor("3d_armor:helmet_wood", { description = "Wood Helmet", inventory_image = "3d_armor_inv_helmet_wood.png", groups = {armor_head=1, armor_heal=0, armor_use=2000, flammable=1}, armor_groups = {fleshy=5}, damage_groups = {cracky=3, snappy=2, choppy=3, crumbly=2, level=1}, })
- armor:register_armor_group (group, base)
-
Registers a new armor group.
Parameters:
- group string Group ID.
- base int Base armor value.
- armor:run_callbacks (callback, player, index, stack)
-
Runs callbacks.
Parameters:
- armor:update_player_visuals (player)
-
Updates visuals.
Parameters:
- player ObjectRef
- armor:set_player_armor (player)
-
Sets player's armor attributes.
Parameters:
- player ObjectRef
- armor:punch (player, hitter[, time_from_last_punch[, tool_capabilities]])
-
Action when armor is punched.
Parameters:
- player ObjectRef Player wearing the armor.
- hitter ObjectRef Entity attacking player.
- time_from_last_punch int Time in seconds since last punch action. (optional)
- tool_capabilities table See entity_damage_mechanism. (optional)
- armor:damage (player, index, stack, use)
-
Action when armor is damaged.
Parameters:
- armor:get_weared_armor_elements (player)
-
Get elements of equipped armor.
Parameters:
- player ObjectRef
Returns:
-
table
List of equipped armors.
- armor:equip (player, itemstack)
-
Equips a piece of armor to a player.
Parameters:
Returns:
-
ItemStack
Leftover item stack.
- armor:unequip (player, armor_element)
-
Unequips a piece of armor from a player.
Parameters:
- armor:remove_all (player)
-
Removes all armor worn by player.
Parameters:
- player ObjectRef
- armor:get_player_skin (name)
-
Retrieves player's current skin.
Parameters:
- name string Player name.
Returns:
-
string
Skin filename.
- armor:update_skin (name)
-
Updates skin.
Parameters:
- name string Player name.
- armor:add_preview (preview)
-
Adds preview for armor inventory.
Parameters:
- preview string Preview image filename.
- armor:get_preview (name)
-
Retrieves preview for armor inventory.
Parameters:
- name string Player name.
Returns:
-
string
Preview image filename.
- armor:get_armor_formspec (name[, listring])
-
Retrieves armor formspec.
Parameters:
- name string Player name.
- listring
bool
Use
listring
formspec element (default:false
). (optional)
Returns:
-
string
Formspec formatted string.
- armor:get_element (item_name)
-
Retrieves element.
Parameters:
- item_name string
Returns:
-
Armor element.
- armor:serialize_inventory_list (list)
-
Serializes armor inventory.
Parameters:
- list table Inventory contents.
Returns:
- armor:deserialize_inventory_list (list_string)
-
Deserializes armor inventory.
Parameters:
- list_string string Serialized inventory contents.
Returns:
- armor:load_armor_inventory (player)
-
Loads armor inventory.
Parameters:
- player ObjectRef
Returns:
-
bool
- armor:save_armor_inventory (player)
-
Saves armor inventory.
Inventory is stored in PlayerMetaRef string "3d_armor_inventory".
Parameters:
- player ObjectRef
- armor:update_inventory (player)
-
Updates inventory.
DEPRECATED: Legacy inventory support.
Parameters:
- player
- armor:set_inventory_stack (player, i, stack)
-
Sets inventory stack.
Parameters:
- armor:get_valid_player (player, msg)
-
Checks for a player that can use armor.
Parameters:
Returns:
-
list
Player name & armor inventory.
Usage:
local name, inv = armor:get_valid_player(player, "[equip]")
- armor.drop_armor (pos, stack)
-
Drops armor item at given position.
Parameters:
- armor.set_skin_mod (mod)
-
Allows skin mod to be set manually.
Useful for skin mod forks that do not use the same name.
Parameters:
- mod string Name of skin mod. Recognized names are "simple_skins", "u_skins", & "wardrobe".
Armor Callbacks Registration
- armor:register_on_update (func)
-
Registers a callback for when player visuals are update.
Parameters:
- func function Function to be executed.
See also:
Usage:
armor:register_on_update(function(player, index, stack) -- code to execute end)
- armor:register_on_equip (func)
-
Registers a callback for when armor is equipped.
Parameters:
- func function Function to be executed.
Usage:
armor:register_on_equip(function(player, index, stack) -- code to execute end)
- armor:register_on_unequip (func)
-
Registers a callback for when armor is unequipped.
Parameters:
- func function Function to be executed.
Usage:
armor:register_on_unequip(function(player, index, stack) -- code to execute end)
- armor:register_on_damage (func)
-
Registers a callback for when armor is damaged.
Parameters:
- func function Function to be executed.
See also:
Usage:
armor:register_on_damage(function(player, index, stack) -- code to execute end)
- armor:register_on_destroy (func)
-
Registers a callback for when armor is destroyed.
Parameters:
- func function Function to be executed.
See also:
Usage:
armor:register_on_destroy(function(player, index, stack) -- code to execute end)