added on_breed on_grown and do_punch custom functions

This commit is contained in:
TenPlus1 2017-09-15 16:06:35 +01:00
parent 7b0a1cf233
commit 4785c37f18
2 changed files with 58 additions and 16 deletions

56
api.lua
View File

@ -1,9 +1,9 @@
-- Mobs Api (8th September 2017)
-- Mobs Api (15th September 2017)
mobs = {}
mobs.mod = "redo"
mobs.version = "20170908"
mobs.version = "20170915"
-- Intllib
@ -814,12 +814,17 @@ local breed = function(self)
collisionbox = self.base_colbox,
})
-- jump when fully grown so not to fall into ground
self.object:setvelocity({
x = 0,
y = self.jump_height,
z = 0
})
-- custom function when child grows up
if self.on_grown then
self.on_grown(self)
else
-- jump when fully grown so as not to fall into ground
self.object:setvelocity({
x = 0,
y = self.jump_height,
z = 0
})
end
end
return
@ -838,7 +843,7 @@ local breed = function(self)
end
end
-- find another same animal who is also horny and mate if close enough
-- find another same animal who is also horny and mate if nearby
if self.horny == true
and self.hornytimer <= 40 then
@ -892,14 +897,27 @@ local breed = function(self)
-- spawn baby
minetest.after(5, function()
-- custom breed function
if self.on_breed then
-- when false skip going any further
if self.on_breed(self, ent) == false then
return
end
else
effect(pos, 15, "tnt_smoke.png", 1, 2, 2, 15, 5)
end
local mob = minetest.add_entity(pos, self.name)
local ent2 = mob:get_luaentity()
local textures = self.base_texture
-- using specific child texture (if found)
if self.child_texture then
textures = self.child_texture[1]
end
-- and resize to half height
mob:set_properties({
textures = textures,
visual_size = {
@ -915,6 +933,7 @@ local breed = function(self)
self.base_colbox[6] * .5,
},
})
-- that is tamed and owned by parents' owner
ent2.child = true
ent2.tamed = true
ent2.owner = self.owner
@ -2059,6 +2078,15 @@ end
-- deal damage and effects when mob punched
local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- custom punch function
if self.do_punch then
-- when false skip going any further
if self.do_punch(self, hitter, tflp, tool_caps, dir) == false then
return
end
end
-- mob health check
if self.health <= 0 then
return
@ -2157,12 +2185,12 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
local s = random(0, #weapon:get_definition().sounds)
minetest.sound_play(weapon:get_definition().sounds[s], {
object = hitter,
object = self.object, --hitter,
max_hear_distance = 8
})
else
minetest.sound_play("default_punch", {
object = hitter,
object = self.object, --hitter,
max_hear_distance = 5
})
end
@ -2704,8 +2732,14 @@ minetest.register_entity(name, {
on_step = mob_step,
do_punch = def.do_punch,
on_punch = mob_punch,
on_breed = def.on_breed,
on_grown = def.on_grown,
on_activate = function(self, staticdata, dtime)
return mob_activate(self, staticdata, def, dtime)
end,

18
api.txt
View File

@ -1,5 +1,5 @@
MOB API (1st September 2017)
MOB API (15th September 2017)
The mob api is a function that can be called on by other mods to add new animals or monsters into minetest.
@ -75,9 +75,7 @@ This functions registers a new mob as a Minetest entity.
'fall_damage' will mob be hurt when falling from height
'fall_speed' maximum falling velocity of mob (default is -10 and must be below -2)
'fear_height' when mob walks near a drop then anything over this value makes it stop and turn back (default is 0 to disable)
'on_die' a function that is called when the mob is killed the parameters are (self, pos)
'floats' 1 to float in water, 0 to sink
'on_rightclick' its same as in minetest.register_entity()
'pathfinding' set to 1 for mobs to use pathfinder feature to locate player, set to 2 so they can build/break also (only works with dogfight attack)
'attack_type' the attack type of a monster
'dogfight' follows player in range and attacks when in reach
@ -89,13 +87,11 @@ This functions registers a new mob as a Minetest entity.
'dogshoot_count2_max' number of seconds before switching back to shoot mode.
'custom_attack' when set this function is called instead of the normal mob melee attack, parameters are (self, to_attack)
'double_melee_attack' if false then api will choose randomly between 'punch' and 'punch2' attack animations
'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops)
'explosion_radius' radius of explosion attack (defaults to 1)
'arrow' if the attack_type is "shoot" or "dogshoot" then the entity name of a pre-defined arrow is required, see below for arrow definition.
'shoot_interval' the minimum shoot interval
'shoot_offset' +/- value to position arrow/fireball when fired
'reach' how far a reach this mob has, default is 3
'on_spawn' is a custom function that runs on mob spawn with 'self' as variable, return true at end of function to run onyl once.
'sounds' this is a table with sounds of the mob
'random' random sounds during gameplay
'war_cry' sound when starting to attack player
@ -107,6 +103,18 @@ This functions registers a new mob as a Minetest entity.
'explode' sound when exploding
'distance' maximum distance sounds are heard from (default is 10)
Custom mob functions inside mob registry:
'on_die' a function that is called when the mob is killed the parameters are (self, pos)
'on_rightclick' its same as in minetest.register_entity()
'on_blast' is called when an explosion happens near mob when using TNT functions, parameters are (object, damage) and returns (do_damage, do_knockback, drops)
'on_spawn' is a custom function that runs on mob spawn with 'self' as variable, return true at end of function to run only once.
'on_breed' called when two similar mobs breed, paramaters are (parent1, parent2) objects, return false to stop child from being resized and owner/tamed flags and child textures being applied.
'on_grown' is called when a child mob has grown up, only paramater is (self).
'do_punch' called when mob is punched with paramaters (self, hitter, time_from_last_punch, tool_capabilities, direction), return false to stop punch damage and knockback from taking place.
Mobs can look for specific nodes as they walk and replace them to mimic eating.
'replace_what' group if items to replace e.g. {"farming:wheat_8", "farming:carrot_8"}