1
0
mirror of https://codeberg.org/tenplus1/mobs_redo.git synced 2024-12-23 17:20:22 +01:00

simplified breeding function, added some settings

This commit is contained in:
TenPlus1 2020-12-05 12:06:34 +00:00
parent 4a6518eeba
commit 1dfd7e1af1
3 changed files with 47 additions and 23 deletions

61
api.lua
View File

@ -8,7 +8,7 @@ local use_cmi = minetest.global_exists("cmi")
mobs = {
mod = "redo",
version = "20201130",
version = "20201205",
intllib = S,
invis = minetest.global_exists("invisibility") and invisibility or {}
}
@ -829,6 +829,11 @@ end
-- check if mob is dead or only hurt
function mob_class:check_for_death(cmi_cause)
-- We dead already
if self.state == "die" then
return true
end
-- has health actually changed?
if self.health == self.old_health and self.health > 0 then
return false
@ -906,6 +911,9 @@ function mob_class:check_for_death(cmi_cause)
self.blinktimer = 0
self.passive = true
self.state = "die"
self.object:set_properties({
pointable = false, collide_with_objects = false
})
self:set_velocity(0)
self:set_animation("die")
@ -1296,16 +1304,20 @@ function mob_class:follow_holding(clicker)
return false
end
-- Thanks Wuzzy for the following editable settings
local HORNY_TIME = 30
local HORNY_AGAIN_TIME = 300
local CHILD_GROW_TIME = 60 * 20 -- 20 minutes
-- find two animals of same type and breed if nearby and horny
function mob_class:breed()
-- child takes 240 seconds before growing into adult
-- child takes a long time before growing into adult
if self.child == true then
self.hornytimer = self.hornytimer + 1
if self.hornytimer > 240 then
if self.hornytimer > CHILD_GROW_TIME then
self.child = false
self.hornytimer = 0
@ -1334,14 +1346,14 @@ function mob_class:breed()
return
end
-- horny animal can mate for 40 seconds,
-- afterwards horny animal cannot mate again for 200 seconds
-- horny animal can mate for HORNY_TIME seconds,
-- afterwards horny animal cannot mate again for HORNY_AGAIN_TIME seconds
if self.horny == true
and self.hornytimer < 240 then
and self.hornytimer < HORNY_TIME + HORNY_AGAIN_TIME then
self.hornytimer = self.hornytimer + 1
if self.hornytimer >= 240 then
if self.hornytimer >= HORNY_TIME + HORNY_AGAIN_TIME then
self.hornytimer = 0
self.horny = false
end
@ -1349,7 +1361,7 @@ function mob_class:breed()
-- find another same animal who is also horny and mate if nearby
if self.horny == true
and self.hornytimer <= 40 then
and self.hornytimer <= HORNY_TIME then
local pos = self.object:get_pos()
@ -1357,7 +1369,6 @@ function mob_class:breed()
"heart.png", 3, 4, 1, 0.1)
local objs = minetest.get_objects_inside_radius(pos, 3)
local num = 0
local ent
for n = 1, #objs do
@ -1386,18 +1397,20 @@ function mob_class:breed()
end
end
if ent
-- found another similar horny animal that isn't self?
if ent and ent.object ~= self.object
and canmate == true
and ent.horny == true
and ent.hornytimer <= 40 then
num = num + 1
end
and ent.hornytimer <= HORNY_TIME then
-- found your mate? then have a baby
if num > 1 then
local pos2 = ent.object:get_pos()
self.hornytimer = 41
ent.hornytimer = 41
-- Have mobs face one another
yaw_to_pos(self, pos2)
yaw_to_pos(ent, self.object:get_pos())
self.hornytimer = HORNY_TIME + 1
ent.hornytimer = HORNY_TIME + 1
-- have we reached active mob limit
if active_limit > 0 and active_mobs >= active_limit then
@ -1465,8 +1478,6 @@ function mob_class:breed()
ent2.owner = self.owner
end, self, ent)
num = 0
break
end
end
@ -2011,10 +2022,11 @@ function mob_class:follow_flop()
self.following = nil
end
else
-- stop following player if not holding specific item
-- stop following player if not holding specific item or mob is horny
if self.following
and self.following:is_player()
and self:follow_holding(self.following) == false then
and (self:follow_holding(self.following) == false
or self.horny) then
self.following = nil
end
@ -4572,8 +4584,11 @@ function mobs:feed_tame(self, clicker, feed_count, breed, tame)
-- make children grow quicker
if self.child == true then
self.hornytimer = self.hornytimer + 20
-- self.hornytimer = self.hornytimer + 20
-- deduct 10% of the time to adulthood
self.hornytimer = self.hornytimer + (
(CHILD_GROW_TIME - self.hornytimer) * 0.1)
print ("====", self.hornytimer)
return true
end

View File

@ -329,6 +329,14 @@ for each mob.
'self.order' set to "follow" or "stand" so that npc will follow owner
or stand it's ground
'self.nametag' contains the name of the mob which it can show above
'self.state' Current mob state.
"stand": no movement (except turning around)
"walk": walk or move around aimlessly
"attack": chase and attack enemy
"runaway": flee from target
"flop": bounce around aimlessly
(for swimming mobs that have stranded)
"die": during death
Adding Mobs in World

View File

@ -23,6 +23,7 @@ Lucky Blocks: 9
Changelog:
- 1.54 - Simplified animal breeding function, added editable settings (thanks Wuzzy), Child mobs now take 20 mins to grow up, reverted to simple mob spawning with setting to use area checks.
- 1.53 - Added 'on_map_load' settings to mobs:spawn so that mobs will only spawn when new areas of map are loaded.
- 1.52 - Added 'mob_active_limit' in settings to set number of mobs in game,
(default is 0 for unlimited), removed {immortal} from mob armor, fluid viscocity slows mobs