api.txt 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. MOB API (28th September 2016)
  2. The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
  3. minetest.conf settings*
  4. 'enable_damage' if true monsters will attack players (default is true)
  5. 'only_peaceful_mobs' if true only animals will spawn in game (default is false)
  6. 'mobs_disable_blood' if false blood effects appear when mob is hit (default is false)
  7. 'mobs_spawn_protected' if set to 1 then mobs will not spawn in protected areas (default is 0)
  8. 'remove_far_mobs' if true then mobs that are outside players visual range will be removed (default is false)
  9. 'mobname_chance' can change specific mob chance rates or set to 0 to disable e.g. mobs_animal:cow_chance = 1000
  10. 'mob_difficulty' sets difficulty level (health and hit damage multiplied by this number), defaults to 1.0.
  11. mobs:register_mob(name, definition)
  12. This functions registers a new mob as a Minetest entity.
  13. 'name' is the name of the mob (e.g. "mobs:dirt_monster")
  14. definition is a table with the following fields
  15. 'type' the type of the mob ("monster", "animal" or "npc")
  16. 'passive' will mob defend itself, set to false to attack
  17. 'docile_by_day' when true, mob will not attack during daylight hours unless provoked
  18. 'attacks_monsters' usually for npc's to attack monsters in area
  19. 'group_attack' true to defend same kind of mobs from attack in area
  20. 'attack_animals' true for monster to attack animals as well as player and npc's
  21. 'attack_specific' has a table of entity names that monsters can attack {"player", "mobs_animal:chicken"}
  22. 'hp_min' minimum health
  23. 'hp_max' maximum health (mob health is randomly selected between both)
  24. 'physical' same is in minetest.register_entity()
  25. 'collisionbox' same is in minetest.register_entity()
  26. 'visual' same is in minetest.register_entity()
  27. 'visual_size' same is in minetest.register_entity()
  28. 'textures' same is in minetest.register_entity()
  29. although you can add multiple lines for random textures {{"texture1.png"},{"texture2.png"}},
  30. 'gotten_texture' alt. texture for when self.gotten value is set to true (used for shearing sheep)
  31. 'child_texture' texture of mod for when self.child is set to true
  32. 'mesh' same is in minetest.register_entity()
  33. 'gotten_mesh' alternative mesh for when self.gotten is true (used for sheep)
  34. 'makes_footstep_sound' same is in minetest.register_entity()
  35. 'follow' item when held will cause mob to follow player, can be single string "default:apple" or table {"default:apple", "default:diamond"}
  36. 'view_range' the range in that the monster will see the playerand follow him
  37. 'walk_chance' chance of mob walking around
  38. 'jump_chance' chance of mob jumping around, set above to 0 for jumping mob only
  39. 'walk_velocity' the velocity when the monster is walking around
  40. 'run_velocity' the velocity when the monster is attacking a player
  41. 'runaway' when true mob will turn and run away when punched
  42. 'stepheight' minimum node height mob can walk onto without jumping (default: 0.6)
  43. 'jump' can mob jump, true or false
  44. 'jump_height' height mob can jump, default is 6
  45. 'fly' can mob fly, true or false (used for swimming mobs also)
  46. 'fly_in' node name that mob flys inside, e.g "air", "default:water_source" for fish
  47. 'damage' the damage per second
  48. 'recovery_time' how much time from when mob is hit to recovery (default: 0.5)
  49. 'knock_back' strength of knock-back when mob hit (default: 3)
  50. 'immune_to' table holding special tool/item names and damage the incur e.g.
  51. {"default:sword_wood", 0}, {"default:gold_lump", -10} immune to sword, gold lump heals
  52. 'blood_amount' number of droplets that appear when hit
  53. 'blood_texture' texture of blood droplets (default: "mobs_blood.png")
  54. 'drops' is list of tables with the following fields:
  55. 'name' itemname e.g. default:stone
  56. 'chance' the inverted chance (same as in abm) to get the item
  57. 'min' the minimum number of items
  58. 'max' the maximum number of items
  59. 'armor' the armor (integer)(3=lowest; 1=highest)(fleshy group is used)
  60. 'drawtype' "front" or "side" (DEPRECATED, replaced with below)
  61. 'rotate' set mob rotation, 0=front, 90=side, 180=back, 270=other side
  62. 'water_damage' the damage per second if the mob is in water
  63. 'lava_damage' the damage per second if the mob is in lava
  64. 'light_damage' the damage per second if the mob is in light
  65. 'fall_damage' will mob be hurt when falling from height
  66. 'fall_speed' speed mob falls (default: -10 and has to be lower than -2)
  67. 'fear_height' when mob walks near a drop then anything over this value makes it stop and turn back (default is 0 to disable)
  68. 'on_die' a function that is called when the mob is killed the parameters are (self, pos)
  69. 'floats' 1 to float in water, 0 to sink
  70. 'on_rightclick' its same as in minetest.register_entity()
  71. 'pathfinding' set to 1 for mobs to use pathfinder feature to locate player, set to 2 so they can build/break also (only works with dogfight attack)
  72. 'attack_type' the attack type of a monster
  73. 'dogfight' follows player in range and attacks when in reach
  74. 'shoot' shoots defined arrows when player is within range
  75. 'explode' follows player in range and will flash and explode when in reach
  76. 'dogshoot' shoots arrows when in range and one on one attack when in reach
  77. 'dogshoot_switch' allows switching between shoot and dogfight modes inside dogshoot using timer (1 = shoot, 2 = dogfight)
  78. 'dogshoot_count_max' number of seconds before switching above modes.
  79. 'custom_attack' is a function that is called when mob is in range to attack player, parameters are (self, to_attack)
  80. 'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations
  81. 'on_blast' is called when TNT explodes near mob, function uses (object, damage) and returns (do_damage, do_knockback, drops)
  82. 'explosion_radius' radius of explosion attack (defaults to 1)
  83. 'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of the arrow is required
  84. 'shoot_interval' the minimum shoot interval
  85. 'shoot_offset' +/- value to position arrow/fireball when fired
  86. 'reach' how far a reach this mob has, default is 3
  87. 'sounds' this is a table with sounds of the mob
  88. 'random' random sounds during gameplay
  89. 'war_cry' sound when starting to attack player
  90. 'attack' sound when attacking player
  91. 'shoot_attack' sound when attacking player by shooting arrow/entity
  92. 'damage' sound when being hit
  93. 'death' sound when killed
  94. 'jump' sound when jumping
  95. 'explode' sound when exploding
  96. 'distance' maximum distance sounds are heard from (default is 10)
  97. 'animation' a table with the animation ranges and speed of the model
  98. 'stand_start' start frame of stand animation
  99. 'stand_end' end frame of stand animation
  100. 'walk_start' start frame of walk animation
  101. 'walk_end' end frame of walk animation
  102. 'run_start' start frame of run animation
  103. 'run_end' end frame of run animation
  104. 'punch_start' start frame of punch animation
  105. 'punch_end' end frame of punch animation
  106. 'punch2_start' start frame of alt.punch animation
  107. 'punch2_end' end frame of alt.punch animation
  108. 'shoot_start' start frame of shoot animation
  109. 'shoot_end' end frame of shoot animation
  110. 'speed_normal' normal animation speed
  111. 'speed_run' running animation speed
  112. 'speed_punch' punching animation speed
  113. 'speed_punch2' alternative punching animation speed
  114. 'speed_shoot' shooting animation speed
  115. 'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"}
  116. 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg"
  117. 'replace_rate' how random should the replace rate be (typically 10)
  118. 'replace_offset' +/- value to check specific node to replace
  119. The mob api also has some preset variables and functions that it will remember for each mob
  120. 'self.gotten' this is used for obtaining milk from cow and wool from sheep
  121. 'self.horny' when animal fed enough it is set to true and animal can breed with same animal
  122. 'self.child' used for when breeding animals have child, will use child_texture and be half size
  123. 'self.owner' string used to set owner of npc mobs, typically used for dogs
  124. 'self.order' set to "follow" or "stand" so that npc will follow owner or stand it's ground
  125. 'on_die' a function that is called when mob is killed
  126. 'do_custom' a custom function that is called while mob is active and which has access to all of the self.* variables e.g. (self.health for health or self.standing_in for node status), return with 'false' to skip remainder of mob API.
  127. mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
  128. mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle)
  129. These functions register a spawn algorithm for the mob. Without this function the call the mobs won't spawn.
  130. 'name' is the name of the animal/monster
  131. 'nodes' is a list of nodenames on that the animal/monster can spawn on top of
  132. 'neighbors' is a list of nodenames on that the animal/monster will spawn beside (default is {"air"} for mobs:register_spawn)
  133. 'max_light' is the maximum of light
  134. 'min_light' is the minimum of light
  135. 'interval' is same as in register_abm() (default is 30 for mobs:register_spawn)
  136. 'chance' is same as in register_abm()
  137. 'active_object_count' mob is only spawned if active_object_count_wider of ABM is <= this
  138. 'min_height' is the maximum height the mob can spawn
  139. 'max_height' is the maximum height the mob can spawn
  140. 'day_toggle' true for day spawning, false for night or nil for anytime
  141. ... also a simpler way to handle mob spawns has been added with the mobs:spawn(def) command which uses above names to make settings clearer:
  142. mobs:spawn({name = "mobs_monster:tree_monster",
  143. nodes = {"group:leaves"},
  144. max_light = 7,
  145. })
  146. Players can override the spawn chance for each mob registered by adding a line to their minetest.conf file with a new value, the lower the value the more each mob will spawn e.g.
  147. mobs_animal:sheep_chance 11000 or mobs_monster:sand_monster_chance 100
  148. For each mob that spawns with this function is a field in mobs.spawning_mobs. It tells if the mob should spawn or not. Default is true. So other mods can only use the API of this mod by disabling the spawning of the default mobs in this mod.
  149. mobs:register_arrow(name, definition)
  150. This function registers a arrow for mobs with the attack type shoot.
  151. 'name' is the name of the arrow
  152. -definition' is a table with the following values:
  153. 'visual' same is in minetest.register_entity()
  154. 'visual_size' same is in minetest.register_entity()
  155. 'textures' same is in minetest.register_entity()
  156. 'velocity' the velocity of the arrow
  157. 'drop' if set to true any arrows hitting a node will drop as item
  158. 'hit_player' a function that is called when the arrow hits a player; this function should hurt the player
  159. the parameters are (self, player)
  160. 'hit_mob' a function that is called when the arrow hits a mob; this function should hurt the mob
  161. the parameters are (self, player)
  162. 'hit_node' a function that is called when the arrow hits a node
  163. the parameters are (self, pos, node)
  164. 'tail' when set to 1 adds a trail or tail to mob arrows
  165. 'tail_texture' texture string used for above effect
  166. 'on_step' is a custom function when arrow is active, nil for default.
  167. mobs:register_egg(name, description, background, addegg)
  168. This function registers a spawn egg which can be used by admin to properly spawn in a mob.
  169. 'name' this is the name of your new mob to spawn e.g. "mob:sheep"
  170. 'description' the name of the new egg you are creating e.g. "Spawn Sheep"
  171. 'background' the texture displayed for the egg in inventory
  172. 'addegg' would you like an egg image in front of your texture (1=yes, 0=no)
  173. 'no_creative' when set to true this stops spawn egg appearing in creative mode for destructive mobs like Dungeon Masters
  174. mobs:explosion(pos, radius, fire, smoke)
  175. This function generates an explosion which removes nodes in a specific radius and replace them with fire or air. Protection nodes, obsidian and locked chests will not be destroyed although a normal chest will drop it's contents.
  176. 'pos' centre position of explosion
  177. 'radius' radius of explosion (typically set to 3)
  178. 'fire' should fire appear in explosion (1=yes, 0=no)
  179. 'smoke' should smoke appear in explosion (1=yes, 0=no)
  180. 'sound' sound played when mob explodes
  181. mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
  182. This function is generally called inside the on_rightclick section of the mob api code, it provides a chance of capturing the mob by hand, using the net or magic lasso items, and can also have the player take the mob by force if tamed and replace with another item entirely.
  183. 'self' mob information
  184. 'clicker' player information
  185. 'chance_hand' chance of capturing mob by hand (1 to 100) 0 to disable
  186. 'chance_net' chance of capturing mob using net (1 to 100) 0 to disable
  187. 'chance_lasso' chance of capturing mob using magic lasso (1 to 100) 0 to disable
  188. 'force_take' take mob by force, even if tamed (true or false)
  189. 'replacewith' once captured replace mob with this item instead
  190. mobs:feed_tame(self, clicker, feed_count, breed)
  191. This function allows the mob to be fed the item inside self.follow be it apple, wheat or whatever a set number of times and be tamed or bred as a result.
  192. 'self' mob information
  193. 'clicker' player information
  194. 'feed_count' number of times mob must be fed to tame or breed
  195. 'breed' true or false stating if mob can be bred and a child created afterwards
  196. 'tame' true or false stating if mob can be tamed so player can pick them up
  197. Useful Internal Variables
  198. 'self.health' contains current health of mob
  199. 'self.texture_list' contains list of all mob textures
  200. 'self.child_texture' contains mob child texture when growing up
  201. 'self.base_texture' contains current skin texture which was randomly selected from textures list
  202. 'self.gotten' true when sheep have been sheared or cows have been milked, a toggle switch which can be used for many functions
  203. 'self.child' true when mob is currently a child (when two mobs have bred and current mob is the outcome)
  204. 'self.hornytimer' background timer that controls breeding functions and mob childhood timings