Module register.lua

MOB Registration

Functions

cmer.register_mob (def) Registers a new mob.
cmer.register_alias (old_mob, new_mob) Registers an alias for other mob, e.g.

Tables

CreatureDef Creature definition table.

Definition Tables

StatsDef Stats definition table.
ModeDef Modes definition table.
ModelDef Model definition table.
AnimationDef Animations defiintion table.
SoundsDef Sounds definition table.
SoundDef Sound definition.
DropDef Item drops definition table.
CombatDef Combat definition table.
SpawnDef Spawning definition table.
ABMNodesDef ABM nodes definition table.
SpawnerDef Spawner definition table.

Callbacks

CreatureDef.on_activate (self, staticdata, dtime_s) Called when mob (re-)activated.
CreatureDef.on_step (self, dtime) Called each server step, after movement and collision processing.
CreatureDef.on_punch (self, puncher, time_from_last_punch, tool_capabilities, dir, damage) Called when mob is punched.
CreatureDef.on_rightclick (self, clicker) Called when mob is right-clicked.
CreatureDef.on_death (self, killer) Called when mob dies.
CreatureDef.get_staticdata (self) Must return a table to save mob data (serialization is done by MOB-Engine).


Functions

cmer.register_mob (def)
Registers a new mob.

Parameters:

Returns:

    bool true if successfule.
cmer.register_alias (old_mob, new_mob)
Registers an alias for other mob, e.g. from other mods or removed ones.

Parameters:

  • old_mob string Name of mob to be replaced. E.g. "creatures:oerrki"
  • new_mob string Name of mob that will replace instances old one. E.g. "creatures:oerkki"

Returns:

    bool true if successful.

Tables

CreatureDef
Creature definition table.

Fields:

Definition Tables

StatsDef
Stats definition table.

Fields:

  • hp int Full health level (1 HP = 1/2 player heart).
  • hostile bool Is mob hostile (required for mode "attack") (default: false). (optional)
  • lifetime int After which time mob despawns, in seconds. (optional)
  • dies_when_tamed bool Stop despawn when tamed (default: false). (optional)
  • can_jump int Height in nodes (default: 0). (optional)
  • can_swim bool Can mob swim or will it drown (default: false). (optional)
  • can_fly bool Allows to fly (requires mode "fly") and disable step sounds (default: false). (optional)
  • can_burn bool Takes damage of lava (default: false). (optional)
  • can_panic bool Runs fast around when hit (requires mode "walk") (default: false). (optional)
  • has_falldamage bool Deals damage if falling more than 3 blocks (default: false). (optional)
  • has_knockback bool Get knocked back when hit (default: false). (optional)
  • sneaky bool Disables step sounds if true (default: false). (optional)
  • light table

    Which light level will burn creature (requires can_burn = true).

    Example:

    light = {min=10, max=15}
    
    (optional)
ModeDef

Modes definition table.

Entity behavior definition. Behavior types are idle, walk, attack, follow, eat, death, & panic. The sum of all modes must be 1.0.

Example:

modes = {
  idle = {chance=0.3,},
  walk = {chance=0.7, moving_speed=1,},
}

Fields:

  • chance float Number between 0.0 and 1.0 (*NOTE: sum of all modes MUST be 1.0*). If chance is 0 then mode is not chosen automatically.
  • duration int Time in seconds until the next mode is chosen (depending on chance).
  • moving_speed int Moving speed (walking/flying/swimming). (optional)
  • update_yaw int Timer in seconds until the looking dir is changed. If moving_speed > 0 then the moving direction is also changed. (optional)
  • radius int (follow & eat modes only) Search distance in blocks/nodes for player.
  • timer int (follow & eat modes only) Time in seconds between each check for player.
  • items table (follow & eat modes only) Table of items to make mob follow in format {<Itemname>, <Itemname>}; e.g. {"farming:wheat"}.
  • nodes table (eat mode only) Eatable nodes in format {<Itemname>, <Itemname>}; e.g. {"default:dirt_with_grass"}.
ModelDef
Model definition table.

Fields:

  • mesh string Mesh name (see Minetest Documentation for supported filetypes).
  • textures table Table of textures (see Minetest Documentation).
  • collisionbox NodeBox Defines mesh collision box (see Minetest Documentation). (optional)
  • scale table Sets visual scale (default: {x=1, y=1}). (optional)
  • rotation float Sets rotation offset when moving (default: 0.0). (optional)
  • backface_culling bool Set to true to enable backface culling. (optional)
  • animations table Table of AnimationDef used if defined. (optional)
  • collide_with_objects bool Collide with other objects (default: true). (optional)
AnimationDef

Animations defiintion table.

Animations coincide with modes. E.g. idle, walk, etc.

Example:

animations = {
  idle = {start=25, stop=75, speed=15,},
  walk = {start=75, stop=100, speed=15,},
}

Fields:

  • start int Start frame.
  • stop int End frame.
  • speed int Animation speed.
  • loop bool If false, animation if just played once (default: true). (optional)
  • duration int (death mode only) Sets time the animation needs until mob is removed. (optional)
SoundsDef

Sounds definition table.

Sounds can be defined for these actions: *on_damage*, *on_death*, swim, & random.

random is a table of SoundDef that will be played randomly during the modes for which they are set.

Example:

sounds = {
  on_damage = {name="creatures_horse_neigh_02", gain=1.0},
  on_death = {name="creatures_horse_snort_02", gain=1.0},
  random = {
    idle = {name="creatures_horse_snort_01", gain=1.0},
    follow = {name="creatures_horse_neigh_01", gain=1.0, time_min=10},
  },
}

Fields:

  • on_damage SoundDef Sound played when entity is hit. (optional)
  • on_death SoundDef Sound played when entity dies. (optional)
  • swim SoundDef Sound played while entity is swimming. (optional)
  • Random table Sounds that will play randomly during specified modes. E.g. idle, walk, etc. (optional)
SoundDef
Sound definition.

Fields:

  • name string Sound file name without file type extension (e.g. "mysound", not "mysound.ogg") (see Minetest documentation).
  • gain float Sound gain (see Minetest documentation).
  • distance int Distance in blocks/nodes at which sound can be heard. (optional)
  • time_min int (random mode only) Minimum time in seconds between sounds. (optional)
  • time_max int (random mode only) Maximum time in seconds between sounds. (optional)
DropDef

Item drops definition table.

Example:

drops = {
  {"default:wood"}, -- 1 item with 100% chance
  {"default:wool", 1, chance=0.3}, -- 1 item with 30% chance
  {"default:stick", {min=2, max=3}, chance=0.2}, -- between 2-3 items with 20% chance
}
CombatDef
Combat definition table.

Fields:

  • attack_damage int How much damage is dealt on each hit.
  • attack_speed float Time in seconds between hits (default: 1.0). (optional)
  • attack_radius float Distance in blocks mob can reach to hit.
  • search_enemy bool true to search enemies to attack.
  • search_timer int Time in seconds to search an enemy (only if none found yet) (default: 2). (optional)
  • search_radius int Radius in blocks within enemies are searched.
  • search_type string What enemy is being searched (see types at cmer.findTarget).
SpawnDef
Spawning definition table.

Fields:

  • abm_nodes ABMNodesDef On what nodes mob can spawn.
  • abm_interval int Time in seconds until Minetest tries to find a node with set specs (default: 44). (optional)
  • abm_chance int Chance is 1/<chance> (default: 7000). (optional)
  • max_number int Maximum mobs of this kind per mapblock (16x16x16).
  • number int How many mobs are spawned if found suitable spawn position. Can be int or table: number = {min=<value>, max=<value>}
  • time_range table Time range in time of day format (0-24000) (table with min & max values). (optional)
  • light table Min and max lightvalue at spawn position (table with min & max values). (optional)
  • height_limit table Min and max height (world Y coordinate) (table with min & max values). (optional)
  • spawner SpawnerDef Is set a spawner_node is added to creative inventory. (optional)
ABMNodesDef
ABM nodes definition table.

Fields:

  • spawn_on table List of nodes on which the mob can spawn. (optional)
  • neighbors table List of nodes that should be neighbors where mob can spawn. Can be nil or table as above (default: {"air"}). (optional)
SpawnerDef
Spawner definition table.

Fields:

  • range int Defines an area (in blocks/nodes) within mobs are spawned.
  • number int Maxmimum number of mobs spawned in area defined via range.
  • description string Item description as string. (optional)
  • light table Min and max lightvalue at spawn position. (optional)

Callbacks

CreatureDef.on_activate (self, staticdata, dtime_s)
Called when mob (re-)activated.

Note: staticdata is deserialized by MOB-Engine (including custom values).

Parameters:

  • self
  • staticdata string Formatted string data to be deserialized.
  • dtime_s int The time passed since the object was unloaded, which can be used for updating the entity state.
CreatureDef.on_step (self, dtime)
Called each server step, after movement and collision processing.

Parameters:

  • self
  • dtime float Usually 0.1 seconds, as per the dedicated_server_step setting in minetest.conf.

Returns:

    bool Prevents default action when returns true.
CreatureDef.on_punch (self, puncher, time_from_last_punch, tool_capabilities, dir, damage)
Called when mob is punched.

Parameters:

  • self
  • puncher ObjectRef
  • time_from_last_punch Meant for disallowing spamming of clicks.
  • tool_capabilities table See: http://minetest.gitlab.io/minetest/tools.html
  • dir Unit vector of direction of punch. Always defined. Points from the puncher to the punched.
  • damage int Damage that will be done to entity.

Returns:

    bool Prevents default action when returns true.
CreatureDef.on_rightclick (self, clicker)
Called when mob is right-clicked.

Parameters:

  • self
  • clicker ObjectRef Entity that did the punching.

Returns:

    bool Prevents default action when returns true.
CreatureDef.on_death (self, killer)
Called when mob dies.

Parameters:

  • self
  • killer ObjectRef (can be nil)
CreatureDef.get_staticdata (self)

Must return a table to save mob data (serialization is done by MOB-Engine).

e.g:

return {
  custom_mob_data = self.my_value,
}

Parameters:

  • self

Returns:

    table
generated by LDoc 1.4.6 Last updated 2021-06-01 20:03:03