api_new.txt 28 KB

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