api.txt 33 KB

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