api.txt 15 KB

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