api.txt 37 KB

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