api.txt 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885
  1. Mobs Redo API
  2. =============
  3. Welcome to the world of mobs in minetest and hopefully an easy guide to defining
  4. your own mobs and having them appear in your worlds.
  5. Registering Mobs
  6. ----------------
  7. To register a mob and have it ready for use requires the following function:
  8. mobs:register_mob(name, definition)
  9. The 'name' of a mob usually starts with the mod name it's running from followed
  10. by it's own name e.g.
  11. "mobs_monster:sand_monster" or "mymod:totally_awesome_beast"
  12. ... and the 'definition' is a table which holds all of the settings and
  13. functions needed for the mob to work properly which contains the following:
  14. 'nametag' contains the name which is shown above mob.
  15. 'type' holds the type of mob that inhabits your world e.g.
  16. "animal" usually docile and walking around.
  17. "monster" attacks player or npc on sight.
  18. "npc" walk around and will defend themselves if hit first, they
  19. kill monsters.
  20. 'hp_min' has the minimum health value the mob can spawn with.
  21. 'hp_max' has the maximum health value the mob can spawn with.
  22. 'armor' holds strength of mob, 100 is normal, lower is more powerful
  23. and needs more hits and better weapons to kill.
  24. 'passive' when false allows animals to defend themselves when hit,
  25. otherwise they amble onwards.
  26. 'walk_velocity' is the speed that your mob can walk around.
  27. 'run_velocity' is the speed your mob can run with, usually when attacking.
  28. 'stand_chance' has a 0-100 chance value your mob will stand from walking.
  29. 'walk_chance' has a 0-100 chance value your mob will walk from standing,
  30. set to 0 for jumping mobs only.
  31. 'randomly_turn' if set to false then mob will not turn to face player or
  32. randomly turn while walking or standing.
  33. 'jump' when true allows your mob to jump updwards.
  34. 'jump_height' holds the height your mob can jump, 0 to disable jumping.
  35. 'can_leap' when true obstacles like fences or pits wont stop a mob
  36. from trying to jump out.
  37. 'stepheight' height of a block that your mob can easily walk up onto,
  38. defaults to 1.1.
  39. 'fly' when true allows your mob to fly around instead of walking.
  40. 'fly_in' holds the node name that the mob flies (or swims) around
  41. in e.g. "air" or "default:water_source".
  42. 'keep_flying' when true mobs like birds no longer stop and stand.
  43. 'stay_near' when set allows mobs the chance to stay around certain nodes.
  44. 'nodes' string or table of nodes to stay nearby e.g. "farming:straw"
  45. 'chance' chance of searching for above node(s), default is 10.
  46. 'runaway' if true causes animals to turn and run away when hit.
  47. 'pushable' when true mobs can be pushed by player or other mobs.
  48. 'view_range' how many nodes in distance the mob can see a player.
  49. 'damage' how many health points the mob does to a player or another
  50. mob when melee attacking.
  51. 'damage_group' group in which damage is dealt, dedaults to "fleshy".
  52. 'damage_texture_modifier' applies texture modifier on hit e.g "^[brighten"
  53. 'knock_back' when true has mobs falling backwards when hit, the greater
  54. the damage the more they move back.
  55. 'fear_height' is how high a cliff or edge has to be before the mob stops
  56. walking, 0 to turn off height fear.
  57. 'fall_speed' has the maximum speed the mob can fall at, default is -10.
  58. 'fall_damage' when true causes falling to inflict damage.
  59. 'water_damage' holds the damage per second infliced to mobs when standing in
  60. water.
  61. 'air_damage' holds damage per second inflicted to mob when standing in air.
  62. 'lava_damage' holds the damage per second inflicted to mobs when standing
  63. in lava.
  64. 'fire_damage' holds the damage per second inflicted to mobs when standing
  65. in fire.
  66. 'light_damage' holds the damage per second inflicted to mobs when light
  67. level is between the min and max values below
  68. 'light_damage_min' minimum light value when mob is affected (default: 14)
  69. 'light_damage_max' maximum light value when mob is affected (default: 15)
  70. 'suffocation' when > 0 mobs will suffocate inside solid blocks and will be
  71. hurt by the value given every second (0 to disable).
  72. 'floats' when set to 1 mob will float in water, 0 has them sink.
  73. 'follow' mobs follow player when holding any of the items which appear
  74. on this table, the same items can be fed to a mob to tame or
  75. breed e.g. {"farming:wheat", "default:apple", "group:fish"}
  76. 'reach' is how far the mob can attack player when standing
  77. nearby, default is 3 nodes.
  78. 'docile_by_day' when true has mobs wandering around during daylight
  79. hours and only attacking player at night or when
  80. provoked.
  81. 'attack_chance' 0 to 100 chance the mob will attack (default is 5).
  82. 'attack_monsters' when true mob will attack monsters.
  83. 'attack_animals' when true mob will attack animals.
  84. 'attack_npcs' when true mob will attack npcs within range.
  85. 'attack_players' when true mob will attack players nearby.
  86. 'owner_loyal' when true non-docile tamed mobs attack anything player
  87. punches when nearby.
  88. 'group_attack' when true has same mob type grouping together to attack
  89. offender.
  90. 'group_helper' string containing mob name that attacks alongside
  91. current mob when group attacking.
  92. mob is attacking in groups.
  93. 'attack_type' tells the api what a mob does when attacking the player
  94. or another mob:
  95. 'dogfight' is a melee attack when player is within mob reach.
  96. 'shoot' has mob shoot pre-defined arrows at player when inside
  97. view_range.
  98. 'dogshoot' has melee attack when inside reach and shoot attack
  99. when inside view_range.
  100. 'explode' causes mob to stop and explode when inside reach.
  101. 'explosion_radius' the radius of explosion node destruction,
  102. defaults to 1
  103. 'explosion_damage_radius' the radius of explosion entity & player damage,
  104. defaults to explosion_radius * 2
  105. 'explosion_timer' number of seconds before mob explodes while its target
  106. is still inside reach or explosion_damage_radius,
  107. defaults to 3.
  108. 'allow_fuse_reset' Allow 'explode' attack_type to reset fuse and resume
  109. chasing if target leaves the blast radius or line of
  110. sight. Defaults to true.
  111. 'stop_to_explode' When set to true (default), mob must stop and wait for
  112. explosion_timer in order to explode. If false, mob will
  113. continue chasing.
  114. 'arrow' holds the pre-defined arrow object to shoot when
  115. attacking.
  116. 'arrow_override' function that allows tweaking of arrow entity from
  117. inside mob definition (self) passed to function.
  118. 'dogshoot_switch' allows switching between attack types by using timers
  119. (1 for shoot, 2 for dogfight)
  120. 'dogshoot_count_max' contains how many seconds before switching from
  121. dogfight to shoot.
  122. 'dogshoot_count2_max' contains how many seconds before switching from shoot
  123. to dogfight.
  124. 'shoot_interval' has the number of seconds between shots.
  125. 'shoot_offset' holds the y position added as to where the
  126. arrow/fireball appears on mob.
  127. 'specific_attack' has a table of entity names that mob can also attack
  128. e.g. {"player", "mobs_animal:chicken"}.
  129. 'runaway_from' contains a table with mob names to run away from, add
  130. "player" to list to runaway from player also.
  131. 'ignore_invisibility' When true mob will still be able to see and attack
  132. player even if invisible (invisibility mod only).
  133. 'blood_amount' contains the number of blood droplets to appear when
  134. mob is hit.
  135. 'blood_texture' has the texture name to use for droplets e.g.
  136. "mobs_blood.png", or table {"blood1.png", "blood2.png"}
  137. 'pathfinding' set to 1 for mobs to use pathfinder feature to locate
  138. player, set to 2 so they can build/break also (only
  139. works with dogfight attack and when 'mobs_griefing'
  140. in minetest.conf is not false). Adding {unbreakable=1}
  141. to node groups stops them being broken by mobs.
  142. 'immune_to' is a table that holds specific damage when being hit by
  143. certain items e.g.
  144. {"default:sword_wood", 0} -- causes no damage.
  145. {"default:gold_lump", -10} -- heals by 10 health points.
  146. {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks.
  147. {"all"} -- stops all weapons causing damage apart from those on list.
  148. 'makes_footstep_sound' when true you can hear mobs walking.
  149. 'sounds' this is a table with sounds of the mob
  150. 'distance' maximum distance sounds can be heard, default is 10.
  151. 'random' random sound that plays during gameplay.
  152. 'war_cry' what you hear when mob starts to attack player.
  153. 'attack' what you hear when being attacked.
  154. 'shoot_attack' sound played when mob shoots.
  155. 'damage' sound heard when mob is hurt.
  156. 'death' played when mob is killed.
  157. 'jump' played when mob jumps.
  158. 'fuse' sound played when mob explode timer starts.
  159. 'explode' sound played when mob explodes.
  160. 'drops' table of items that are dropped when mob is killed, fields are:
  161. 'name' name of item to drop.
  162. 'chance' chance of drop, 1 for always, 2 for 1-in-2 chance etc.
  163. 'min' minimum number of items dropped, set to 0 for rare drops.
  164. 'max' maximum number of items dropped.
  165. Note: If weapon has {fire=1} damage group set then cooked items will drop.
  166. Note2: A function can now be passed which can also return drops table, e.g.
  167. drops = function(pos)
  168. -- do something
  169. return { {name = "farming:bread"}, {name = "default:dirt", chance = 2} }
  170. end
  171. 'visual' holds the look of the mob you wish to create:
  172. 'cube' looks like a normal node
  173. 'sprite' sprite which looks same from all angles.
  174. 'upright_sprite' flat model standing upright.
  175. 'wielditem' how it looks when player holds it in hand.
  176. 'mesh' uses separate object file to define mob.
  177. 'visual_size' has the size of the mob, defaults to {x = 1, y = 1}
  178. 'collisionbox' has the box in which mob can be interacted with the
  179. world e.g. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
  180. 'selectionbox' has the box in which player can interact with mob
  181. 'textures' holds a table list of textures to be used for mob, or you
  182. could use multiple lists inside another table for random
  183. selection e.g. { {"texture1.png"}, {"texture2.png"} }
  184. 'child_texture' holds the texture table for when baby mobs are used.
  185. 'gotten_texture' holds the texture table for when self.gotten value is
  186. true, used for milking cows or shearing sheep.
  187. 'texture_mods' holds a string which overlays a texture on top of the
  188. mob texture e.g. "^saddle.png"
  189. 'mesh' holds the name of the external object used for mob model
  190. e.g. "mobs_cow.b3d"
  191. 'gotten_mesh" holds the name of the external object used for when
  192. self.gotten is true for mobs.
  193. 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back,
  194. 270 = other side.
  195. 'glow' has mob glow without light source, 0 to 15 or nil to disable
  196. 'double_melee_attack' when true has the api choose between 'punch' and
  197. 'punch2' animations. [DEPRECATED]
  198. 'animation' holds a table containing animation names and settings for use with
  199. mesh models:
  200. 'stand_start' start frame for when mob stands still.
  201. 'stand_end' end frame of stand animation.
  202. 'stand_speed' speed of animation in frames per second.
  203. 'walk_start' when mob is walking around.
  204. 'walk_end'
  205. 'walk_speed'
  206. 'run_start' when a mob runs or attacks.
  207. 'run_end'
  208. 'run_speed'
  209. 'fly_start' when a mob is flying.
  210. 'fly_end'
  211. 'fly_speed'
  212. 'jump_start' when a mob is jumping
  213. 'jump_end'
  214. 'jump_speed'
  215. 'punch_start' when a mob melee attacks.
  216. 'punch_end'
  217. 'punch_speed'
  218. 'punch2_start' alternative melee attack animation.
  219. 'punch2_end'
  220. 'punch2_speed'
  221. 'shoot_start' shooting animation.
  222. 'shoot_end'
  223. 'shoot_speed'
  224. 'die_start' death animation
  225. 'die_end'
  226. 'die_speed'
  227. 'die_loop' when set to false stops the animation looping.
  228. 'die_rotate' if true mob spins during death animation.
  229. Using '_loop = false' setting will stop any of the above animations from
  230. looping.
  231. 'speed_normal' is used for animation speed for compatibility with some
  232. older mobs.
  233. Note: Up to 5 different animations can be used per action e.g.
  234. stand_start, stand_end, stand1_start, stand1_end .. up to stand4_start
  235. Node Replacement
  236. ----------------
  237. Mobs can look around for specific nodes as they walk and replace them to mimic
  238. eating.
  239. 'replace_what' group of items to replace e.g.
  240. {"farming:wheat_8", "farming:carrot_8"}
  241. or you can use the specific options of what, with and
  242. y offset by using this instead:
  243. {
  244. {"group:grass", "air", 0},
  245. {"default:dirt_with_grass", "default:dirt", -1}
  246. }
  247. 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg"
  248. 'replace_rate' how random should the replace rate be (typically 10)
  249. 'replace_offset' +/- value to check specific node to replace
  250. 'on_replace(self, pos, oldnode, newnode)' is called when mob is about to
  251. replace a node.
  252. 'self' ObjectRef of mob
  253. 'pos' Position of node to replace
  254. 'oldnode' Current node
  255. 'newnode' What the node will become after replacing
  256. If false is returned, the mob will not replace the node.
  257. By default, replacing sets self.gotten to true and resets the object
  258. properties. (DEPRECATED, use on_replace to make changes).
  259. Custom Definition Functions
  260. ---------------------------
  261. Along with the above mob registry settings we can also use custom functions to
  262. enhance mob functionality and have them do many interesting things:
  263. 'on_die' a function that is called when the mob is killed the
  264. parameters are (self, pos)
  265. 'on_rightclick' its same as in minetest.register_entity()
  266. 'on_blast' is called when an explosion happens near mob when using TNT
  267. functions, parameters are (object, damage) and returns
  268. (do_damage, do_knockback, drops)
  269. 'on_spawn' is a custom function that runs on mob spawn with 'self' as
  270. variable, return true at end of function to run only once.
  271. 'after_activate' is a custom function that runs once mob has been activated
  272. with these paramaters (self, staticdata, def, dtime)
  273. 'on_breed' called when two similar mobs breed, paramaters are
  274. (parent1, parent2) objects, return false to stop child from
  275. being resized and owner/tamed flags and child textures being
  276. applied. Function itself must spawn new child mob.
  277. 'on_grown' is called when a child mob has grown up, only paramater is
  278. (self).
  279. 'do_punch' called when mob is punched with paramaters (self, hitter,
  280. time_from_last_punch, tool_capabilities, direction), return
  281. false to stop punch damage and knockback from taking place.
  282. 'custom_attack' when set this function is called instead of the normal mob
  283. melee attack, parameters are (self, to_attack) and if true
  284. is returned normal attack function continued.
  285. 'on_die' a function that is called when mob is killed (self, pos), also
  286. has access to self.cause_of_death table.
  287. 'on_flop' function called when flying or swimmimng mob is no longer in
  288. air/water, (self) paramater and return true to skip the built
  289. in api flop feature.
  290. 'do_custom' a custom function that is called every tick while mob is
  291. active and which has access to all of the self.* variables
  292. e.g. (self.health for health or self.standing_in for node
  293. status), return with 'false' to skip remainder of mob API.
  294. Internal Variables
  295. ------------------
  296. The mob api also has some preset variables and functions that it will remember
  297. for each mob.
  298. 'self.health' contains current health of mob (cannot exceed
  299. self.hp_max)
  300. 'self.texture_list' contains list of all mob textures
  301. 'self.child_texture' contains mob child texture when growing up
  302. 'self.base_texture' contains current skin texture which was randomly
  303. selected from textures list
  304. 'self.gotten' this is used for obtaining milk from cow and wool from
  305. sheep
  306. 'self.horny' when animal fed enough it is set to true and animal can
  307. breed with same animal
  308. 'self.hornytimer' background timer that controls breeding functions and
  309. mob childhood timings
  310. 'self.child' used for when breeding animals have child, will use
  311. child_texture and be half size
  312. 'self.owner' string used to set owner of npc mobs, typically used for
  313. dogs
  314. 'self.order' set to "follow" or "stand" so that npc will follow owner
  315. or stand it's ground
  316. 'self.nametag' contains the name of the mob which it can show above
  317. 'self.state' Current mob state.
  318. "stand": no movement (except turning around)
  319. "walk": walk or move around aimlessly
  320. "attack": chase and attack enemy
  321. "runaway": flee from target
  322. "flop": bounce around aimlessly
  323. (for swimming mobs that have stranded)
  324. "die": during death
  325. Adding Mobs in World
  326. --------------------
  327. mobs:add_mob(pos, {
  328. name = "mobs_animal:chicken",
  329. child = true,
  330. owner = "singleplayer",
  331. nametag = "Bessy",
  332. ignore_count = true -- ignores mob count per map area
  333. })
  334. Returns false if mob could not be added, returns mob object if spawned ok.
  335. Removing Mob from World
  336. -----------------------
  337. mobs:remove(self, decrease)
  338. Removes mob 'self' from the world and if 'decrease' is true then the mob counter
  339. will also be decreased by one.
  340. Spawning Mobs in World
  341. ----------------------
  342. mobs:spawn({
  343. name = "mobs_monster:tree_monster",
  344. nodes = {"group:leaves"},
  345. max_light = 7,
  346. })
  347. Spawn functions require the following settings, some of which already have a
  348. default setting and can be omitted:
  349. 'name' is the name of the animal/monster
  350. 'nodes' is a list of nodenames on that the animal/monster can
  351. spawn on top of (defaults to {"group:dirt", "group:stone"}
  352. 'neighbors' is a list of nodenames on that the animal/monster will
  353. spawn beside (default is {"air"})
  354. 'interval' is same as in register_abm() (default is 30)
  355. 'chance' is same as in register_abm() (default is 5000)
  356. 'min_light' is the minimum light level (default is 0)
  357. 'max_light' is the maximum light (default is 15)
  358. 'min_height' is the minimum height a mob can spawn (default: -31000)
  359. 'max_height' is the maximum height a mob can spawn (default is 31000)
  360. 'active_object_count' number of this type of mob to spawn at one time inside
  361. map area (default is 1)
  362. 'day_toggle' true for day spawning, false for night or nil for
  363. anytime
  364. 'on_spawn' is a custom function which runs after mob has spawned
  365. and gives self and pos values.
  366. 'on_map_load' when true mobs will have a chance of spawning only
  367. when new areas of map are loaded, interval will not be
  368. used.
  369. The older spawn functions are still active and working but have no defaults like
  370. the mobs:spawn, so it is recommended to use the above instead.
  371. mobs:register_spawn(name, nodes, max_light, min_light, chance,
  372. active_object_count, max_height, day_toggle)
  373. mobs:spawn_specific(name, nodes, neighbors, min_light, max_light, interval,
  374. chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
  375. A simpler way to handle mob spawns has been added with the mobs:spawn(def)
  376. command which uses above names to make settings clearer:
  377. For each mob that spawns with this function is a field in mobs.spawning_mobs.
  378. It tells if the mob should spawn or not. Default is true. So other mods can
  379. only use the API of this mod by disabling the spawning of the default mobs in
  380. this mod.
  381. mobs:spawn_abm_check(pos, node, name)
  382. This global function can be changed to contain additional checks for mobs to
  383. spawn e.g. mobs that spawn only in specific areas and the like. By returning
  384. true the mob will not spawn.
  385. 'pos' holds the position of the spawning mob
  386. 'node' contains the node the mob is spawning on top of
  387. 'name' is the name of the animal/monster
  388. Particle Effects
  389. ----------------
  390. mobs:effect(pos, amount, texture, min_size, max_size, radius, gravity, glow, fall)
  391. This function provides a quick way to spawn particles as an effect.
  392. 'pos' center position of particle effect.
  393. 'amount' how many particles.
  394. 'texture' texture filename to use for effect.
  395. 'min_size' smallest particle size.
  396. 'max_size' largest particle size.
  397. 'radius' how far particles spread outward from center.
  398. 'gravity' gravity applied to particles once they spawn.
  399. 'glow' number between 1 and 15 for glowing particles.
  400. 'fall' when true particles fall, false has them rising, nil has them scatter.
  401. Making Arrows
  402. -------------
  403. mobs:register_arrow(name, definition)
  404. This function registers a arrow for mobs with the attack type shoot.
  405. 'name' is the name of the arrow
  406. 'definition' is a table with the following values:
  407. 'visual' same is in minetest.register_entity()
  408. 'visual_size' same is in minetest.register_entity()
  409. 'textures' same is in minetest.register_entity()
  410. 'physical' same is in minetest.register_entity() [default: false]
  411. 'collide_with_objects' same as above
  412. 'velocity' the velocity of the arrow
  413. 'drop' if set to true any arrows hitting a node will drop as item
  414. 'hit_player' a function that is called when the arrow hits a player;
  415. this function should hurt the player, the parameters are
  416. (self, player)
  417. 'hit_mob' a function that is called when the arrow hits a mob;
  418. this function should hurt the mob, the parameters are
  419. (self, player)
  420. 'hit_object' a function that is called when the arrow hits an object;
  421. this function parameters are (self, player)
  422. 'hit_node' a function that is called when the arrow hits a node, the
  423. parameters are (self, pos, node)
  424. 'tail' when set to 1 adds a trail or tail to mob arrows
  425. 'tail_texture' texture string used for above effect
  426. 'tail_size' has size for above texture (defaults to between 5 and 10)
  427. 'expire' contains float value for how long tail appears for
  428. (defaults to 0.25)
  429. 'glow' has value for how brightly tail glows 1 to 10 (default is
  430. 0 for no glow)
  431. 'rotate' integer value in degrees to rotate arrow
  432. 'on_step' is a custom function when arrow is active, nil for
  433. default.
  434. 'on_punch' is a custom function when arrow is punched, nil by default
  435. 'collisionbox' is hitbox table for arrow, {-.1,-.1,-.1,.1,.1,.1} by default.
  436. 'lifetime' contains float value for how many seconds arrow exists in
  437. world before being removed (default is 4.5 seconds).
  438. Spawn Eggs
  439. ----------
  440. mobs:register_egg(name, description, background, addegg, no_creative)
  441. This function registers a spawn egg which can be used to properly spawn in a mob.
  442. Animals are spawned as tamed unless sneak/shift is held while spawning.
  443. 'name' this is the name of your new mob to spawn e.g. "mob:sheep"
  444. 'description' the name of the new egg you are creating e.g. "Spawn Sheep"
  445. 'background' the texture displayed for the egg in inventory
  446. 'addegg' would you like an egg image in front of your texture (1 = yes,
  447. 0 = no)
  448. 'no_creative' when set to true this stops spawn egg appearing in creative
  449. mode for destructive mobs like Dungeon Masters.
  450. Explosion Function
  451. ------------------
  452. mobs:explosion(pos, radius) -- DEPRECATED!!! use mobs:boom() instead
  453. mobs:boom(self, pos, radius, damage_radius, texture)
  454. 'self' mob entity
  455. 'pos' centre position of explosion
  456. 'radius' radius of explosion (typically set to 3)
  457. 'damage_radius' radius of damage around explosion
  458. 'texture' particle texture during explosion, defaults to "tnt_smoke.png"
  459. This function generates an explosion which removes nodes in a specific radius
  460. and damages any entity caught inside the blast radius. Protection will limit
  461. node destruction but not entity damage.
  462. Capturing Mobs
  463. --------------
  464. mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
  465. force_take, replacewith)
  466. This function is generally called inside the on_rightclick section of the mob
  467. api code, it provides a chance of capturing the mob by hand, using the net or
  468. lasso items, and can also have the player take the mob by force if tamed and
  469. replace with another item entirely.
  470. 'self' mob information
  471. 'clicker' player information
  472. 'chance_hand' chance of capturing mob by hand (1 to 100) 0 to disable
  473. 'chance_net' chance of capturing mob using net (1 to 100) 0 to disable
  474. 'chance_lasso' chance of capturing mob using magic lasso (1 to 100) 0 to
  475. disable
  476. 'force_take' take mob by force, even if tamed (true or false)
  477. 'replacewith' once captured replace mob with this item instead (overrides
  478. new mob eggs with saved information)
  479. mobs:force_capture(self, clicker)
  480. Same as above but does no checks, it simply captures any and all mobs and places
  481. inside a spawn egg containing all of the mob information.
  482. Feeding and Taming/Breeding
  483. ---------------------------
  484. mobs:feed_tame(self, clicker, feed_count, breed, tame)
  485. This function allows the mob to be fed the item inside self.follow be it apple,
  486. wheat or whatever a set number of times and be tamed or bred as a result.
  487. Will return true when mob is fed with item it likes.
  488. 'self' mob information
  489. 'clicker' player information
  490. 'feed_count' number of times mob must be fed to tame or breed
  491. 'breed' true or false stating if mob can be bred and a child created
  492. afterwards
  493. 'tame' true or false stating if mob can be tamed so player can pick
  494. them up
  495. Protecting Mobs
  496. ---------------
  497. mobs:protect(self, clicker)
  498. This function can be used to right-click any tamed mob with mobs:protector item,
  499. this will protect the mob from harm inside of a protected area from other
  500. players. Will return true when mob right-clicked with mobs:protector item.
  501. 'self' mob information
  502. 'clicker' player information
  503. Riding Mobs
  504. -----------
  505. Mobs can now be ridden by players and the following shows its functions and
  506. usage:
  507. mobs:attach(self, player)
  508. This function attaches a player to the mob so it can be ridden.
  509. 'self' mob information
  510. 'player' player information
  511. mobs:detach(player, offset)
  512. This function will detach the player currently riding a mob to an offset
  513. position.
  514. 'player' player information
  515. 'offset' position table containing offset values
  516. mobs:drive(self, move_animation, stand_animation, can_fly, dtime)
  517. This function allows an attached player to move the mob around and animate it at
  518. same time.
  519. 'self' mob information
  520. 'move_animation' string containing movement animation e.g. "walk"
  521. 'stand_animation' string containing standing animation e.g. "stand"
  522. 'can_fly' if true then jump and sneak controls will allow mob to fly
  523. up and down
  524. 'dtime' tick time used inside drive function
  525. mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
  526. This function allows an attached player to fly the mob around using directional
  527. controls.
  528. 'self' mob information
  529. 'dtime' tick time used inside fly function
  530. 'speed' speed of flight
  531. 'can_shoot' true if mob can fire arrow (sneak and left mouse button
  532. fires)
  533. 'arrow_entity' name of arrow entity used for firing
  534. 'move_animation' string containing name of pre-defined animation e.g. "walk"
  535. or "fly" etc.
  536. 'stand_animation' string containing name of pre-defined animation e.g.
  537. "stand" or "blink" etc.
  538. Note: animation names above are from the pre-defined animation lists inside mob
  539. registry without extensions.
  540. mobs:set_animation(self, name)
  541. This function sets the current animation for mob, defaulting to "stand" if not
  542. found.
  543. 'self' mob information
  544. 'name' name of animation
  545. Certain variables need to be set before using the above functions:
  546. 'self.v2' toggle switch used to define below values for the
  547. first time
  548. 'self.max_speed_forward' max speed mob can move forward
  549. 'self.max_speed_reverse' max speed mob can move backwards
  550. 'self.accel' acceleration speed
  551. 'self.terrain_type' integer containing terrain mob can walk on
  552. (1 = water, 2 or 3 = land)
  553. 'self.driver_attach_at' position offset for attaching player to mob
  554. 'self.driver_eye_offset' position offset for attached player view
  555. 'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1}
  556. mobs:line_of_sight(self, pos1, pos2, stepsize) [DEPRECATED]
  557. This function is for use within the mobs definition for special use cases and
  558. returns true if a mob can see the player or victim.
  559. ...'self' mob information
  560. 'pos1' position of mob
  561. 'pos2' position of vistim or player
  562. 'stepsize' usually set to 1
  563. Use this instead:
  564. mob_class:line_of_sight(pos1, pos2, stepsize)
  565. mobs:can_spawn(pos, name)
  566. This function checks the surrounding area at [pos] to see if there is enough empty
  567. space to spawn mob [name], if so then a new position is returned for use,
  568. otherwise nil is returned.
  569. mobs:is_node_dangerous(mob_object, nodename)
  570. This function returns true if the node name given is harmful to the mob (mob_object),
  571. it is mainly used when a mob is near a node it has to avoid.
  572. External Settings for "minetest.conf"
  573. ------------------------------------
  574. 'enable_damage' if true monsters will attack players (default is true)
  575. 'only_peaceful_mobs' if true only animals will spawn in game (default is
  576. false)
  577. 'mobs_disable_blood' if false blood effects appear when mob is hit (default
  578. is false)
  579. 'mobs_spawn_protected' if set to false then mobs will not spawn in protected
  580. areas (default is true)
  581. 'mobs_spawn_monster_protected' if set to false then monsters will not spawn in
  582. protected areas (default is true)
  583. 'remove_far_mobs' if true then untamed mobs that are outside players
  584. visual range will be removed (default is true)
  585. 'mobname' can change specific mob chance rate (0 to disable) and
  586. spawn number e.g. mobs_animal:cow = 1000,5
  587. 'mob_difficulty' sets difficulty level (health and hit damage
  588. multiplied by this number), defaults to 1.0.
  589. 'mob_show_health' if false then punching mob will not show health status
  590. (true by default)
  591. 'mob_chance_multiplier' multiplies chance of all mobs spawning and can be set
  592. to 0.5 to have mobs spawn more or 2.0 to spawn less.
  593. e.g. 1 in 7000 * 0.5 = 1 in 3500 so better odds of
  594. spawning.
  595. 'mobs_spawn' if false then mobs no longer spawn without spawner or
  596. spawn egg.
  597. 'mobs_drop_items' when false mobs no longer drop items when they die.
  598. 'mobs_griefing' when false mobs cannot break blocks when using either
  599. pathfinding level 2, replace functions or mobs:boom
  600. function.
  601. 'mob_nospawn_range' Minimum range a mob can spawn near player (def: 12)
  602. 'mob_active_limit' Number of active mobs in game, 0 for unlimited
  603. 'mob_area_spawn' When true will check surrounding area the size of the
  604. mob for obstructions before spawning, otherwise it
  605. defaults to checking the height of the mob only.
  606. 'mob_smooth_rotate' Enables smooth rotation when mobs turn by default.
  607. Players can override the spawn chance for each mob registered by adding a line
  608. to their minetest.conf file with a new value, the lower the value the more each
  609. mob will spawn e.g.
  610. mobs_animal:sheep 11000
  611. mobs_monster:sand_monster 100
  612. ...you can also change how many of a certain mob appear in an active mapblock by
  613. adding a comma and then a new value e.g.
  614. mobs_animal:cow = 8000,4 <-- 4 cows per mapblock at 8000 spawn chance
  615. mobs_monster:dirt_monster = ,20 <-- 20 dirt monsters per mapblock
  616. Rideable Horse Example Mob
  617. --------------------------
  618. mobs:register_mob("mob_horse:horse", {
  619. type = "animal",
  620. visual = "mesh",
  621. visual_size = {x = 1.20, y = 1.20},
  622. mesh = "mobs_horse.x",
  623. collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
  624. animation = {
  625. speed_normal = 15,
  626. speed_run = 30,
  627. stand_start = 25,
  628. stand_end = 75,
  629. walk_start = 75,
  630. walk_end = 100,
  631. run_start = 75,
  632. run_end = 100,
  633. },
  634. textures = {
  635. {"mobs_horse.png"},
  636. {"mobs_horsepeg.png"},
  637. {"mobs_horseara.png"}
  638. },
  639. fear_height = 3,
  640. runaway = true,
  641. fly = false,
  642. walk_chance = 60,
  643. view_range = 5,
  644. follow = {"farming:wheat"},
  645. passive = true,
  646. hp_min = 12,
  647. hp_max = 16,
  648. armor = 200,
  649. lava_damage = 5,
  650. fall_damage = 5,
  651. water_damage = 1,
  652. makes_footstep_sound = true,
  653. drops = {
  654. {name = "mobs:meat_raw", chance = 1, min = 2, max = 3}
  655. },
  656. sounds = {
  657. random = "horse_neigh.ogg",
  658. damage = "horse_whinney.ogg",
  659. },
  660. do_custom = function(self, dtime)
  661. -- set needed values if not already present
  662. if not self.v2 then
  663. self.v2 = 0
  664. self.max_speed_forward = 6
  665. self.max_speed_reverse = 2
  666. self.accel = 6
  667. self.terrain_type = 3
  668. self.driver_attach_at = {x = 0, y = 20, z = -2}
  669. self.driver_eye_offset = {x = 0, y = 3, z = 0}
  670. self.driver_scale = {x = 1, y = 1}
  671. end
  672. -- if driver present allow control of horse
  673. if self.driver then
  674. mobs.drive(self, "walk", "stand", false, dtime)
  675. return false -- skip rest of mob functions
  676. end
  677. return true
  678. end,
  679. on_die = function(self, pos)
  680. -- drop saddle when horse is killed while riding
  681. -- also detach from horse properly
  682. if self.driver then
  683. minetest.add_item(pos, "mobs:saddle")
  684. mobs.detach(self.driver, {x = 1, y = 0, z = 1})
  685. end
  686. end,
  687. on_rightclick = function(self, clicker)
  688. -- make sure player is clicking
  689. if not clicker or not clicker:is_player() then
  690. return
  691. end
  692. -- feed, tame or heal horse
  693. if mobs:feed_tame(self, clicker, 10, true, true) then
  694. return
  695. end
  696. -- make sure tamed horse is being clicked by owner only
  697. if self.tamed and self.owner == clicker:get_player_name() then
  698. local inv = clicker:get_inventory()
  699. -- detatch player already riding horse
  700. if self.driver and clicker == self.driver then
  701. mobs.detach(clicker, {x = 1, y = 0, z = 1})
  702. -- add saddle back to inventory
  703. if inv:room_for_item("main", "mobs:saddle") then
  704. inv:add_item("main", "mobs:saddle")
  705. else
  706. minetest.add_item(clicker.get_pos(), "mobs:saddle")
  707. end
  708. -- attach player to horse
  709. elseif not self.driver
  710. and clicker:get_wielded_item():get_name() == "mobs:saddle" then
  711. self.object:set_properties({stepheight = 1.1})
  712. mobs.attach(self, clicker)
  713. -- take saddle from inventory
  714. inv:remove_item("main", "mobs:saddle")
  715. end
  716. end
  717. -- used to capture horse with magic lasso
  718. mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
  719. end
  720. })