api.txt 40 KB

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