5 Welcome to the world of mobs in minetest and hopefully an easy guide to defining
6 your own mobs and having them appear in your worlds.
12 To register a mob and have it ready for use requires the following function:
14 mobs:register_mob(name, definition)
16 The 'name' of a mob usually starts with the mod name it's running from followed
19 "mobs_monster:sand_monster" or "mymod:totally_awesome_beast"
21 ... and the 'definition' is a table which holds all of the settings and
22 functions needed for the mob to work properly which contains the following:
24 'nametag' contains the name which is shown above mob.
25 'type' holds the type of mob that inhabits your world e.g.
26 "animal" usually docile and walking around.
27 "monster" attacks player or npc on sight.
28 "npc" walk around and will defend themselves if hit first, they
30 'hp_min' has the minimum health value the mob can spawn with.
31 'hp_max' has the maximum health value the mob can spawn with.
32 'armor' holds strength of mob, 100 is normal, lower is more powerful
33 and needs more hits and better weapons to kill.
34 'passive' when true allows animals to defend themselves when hit,
35 otherwise they amble onwards.
36 'walk_velocity' is the speed that your mob can walk around.
37 'run_velocity' is the speed your mob can run with, usually when attacking.
38 'walk_chance' has a 0-100 chance value your mob will walk from standing,
39 set to 0 for jumping mobs only.
40 'jump' when true allows your mob to jump updwards.
41 'jump_height' holds the height your mob can jump, 0 to disable jumping.
42 'step_height' height of a block that your mob can easily walk up onto.
43 'fly' when true allows your mob to fly around instead of walking.
44 'fly_in' holds the node name that the mob flies (or swims) around
45 in e.g. "air" or "default:water_source".
46 'runaway' if true causes animals to turn and run away when hit.
47 'view_range' how many nodes in distance the mob can see a player.
48 'reach' how many nodes in distance a mob can attack a player while
50 'damage' how many health points the mob does to a player or another
51 mob when melee attacking.
52 'knockback' when true has mobs falling backwards when hit, the greater
53 the damage the more they move back.
54 'fear_height' is how high a cliff or edge has to be before the mob stops
55 walking, 0 to turn off height fear.
56 'fall_speed' has the maximum speed the mob can fall at, default is -10.
57 'fall_damage' when true causes falling to inflict damage.
58 'water_damage' holds the damage per second infliced to mobs when standing in
60 'lava_damage' holds the damage per second inflicted to mobs when standing
62 'light_damage' holds the damage per second inflicted to mobs when it's too
63 bright (above 13 light).
64 'suffocation' when true causes mobs to suffocate inside solid blocks.
65 'floats' when set to 1 mob will float in water, 0 has them sink.
66 'follow' mobs follow player when holding any of the items which appear
67 on this table, the same items can be fed to a mob to tame or
68 breed e.g. {"farming:wheat", "default:apple"}
70 'reach' is how far the mob can attack player when standing
71 nearby, default is 3 nodes.
72 'docile_by_day' when true has mobs wandering around during daylight
73 hours and only attacking player at night or when
75 'attacks_monsters' when true has npc's attacking monsters or not.
76 'attack_animal' when true will have monsters attacking animals.
77 'owner_loyal' when true will have tamed mobs attack anything player
79 'group_attack' when true has same mob type grouping together to attack
81 'attack_type' tells the api what a mob does when attacking the player
83 'dogfight' is a melee attack when player is within mob reach.
84 'shoot' has mob shoot pre-defined arrows at player when inside
86 'dogshoot' has melee attack when inside reach and shoot attack
87 when inside view_range.
88 'explode' causes mob to explode when inside reach.
89 'explosion_radius' has the radius of the explosion which defaults to 1.
90 'explosion_timer' number of seconds before mob explodes while still
92 'arrow' holds the pre-defined arrow object to shoot when
94 'dogshoot_switch' allows switching between attack types by using timers
95 (1 for shoot, 2 for dogfight)
96 'dogshoot_count_max' contains how many seconds before switching from
98 'dogshoot_count_max2' contains how many seconds before switching from shoot
100 'shoot_interval' has the number of seconds between shots.
101 'shoot_offset' holds the y position added as to where the
102 arrow/fireball appears on mob.
103 'specific_attack' has a table of entity names that mob can also attack
104 e.g. {"player", "mobs_animal:chicken"}.
105 'runaway_from' contains a table with mob names to run away from, add
106 "player" to list to runaway from player also.
107 'blood_amount' contains the number of blood droplets to appear when
109 'blood_texture' has the texture name to use for droplets e.g.
110 "mobs_blood.png", or table {"blood1.png", "blood2.png"}
111 'pathfinding' set to 1 for mobs to use pathfinder feature to locate
112 player, set to 2 so they can build/break also (only
113 works with dogfight attack and when 'mobs_griefing'
114 in minetest.conf is not false).
115 'immune_to' is a table that holds specific damage when being hit by
117 {"default:sword_wood", 0} -- causes no damage.
118 {"default:gold_lump", -10} -- heals by 10 health points.
119 {"default:coal_block", 20} -- 20 damage when hit on head with coal blocks.
121 'makes_footstep_sound' when true you can hear mobs walking.
122 'sounds' this is a table with sounds of the mob
123 'distance' maximum distance sounds can be heard, default is 10.
124 'random' random sound that plays during gameplay.
125 'war_cry' what you hear when mob starts to attack player.
126 'attack' what you hear when being attacked.
127 'shoot_attack' sound played when mob shoots.
128 'damage' sound heard when mob is hurt.
129 'death' played when mob is killed.
130 'jump' played when mob jumps.
131 'explode' sound played when mob explodes.
133 'drops' table of items that are dropped when mob is killed, fields are:
134 'name' name of item to drop.
135 'chance' chance of drop, 1 for always, 2 for 1-in-2 chance etc.
136 'min' minimum number of items dropped.
137 'max' maximum number of items dropped.
139 'visual' holds the look of the mob you wish to create:
140 'cube' looks like a normal node
141 'sprite' sprite which looks same from all angles.
142 'upright_sprite' flat model standing upright.
143 'wielditem' how it looks when player holds it in hand.
144 'mesh' uses separate object file to define mob.
145 'visual_size' has the size of the mob, defaults to {x = 1, y = 1}
146 'collision_box' has the box in which mob can be interacted with the
147 world e.g. {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
148 'selection_box' has the box in which player can interact with mob
149 'textures' holds a table list of textures to be used for mob, or you
150 could use multiple lists inside another table for random
151 selection e.g. { {"texture1.png"}, {"texture2.png"} }
152 'child_texture' holds the texture table for when baby mobs are used.
153 'gotten_texture' holds the texture table for when self.gotten value is
154 true, used for milking cows or shearing sheep.
155 'mesh' holds the name of the external object used for mob model
157 'gotten_mesh" holds the name of the external object used for when
158 self.gotten is true for mobs.
159 'rotate' custom model rotation, 0 = front, 90 = side, 180 = back,
161 'double_melee_attack' when true has the api choose between 'punch' and
164 'animation' holds a table containing animation names and settings for use with mesh models:
165 'stand_start' start frame for when mob stands still.
166 'stand_end' end frame of stand animation.
167 'stand_speed' speed of animation in frames per second.
168 'walk_start' when mob is walking around.
171 'run_start' when a mob runs or attacks.
174 'fly_start' when a mob is flying.
177 'punch_start' when a mob melee attacks.
180 'punch2_start' alternative melee attack animation.
183 'shoot_start' shooting animation.
186 'die_start' death animation
189 'die_loop' when set to false stops the animation looping.
191 Using '_loop = false' setting will stop any of the above animations from
194 'speed_normal' is used for animation speed for compatibility with some
201 Mobs can look around for specific nodes as they walk and replace them to mimic
204 'replace_what' group of items to replace e.g.
205 {"farming:wheat_8", "farming:carrot_8"}
206 or you can use the specific options of what, with and
207 y offset by using this instead:
209 {"group:grass", "air", 0},
210 {"default:dirt_with_grass", "default:dirt", -1}
212 'replace_with' replace with what e.g. "air" or in chickens case "mobs:egg"
213 'replace_rate' how random should the replace rate be (typically 10)
214 'replace_offset' +/- value to check specific node to replace
216 'on_replace(self, pos, oldnode, newnode)' is called when mob is about to
218 'self' ObjectRef of mob
219 'pos' Position of node to replace
220 'oldnode' Current node
221 'newnode' What the node will become after replacing
223 If false is returned, the mob will not replace the node.
225 By default, replacing sets self.gotten to true and resets the object
229 Custom Definition Functions
230 ---------------------------
232 Along with the above mob registry settings we can also use custom functions to
233 enhance mob functionality and have them do many interesting things:
235 'on_die' a function that is called when the mob is killed the
236 parameters are (self, pos)
237 'on_rightclick' its same as in minetest.register_entity()
238 'on_blast' is called when an explosion happens near mob when using TNT
239 functions, parameters are (object, damage) and returns
240 (do_damage, do_knockback, drops)
241 'on_spawn' is a custom function that runs on mob spawn with 'self' as
242 variable, return true at end of function to run only once.
243 'after_activate' is a custom function that runs once mob has been activated
244 with these paramaters (self, staticdata, def, dtime)
245 'on_breed' called when two similar mobs breed, paramaters are
246 (parent1, parent2) objects, return false to stop child from
247 being resized and owner/tamed flags and child textures being
248 applied. Function itself must spawn new child mob.
249 'on_grown' is called when a child mob has grown up, only paramater is
251 'do_punch' called when mob is punched with paramaters (self, hitter,
252 time_from_last_punch, tool_capabilities, direction), return
253 false to stop punch damage and knockback from taking place.
254 'custom_attack' when set this function is called instead of the normal mob
255 melee attack, parameters are (self, to_attack).
256 'on_die' a function that is called when mob is killed (self, pos)
257 'do_custom' a custom function that is called every tick while mob is
258 active and which has access to all of the self.* variables
259 e.g. (self.health for health or self.standing_in for node
260 status), return with 'false' to skip remainder of mob API.
266 The mob api also has some preset variables and functions that it will remember
269 'self.health' contains current health of mob (cannot exceed
271 'self.texture_list' contains list of all mob textures
272 'self.child_texture' contains mob child texture when growing up
273 'self.base_texture' contains current skin texture which was randomly
274 selected from textures list
275 'self.gotten' this is used for obtaining milk from cow and wool from
277 'self.horny' when animal fed enough it is set to true and animal can
278 breed with same animal
279 'self.hornytimer' background timer that controls breeding functions and
280 mob childhood timings
281 'self.child' used for when breeding animals have child, will use
282 child_texture and be half size
283 'self.owner' string used to set owner of npc mobs, typically used for
285 'self.order' set to "follow" or "stand" so that npc will follow owner
287 'self.nametag' contains the name of the mob which it can show above
290 Spawning Mobs in World
291 ----------------------
293 mobs:register_spawn(name, nodes, max_light, min_light, chance,
294 active_object_count, max_height, day_toggle)
296 mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval,
297 chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
299 These functions register a spawn algorithm for the mob. Without this function
300 the call the mobs won't spawn.
302 'name' is the name of the animal/monster
303 'nodes' is a list of nodenames on that the animal/monster can
305 'neighbors' is a list of nodenames on that the animal/monster will
306 spawn beside (default is {"air"} for
308 'max_light' is the maximum of light
309 'min_light' is the minimum of light
310 'interval' is same as in register_abm() (default is 30 for
312 'chance' is same as in register_abm()
313 'active_object_count' number of this type of mob to spawn at one time inside
315 'min_height' is the minimum height the mob can spawn
316 'max_height' is the maximum height the mob can spawn
317 'day_toggle' true for day spawning, false for night or nil for
319 'on_spawn' is a custom function which runs after mob has spawned
320 and gives self and pos values.
322 A simpler way to handle mob spawns has been added with the mobs:spawn(def)
323 command which uses above names to make settings clearer:
325 mobs:spawn({name = "mobs_monster:tree_monster",
326 nodes = {"group:leaves"},
331 For each mob that spawns with this function is a field in mobs.spawning_mobs.
332 It tells if the mob should spawn or not. Default is true. So other mods can
333 only use the API of this mod by disabling the spawning of the default mobs in
340 mobs:register_arrow(name, definition)
342 This function registers a arrow for mobs with the attack type shoot.
344 'name' is the name of the arrow
345 'definition' is a table with the following values:
346 'visual' same is in minetest.register_entity()
347 'visual_size' same is in minetest.register_entity()
348 'textures' same is in minetest.register_entity()
349 'velocity' the velocity of the arrow
350 'drop' if set to true any arrows hitting a node will drop as item
351 'hit_player' a function that is called when the arrow hits a player;
352 this function should hurt the player, the parameters are
354 'hit_mob' a function that is called when the arrow hits a mob;
355 this function should hurt the mob, the parameters are
357 'hit_node' a function that is called when the arrow hits a node, the
358 parameters are (self, pos, node)
359 'tail' when set to 1 adds a trail or tail to mob arrows
360 'tail_texture' texture string used for above effect
361 'tail_size' has size for above texture (defaults to between 5 and 10)
362 'expire' contains float value for how long tail appears for
364 'glow' has value for how brightly tail glows 1 to 10 (default is
366 'rotate' integer value in degrees to rotate arrow
367 'on_step' is a custom function when arrow is active, nil for
374 mobs:register_egg(name, description, background, addegg, no_creative)
376 This function registers a spawn egg which can be used by admin to properly spawn in a mob.
378 'name' this is the name of your new mob to spawn e.g. "mob:sheep"
379 'description' the name of the new egg you are creating e.g. "Spawn Sheep"
380 'background' the texture displayed for the egg in inventory
381 'addegg' would you like an egg image in front of your texture (1 = yes,
383 'no_creative' when set to true this stops spawn egg appearing in creative
384 mode for destructive mobs like Dungeon Masters.
390 mobs:explosion(pos, radius) -- DEPRECATED!!! use mobs:boom() instead
392 mobs:boom(self, pos, radius)
394 'pos' centre position of explosion
395 'radius' radius of explosion (typically set to 3)
397 This function generates an explosion which removes nodes in a specific radius
398 and damages any entity caught inside the blast radius. Protection will limit
399 node destruction but not entity damage.
405 mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso,
406 force_take, replacewith)
408 This function is generally called inside the on_rightclick section of the mob
409 api code, it provides a chance of capturing the mob by hand, using the net or
410 lasso items, and can also have the player take the mob by force if tamed and
411 replace with another item entirely.
413 'self' mob information
414 'clicker' player information
415 'chance_hand' chance of capturing mob by hand (1 to 100) 0 to disable
416 'chance_net' chance of capturing mob using net (1 to 100) 0 to disable
417 'chance_lasso' chance of capturing mob using magic lasso (1 to 100) 0 to
419 'force_take' take mob by force, even if tamed (true or false)
420 'replacewith' once captured replace mob with this item instead (overrides
421 new mob eggs with saved information)
424 Feeding and Taming/Breeding
425 ---------------------------
427 mobs:feed_tame(self, clicker, feed_count, breed, tame)
429 This function allows the mob to be fed the item inside self.follow be it apple,
430 wheat or whatever a set number of times and be tamed or bred as a result.
431 Will return true when mob is fed with item it likes.
433 'self' mob information
434 'clicker' player information
435 'feed_count' number of times mob must be fed to tame or breed
436 'breed' true or false stating if mob can be bred and a child created
438 'tame' true or false stating if mob can be tamed so player can pick
445 mobs:protect(self, clicker)
447 This function can be used to right-click any tamed mob with mobs:protector item,
448 this will protect the mob from harm inside of a protected area from other
449 players. Will return true when mob right-clicked with mobs:protector item.
451 'self' mob information
452 'clicker' player information
458 Mobs can now be ridden by players and the following shows its functions and
462 mobs:attach(self, player)
464 This function attaches a player to the mob so it can be ridden.
466 'self' mob information
467 'player' player information
470 mobs:detach(player, offset)
472 This function will detach the player currently riding a mob to an offset
475 'player' player information
476 'offset' position table containing offset values
479 mobs:drive(self, move_animation, stand_animation, can_fly, dtime)
481 This function allows an attached player to move the mob around and animate it at
484 'self' mob information
485 'move_animation' string containing movement animation e.g. "walk"
486 'stand_animation' string containing standing animation e.g. "stand"
487 'can_fly' if true then jump and sneak controls will allow mob to fly
489 'dtime' tick time used inside drive function
492 mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
494 This function allows an attached player to fly the mob around using directional
497 'self' mob information
498 'dtime' tick time used inside fly function
499 'speed' speed of flight
500 'can_shoot' true if mob can fire arrow (sneak and left mouse button
502 'arrow_entity' name of arrow entity used for firing
503 'move_animation' string containing name of pre-defined animation e.g. "walk"
505 'stand_animation' string containing name of pre-defined animation e.g.
506 "stand" or "blink" etc.
508 Note: animation names above are from the pre-defined animation lists inside mob
509 registry without extensions.
512 mobs:set_animation(self, name)
514 This function sets the current animation for mob, defaulting to "stand" if not
517 'self' mob information
518 'name' name of animation
521 Certain variables need to be set before using the above functions:
523 'self.v2' toggle switch used to define below values for the
525 'self.max_speed_forward' max speed mob can move forward
526 'self.max_speed_reverse' max speed mob can move backwards
527 'self.accel' acceleration speed
528 'self.terrain_type' integer containing terrain mob can walk on
529 (1 = water, 2 or 3 = land)
530 'self.driver_attach_at' position offset for attaching player to mob
531 'self.driver_eye_offset' position offset for attached player view
532 'self.driver_scale' sets driver scale for mobs larger than {x=1, y=1}
535 External Settings for "minetest.conf"
536 ------------------------------------
538 'enable_damage' if true monsters will attack players (default is true)
539 'only_peaceful_mobs' if true only animals will spawn in game (default is
541 'mobs_disable_blood' if false blood effects appear when mob is hit (default
543 'mobs_spawn_protected' if set to false then mobs will not spawn in protected
544 areas (default is true)
545 'remove_far_mobs' if true then mobs that are outside players visual
546 range will be removed (default is false)
547 'mobname' can change specific mob chance rate (0 to disable) and
548 spawn number e.g. mobs_animal:cow = 1000,5
549 'mob_difficulty' sets difficulty level (health and hit damage
550 multiplied by this number), defaults to 1.0.
551 'mob_show_health' if false then punching mob will not show health status
553 'mob_chance_multiplier' multiplies chance of all mobs spawning and can be set
554 to 0.5 to have mobs spawn more or 2.0 to spawn less.
555 e.g. 1 in 7000 * 0.5 = 1 in 3500 so better odds of
557 'mobs_spawn' if false then mobs no longer spawn without spawner or
559 'mobs_drop_items' when false mobs no longer drop items when they die.
560 'mobs_griefing' when false mobs cannot break blocks when using either
561 pathfinding level 2, replace functions or mobs:boom
564 Players can override the spawn chance for each mob registered by adding a line
565 to their minetest.conf file with a new value, the lower the value the more each
568 mobs_animal:sheep_chance 11000
569 mobs_monster:sand_monster_chance 100
572 Rideable Horse Example Mob
573 --------------------------
575 mobs:register_mob("mob_horse:horse", {
578 visual_size = {x = 1.20, y = 1.20},
579 mesh = "mobs_horse.x",
580 collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
593 {"mobs_horsepeg.png"},
594 {"mobs_horseara.png"}
601 follow = {"farming:wheat"},
609 makes_footstep_sound = true,
611 {name = "mobs:meat_raw", chance = 1, min = 2, max = 3}
614 random = "horse_neigh.ogg",
615 damage = "horse_whinney.ogg",
618 do_custom = function(self, dtime)
620 -- set needed values if not already present
623 self.max_speed_forward = 6
624 self.max_speed_reverse = 2
626 self.terrain_type = 3
627 self.driver_attach_at = {x = 0, y = 20, z = -2}
628 self.driver_eye_offset = {x = 0, y = 3, z = 0}
629 self.driver_scale = {x = 1, y = 1}
632 -- if driver present allow control of horse
635 mobs.drive(self, "walk", "stand", false, dtime)
637 return false -- skip rest of mob functions
643 on_die = function(self, pos)
645 -- drop saddle when horse is killed while riding
646 -- also detach from horse properly
648 minetest.add_item(pos, "mobs:saddle")
649 mobs.detach(self.driver, {x = 1, y = 0, z = 1})
654 on_rightclick = function(self, clicker)
656 -- make sure player is clicking
657 if not clicker or not clicker:is_player() then
661 -- feed, tame or heal horse
662 if mobs:feed_tame(self, clicker, 10, true, true) then
666 -- make sure tamed horse is being clicked by owner only
667 if self.tamed and self.owner == clicker:get_player_name() then
669 local inv = clicker:get_inventory()
671 -- detatch player already riding horse
672 if self.driver and clicker == self.driver then
674 mobs.detach(clicker, {x = 1, y = 0, z = 1})
676 -- add saddle back to inventory
677 if inv:room_for_item("main", "mobs:saddle") then
678 inv:add_item("main", "mobs:saddle")
680 minetest.add_item(clicker.getpos(), "mobs:saddle")
683 -- attach player to horse
684 elseif not self.driver
685 and clicker:get_wielded_item():get_name() == "mobs:saddle" then
687 self.object:set_properties({stepheight = 1.1})
688 mobs.attach(self, clicker)
690 -- take saddle from inventory
691 inv:remove_item("main", "mobs:saddle")
695 -- used to capture horse with magic lasso
696 mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)