Update 'mobs_redo' docstrings

This commit is contained in:
Jordan Irwin 2017-08-11 11:32:29 -07:00
parent 2af72ff7e3
commit addf482665

355
api.lua
View File

@ -26,79 +26,94 @@ function umobs.mobsRegisterMob(name, def)
end end
--- --- Registers spawning behavior of mob for *mobs_redo* engine.
-- --
-- @function umobs.mobsRegisterSpawn -- @function umobs.mobsRegisterSpawn
-- @param name -- @tparam string name
-- @param nodes -- @tparam table nodes
-- @param max_light -- @tparam int max_light
-- @param min_light -- @tparam int min_light
-- @param chance -- @tparam int chance
-- @param active_object_count -- @tparam int active_object_count
-- @param max_height -- @tparam int max_height
-- @param day_toggle -- @tparam bool day_toggle
-- @see umobs.mobsRegisterSpawnSpecific
function umobs.mobsRegisterSpawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle) function umobs.mobsRegisterSpawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
return mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle) return mobs:register_spawn(name, nodes, max_light, min_light, chance, active_object_count, max_height, day_toggle)
end end
--- --- Registers spawning behavior of mob for *mobs_redo* engine.
-- --
-- @function umobs.mobsRegisterSpawnSpecific -- @function umobs.mobsRegisterSpawnSpecific
-- @param name -- @tparam string name Name of the animal/monster.
-- @param nodes -- @tparam table nodes A list of nodes on top of which the mob can spawn.
-- @param neighbors -- @tparam table neighbors A list of nodes of which must be adjacent for the mob to spawn(default: ***{"air"}***).
-- @param min_light -- @tparam int min_light The minimum light value of node for spawn to occur.
-- @param max_light -- @tparam int max_light The maximum light value of node for spawn to occur.
-- @param interval -- @tparam int interval Same as in [minetest.register_abm](http://dev.minetest.net/minetest.register_abm) (default: ***30***).
-- @param chance -- @tparam int chance Same as in [minetest.register_abm](http://dev.minetest.net/minetest.register_abm).
-- @param active_object_count -- @tparam int active_object_count Mob is only spawned if ***active_object_count_wider*** of ABM is <= this.
-- @param min_height -- @tparam int min_height Minimum height at which mob will spawn.
-- @param max_height -- @tparam int max_height Maximum height at which mob will spawn.
-- @param day_toggle -- @tparam bool day_toggle
-- @param on_spawn -- - Value descriptions:
-- - ***true:*** Mob will spawn during daytime.
-- - ***false:*** Mob will spawn during nighttime.
-- - ***nil:*** Mob will spawn anytime.
--
-- @tparam callback on_spawn
-- - Called after mob has spawned.
-- - Usage: ***on_spawn = function(self, pos)
function umobs.mobsRegisterSpawnSpecific(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle, on_spawn) function umobs.mobsRegisterSpawnSpecific(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
return mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle, on_spawn) return mobs:spawn_specfic(name, nodes, neighbors, min_light, max_light, interval, chance, active_object_count, min_height, max_height, day_toggle, on_spawn)
end end
--- --- Registers spawning behavior of mob for *mobs_redo* engine.
-- --
-- @function umobs.mobsSpawn -- @function umobs.mobsSpawn
-- @tparam table def See: [umobs.mobsSpawn.def](#umobs.mobsSpawn.def) -- @tparam table def See: [umobs.mobsRegisterSpawnSpecific](#umobs.mobsRegisterSpawnSpecific), where parameters = table definition fields here.
function umobs.mobsSpawn(def) function umobs.mobsSpawn(def)
return mobs:spawn(def) return mobs:spawn(def)
end end
--- --- Registers an item that mob can use for ranged attack for *mobs_redo* engine.
-- --
-- @function umobs.mobsRegisterArrow -- @function umobs.mobsRegisterArrow
-- @param name -- @tparam string name Name of throwable item.
-- @tparam table def See: [umobs.mobsRegisterArrow.def](#umobs.mobsRegisterArrow.def) -- @tparam table def See: [umobs.mobsRegisterArrow.def](#umobs.mobsRegisterArrow.def)
function umobs.mobsRegisterArrow(name, def) function umobs.mobsRegisterArrow(name, def)
return mobs:register_arrow(name, def) return mobs:register_arrow(name, def)
end end
--- --- Registers a mob spawning egg for *mobs_redo* engine.
--
-- The "egg" is an item that is held in inventory when a mob is captured/tamed.
-- --
-- @function umobs.mobsRegisterEgg -- @function umobs.mobsRegisterEgg
-- @param name -- @tparam string name Name of the mob to be spawned (ex.: "***mob:sheep***").
-- @param description -- @tparam string description name of the egg (ex.: "***Spawn Sheep***").
-- @param background -- @tparam background Texture displayed for egg in inventory.
-- @param addegg -- @tparam int addegg Adds an egg image in front of your texture (1=yes, 0=no).
function umobs.mobsRegisterEgg(name, description, background, addegg) -- @tparam bool no_creative If ***true***, spawn egg is not available in creative mode (useful for destructive mobs like ***Dungeon Master***).
return mobs:register_egg(name, description, background, addegg) function umobs.mobsRegisterEgg(name, description, background, addegg, no_creative)
return mobs:register_egg(name, description, background, addegg, no_creative)
end end
--- --- Generates a self-destruct explosion from mob.
--
-- Explosion removes nodes in a specific radius and damages any
-- entity caught inside the blast radius. Protection will limit
-- node destruction but not entity damage.
-- --
-- @function umobs.mobsBoom -- @function umobs.mobsBoom
-- @param self -- @param self The mob entity.
-- @param pos -- @tparam (pos) pos Position of explosion centre.
-- @param radius -- @tparam int radius Radius of explosion reach (typically set to ***3***).
function umobs.mobsBoom(self, pos, radius) function umobs.mobsBoom(self, pos, radius)
return mobs:boom(self, pos, radius) return mobs:boom(self, pos, radius)
end end
@ -116,97 +131,137 @@ function umobs.mobsExplosion(pos, radius)
end end
--- --- Attempts to capture a mob and place in inventory.
--
-- This function is generally called inside the ***on_rightclick***
-- section of the mob api code. It provides a chance of capturing
-- the mob by hand, using the net, or magic lasso items. It can
-- also have the player take the mob by force if tamed and replace
-- it with another item entirely.
-- --
-- @function umobs.mobsCaptureMob -- @function umobs.mobsCaptureMob
-- @param self -- @param self Mob information.
-- @param clicker -- @param clicker Player information.
-- @param chance_hand -- @tparam int chance_hand
-- @param chance_net -- - Chance of capturing mob by hand.
-- @param chance_lasso -- - ***0*** to disable.
-- @param force_take -- - Min: ***0***
-- @param replacewith -- - Max: ***100***
--
-- @tparam int chance_net
-- - Chance of capturing mob with net.
-- - ***0*** to disable.
-- - Min: ***0***
-- - Max: ***100***
--
-- @tparam int chance_lasso
-- - Chance of capturing mob with magic lasso.
-- - ***0*** to disable.
-- - Min: ***0***
-- - Max: ***100***
--
-- @tparam bool force_take If ***true***, takes mob by force even if tamed by another player.
-- @tparam string replacewith On capture, place this item in inventory instead of mob (overrides new mob eggs with saved information).
function umobs.mobsCaptureMob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith) function umobs.mobsCaptureMob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
return mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith) return mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
end end
--- --- Allows feeding items to mobs.
--
-- This function allows the mob to be fed the item inside ***self.follow***
-- a set number of times to be tamed or bred as a result. Will return
-- ***true*** when mob is fed with item it likes.
-- --
-- @function umobs.mobsFeedTame -- @function umobs.mobsFeedTame
-- @param self -- @param table self Mob information.
-- @param clicker -- @param clicker Player information.
-- @param feed_count -- @tparam int feed_count Number of times mob must be fed to tame or breed.
-- @param breed -- @tparam bool breed If ***true***, mob can be bred and a child created afterwards.
-- @param tame -- @tparam bool tame If ***true***, mob can be tamed so player can pick them up.
function umobs.mobsFeedTame(self, clicker, feed_count, breed, tame) function umobs.mobsFeedTame(self, clicker, feed_count, breed, tame)
return mobs:feed_tame(self, clicker, feed_count, breed, tame) return mobs:feed_tame(self, clicker, feed_count, breed, tame)
end end
--- --- Protects mobs from being attacked by other players.
--
-- This function can be used to right-click any tamed mob with
-- ***mobs:protector*** item. This will protect the mob from harm
-- inside a protected area from other players. Will return ***true***
-- when mob right-clicked with ***mobs:protector*** item.
-- --
-- @function umobs.mobsProtect -- @function umobs.mobsProtect
-- @param self -- @param self Mob information.
-- @param clicker -- @param clicker Player information.
function umobs.mobsProtect(self, clicker) function umobs.mobsProtect(self, clicker)
return mobs:protect(self, clicker) return mobs:protect(self, clicker)
end end
--- --- Attaches a player to the mob so it can be ridden.
-- --
-- @function umobs.mobsAttach -- @function umobs.mobsAttach
-- @param self -- @param self Mob information.
-- @param player -- @param player Player information.
function umobs.mobsAttach(self, player) function umobs.mobsAttach(self, player)
return mobs:attach(self, player) return mobs:attach(self, player)
end end
--- --- Detaches player from riding mob.
--
-- Detaches the player currently riding a mob to an offset position.
-- --
-- @function umobs.mobsDetach -- @function umobs.mobsDetach
-- @param player -- @param player Player information.
-- @param offset -- @tparam pos offset Position table containing offset values.
function umobs.mobsDetach(player, offset) function umobs.mobsDetach(player, offset)
return mobs:detach(player, offset) return mobs:detach(player, offset)
end end
--- --- Controls mob movement with player.
--
-- Allows an attached player to move the mob around and animate it at same time.
-- --
-- @function umobs.mobsDrive -- @function umobs.mobsDrive
-- @param self -- @param self Mob information.
-- @param move_animation -- @tparam string move_animation Pre-defined movement state animation (e.g. "***walk***").
-- @param stand_animation -- @tparam string stand_animation Pre-defined standing state animation (e.g. "***stand***").
-- @param can_fly -- @tparam bool can_fly If ***true***, jump and sneak controls will allow mob to fly up and down.
-- @param dtime -- @param dtime Tick time used inside function.
function umobs.mobsDrive(self, move_animation, stand_animation, can_fly, dtime) function umobs.mobsDrive(self, move_animation, stand_animation, can_fly, dtime)
return mobs:drive(self, move_animation, stand_animation, can_fly, dtime) return mobs:drive(self, move_animation, stand_animation, can_fly, dtime)
end end
--- --- Controls mob flight with player.
--
-- Allows the attached player to fly the mob around using directional controls.
--
-- **NOTE:** animation names are from the *pre-defined* animation lists inside mob registry without extensions.
-- --
-- @function umobs.mobsFly -- @function umobs.mobsFly
-- @param self -- @param self Mob information.
-- @param dtime -- @param dtime Tick time used inside function.
-- @param speed -- @tparam int speed Speed at which mob moves in flight.
-- @param can_shoot -- @tparam bool can_shoot If ***true***, player can fire arrow with mob (sneak and left mouse button fires).
-- @param arrow_entity -- @tparam string arrow_entity Name of item used for firing ranged attack.
-- @param move_animation -- @tparam string move_animation Pre-defined movement state animation (e.g. "***walk***", "***fly***", etc.).
-- @param stand_animation -- @tparam string stand_animation Pre-defined standing state animation (e.g. "***stand***", "***blink***", etc.).
function umobs.mobsFly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation) function umobs.mobsFly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
return mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation) return mobs:fly(self, dtime, speed, can_shoot, arrow_entity, move_animation, stand_animation)
end end
--- --- Sets current animation for mob.
--
-- Default: "***stand***"
-- --
-- @function umobs.mobsSetAnimation -- @function umobs.mobsSetAnimation
-- @param self -- @param self Mob information.
-- @param name -- @tparam string name Name of animation (e.g. "***stand***", "***walk***", "***fly***", etc.).
function umobs.mobsSetAnimation(self, name) function umobs.mobsSetAnimation(self, name)
return mobs:set_animation(self, name) return mobs:set_animation(self, name)
end end
@ -260,8 +315,8 @@ end
-- - Example: -- - Example:
-- <pre> -- <pre>
-- immune_to = { -- immune_to = {
-- {"default:sword_wood", 0}, -- immune to sword -- {"default:sword_wood", 0}, \-- immune to sword
-- {"default:gold_lump", -10}, -- gold lump heals -- {"default:gold_lump", -10}, \-- gold lump heals
-- } -- }
-- </pre> -- </pre>
-- --
@ -408,13 +463,6 @@ end
-- - ***die_start, die_end, die_speed:*** When mob dies. -- - ***die_start, die_end, die_speed:*** When mob dies.
--- Definition table for [umobs.mobsSpawn](#umobs.mobsSpawn).
--
-- For field values, see [umobs.mobsRegisterSpawnSpecific](umobs.mobsRegisterSpawnSpecific) parameters.
--
-- @table umobs.mobsSpawn.def
--- Definition table for [umobs.mobsRegisterArrow](#umobs.mobsRegisterArrow). --- Definition table for [umobs.mobsRegisterArrow](#umobs.mobsRegisterArrow).
-- --
-- @table umobs.mobsRegisterArrow.def -- @table umobs.mobsRegisterArrow.def
@ -522,3 +570,138 @@ end
-- @setting mob_show_health -- @setting mob_show_health
-- - Type: ***bool*** -- - Type: ***bool***
-- - Default: ***true*** -- - Default: ***true***
--- Mobs Redo Notes.
--
-- @section mobs_redo_notes
--- These variables need to be set before using the mobs functions:
--
-- - `self.v2:` Toggle switch used to define below values for the first time.
-- - `self.max_speed_forward:` Max speed mob can move forward.
-- - `self.max_speed_reverse:` Max speed mob can move backwards.
-- - `self.accel:` Acceleration speed.
-- - `self.terrain_type:` Integer containing terrain mob can walk on:
-- - ***1:*** water
-- - ***2:*** water/land???
-- - ***3:*** land
-- - `self.driver_attach_at:` Position offset for attaching player to mob.
-- - `self.driver_eye_offset:` Position offset for attached player view.
-- - `self.driver_scale:` Sets driver scale for mobs larger than {x=1, y=1}.
--
-- @notes Variables
--- Mobs Redo Examples.
--
-- @section mobs_redo_examples
--- Rideable horse.
--
-- Example of how to register a rideable horse:
-- <pre>
-- mobs:register_mob("mob_horse:horse", {
-- type = "animal",
-- visual = "mesh",
-- visual_size = {x = 1.20, y = 1.20},
-- mesh = "mobs_horse.x",
-- collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.25, 0.4},
-- animation = {
-- speed_normal = 15,
-- speed_run = 30,
-- stand_start = 25,
-- stand_end = 75,
-- walk_start = 75,
-- walk_end = 100,
-- run_start = 75,
-- run_end = 100,
-- },
-- textures = {
-- {"mobs_horse.png"},
-- {"mobs_horsepeg.png"},
-- {"mobs_horseara.png"}
-- },
-- fear_height = 3,
-- runaway = true,
-- fly = false,
-- walk_chance = 60,
-- view_range = 5,
-- follow = {"farming:wheat"},
-- passive = true,
-- hp_min = 12,
-- hp_max = 16,
-- armor = 200,
-- lava_damage = 5,
-- fall_damage = 5,
-- water_damage = 1,
-- makes_footstep_sound = true,
-- drops = {
-- {name = "mobs:meat_raw", chance = 1, min = 2, max = 3}
-- },
-- do_custom = function(self, dtime)
-- \-- set needed values if not already present
-- if not self.v2 then
-- \-- elf.v2 = 0
-- self.max_speed_forward = 6
-- self.max_speed_reverse = 2
-- self.accel = 6
-- self.terrain_type = 3
-- self.driver_attach_at = {x = 0, y = 20, z = -2}
-- self.driver_eye_offset = {x = 0, y = 3, z = 0}
-- self.driver_scale = {x = 1, y = 1}
-- end
-- \-- if driver present allow control of horse
-- if self.driver then
-- mobs.drive(self, "walk", "stand", false, dtime)
-- return false \-- skip rest of mob functions
-- end
-- return true
-- end,
-- on_die = function(self, pos)
-- \-- drop saddle when horse is killed while riding
-- \-- also detach from horse properly
-- if self.driver then
-- minetest.add_item(pos, "mobs:saddle")
-- mobs.detach(self.driver, {x = 1, y = 0, z = 1})
-- end
-- end,
-- on_rightclick = function(self, clicker)
-- \-- make sure player is clicking
-- if not clicker or not clicker:is_player() then
-- return
-- end
-- \-- feed, tame or heal horse
-- if mobs:feed_tame(self, clicker, 10, true, true) then
-- return
-- end
-- \-- make sure tamed horse is being clicked by owner only
-- if self.tamed and self.owner == clicker:get_player_name() then
-- local inv = clicker:get_inventory()
-- \-- detatch player already riding horse
-- if self.driver and clicker == self.driver then
-- mobs.detach(clicker, {x = 1, y = 0, z = 1})
-- \-- add saddle back to inventory
-- if inv:room_for_item("main", "mobs:saddle") then
-- inv:add_item("main", "mobs:saddle")
-- else
-- minetest.add_item(clicker.getpos(), "mobs:saddle")
-- end
-- \-- attach player to horse
-- elseif not self.driver
-- and clicker:get_wielded_item():get_name() == "mobs:saddle" then
-- self.object:set_properties({stepheight = 1.1})
-- mobs.attach(self, clicker)
-- \-- take saddle from inventory
-- inv:remove_item("main", "mobs:saddle")
-- end
-- end
-- \-- used to capture horse with magic lasso
-- mobs:capture_mob(self, clicker, 0, 0, 80, false, nil)
-- end
-- })
-- </pre>
--
-- @examples Horse