From 43a53e18c1bb1c3abbc4643a668e5e27afe55351 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Tue, 24 Mar 2015 12:12:53 +0000 Subject: [PATCH] Changed recovery time from breeding and growing up times --- README.txt | 1 + api.lua | 127 ++++++++++++++++++++++++++-------------------------- chicken.lua | 3 ++ cow.lua | 3 ++ sheep.lua | 3 ++ 5 files changed, 73 insertions(+), 64 deletions(-) diff --git a/README.txt b/README.txt index 623ef26..39b57ec 100644 --- a/README.txt +++ b/README.txt @@ -29,6 +29,7 @@ This mod contains the following additions: Changelog: beta- Npc mob added, kills monsters, attacks player when punched, right click with food to heal or gold lump for drop +1.06- Changed recovery times after breeding, and time taken to grow up (can be sped up by feeding baby animal) 1.05- Added ExeterDad's bunny's which can be picked up and tamed with 4 carrots from farming redo or farming_plus, also shears added to get wool from sheep and lastly Jordach/BSD's kitten 1.04- Added mating for sheep, cows and hogs... feed animals to make horny and hope for a baby which is half size, will grow up quick though :) 1.03- Added mob drop/replace feature so that chickens can drop eggs, cow/sheep can eat grass/wheat etc. diff --git a/api.lua b/api.lua index 8c7277d..7810d64 100644 --- a/api.lua +++ b/api.lua @@ -1,4 +1,4 @@ - -- Mobs Api (15th March 2015) + -- Mobs Api (24th March 2015) mobs = {} mobs.mod = "redo" @@ -339,76 +339,23 @@ function mobs:register_mob(name, def) end end end - - if self.following and self.following:is_player() and self.following:get_wielded_item():get_name() ~= self.follow then - self.following = nil - self.v_start = false - end - if self.following then - - local s = self.object:getpos() - local p - if self.following.is_player and self.following:is_player() then - p = self.following:getpos() - elseif self.following.object then - p = self.following.object:getpos() - end - - if p then - local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 - if dist > self.view_range then - self.following = nil - self.v_start = false - else - local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} - local yaw = math.atan(vec.z/vec.x)+math.pi/2 - if self.drawtype == "side" then - yaw = yaw+(math.pi/2) - end - if p.x > s.x then - yaw = yaw+math.pi - end - self.object:setyaw(yaw) - if dist > 2 then - if not self.v_start then - self.v_start = true - self.set_velocity(self, self.walk_velocity) - else - if self.jump and self.get_velocity(self) <= 1.5 and self.object:getvelocity().y == 0 then - local v = self.object:getvelocity() - v.y = 6 - self.object:setvelocity(v) - end - self.set_velocity(self, self.walk_velocity) - end - self:set_animation("walk") - else - self.v_start = false - self.set_velocity(self, 0) - self:set_animation("stand") - end - return - end - end - end - - -- horny animal can mate for 40 seconds, afterwards horny animal cannot mate again for 60 seconds - if self.horny == true and self.hornytimer < 100 and self.child == false then + -- horny animal can mate for 40 seconds, afterwards horny animal cannot mate again for 200 seconds + if self.horny == true and self.hornytimer < 240 and self.child == false then self.hornytimer = self.hornytimer + 1 if self.hornytimer <= 40 then effect(self.object:getpos(), 4, "heart.png") end - if self.hornytimer >= 100 then + if self.hornytimer >= 240 then self.hornytimer = 0 self.horny = false end end - -- if animal is child take 120 seconds before growing into adult + -- if animal is child take 240 seconds before growing into adult if self.child == true then self.hornytimer = self.hornytimer + 1 - if self.hornytimer > 120 then + if self.hornytimer > 240 then self.child = false self.hornytimer = 0 self.object:set_properties({ @@ -462,6 +409,59 @@ function mobs:register_mob(name, def) end end + if self.following and self.following:is_player() and self.following:get_wielded_item():get_name() ~= self.follow then + self.following = nil + self.v_start = false + end + + if self.following then + + local s = self.object:getpos() + local p + if self.following.is_player and self.following:is_player() then + p = self.following:getpos() + elseif self.following.object then + p = self.following.object:getpos() + end + + if p then + local dist = ((p.x-s.x)^2 + (p.y-s.y)^2 + (p.z-s.z)^2)^0.5 + if dist > self.view_range then + self.following = nil + self.v_start = false + else + local vec = {x=p.x-s.x, y=p.y-s.y, z=p.z-s.z} + local yaw = math.atan(vec.z/vec.x)+math.pi/2 + if self.drawtype == "side" then + yaw = yaw+(math.pi/2) + end + if p.x > s.x then + yaw = yaw+math.pi + end + self.object:setyaw(yaw) + if dist > 2 then + if not self.v_start then + self.v_start = true + self.set_velocity(self, self.walk_velocity) + else + if self.jump and self.get_velocity(self) <= 0.5 and self.object:getvelocity().y == 0 then -- 0.5 was 1.5 + local v = self.object:getvelocity() + v.y = 6 + self.object:setvelocity(v) + end + self.set_velocity(self, self.walk_velocity) + end + self:set_animation("walk") + else + self.v_start = false + self.set_velocity(self, 0) + self:set_animation("stand") + end + return + end + end + end + if self.state == "stand" then -- randomly turn if math.random(1, 4) == 1 then @@ -701,14 +701,13 @@ function mobs:register_mob(name, def) end end end - + -- quick fix for dog so it doesn't revert back to wolf + if self.type == "monster" and self.tamed == true then + self.type = "npc" + end if self.lifetimer <= 0 and not self.tamed and self.type ~= "npc" then self.object:remove() end - - -- Internal check to see if player damage is still enabled - damage_enabled = minetest.setting_getbool("enable_damage") - end, get_staticdata = function(self) diff --git a/chicken.lua b/chicken.lua index 0159beb..2f438c5 100644 --- a/chicken.lua +++ b/chicken.lua @@ -67,6 +67,9 @@ mobs:register_mob("mobs:chicken", { clicker:set_wielded_item(tool) end self.food = (self.food or 0) + 1 + if self.child == true then + self.hornytimer = self.hornytimer + 10 + end if self.food >= 8 then self.food = 0 if self.child == false then self.horny = true end diff --git a/cow.lua b/cow.lua index 23df85c..9745ee7 100644 --- a/cow.lua +++ b/cow.lua @@ -77,6 +77,9 @@ mobs:register_mob("mobs:cow", { clicker:set_wielded_item(tool) end self.food = (self.food or 0) + 1 + if self.child == true then + self.hornytimer = self.hornytimer + 10 + end if self.food >= 8 then self.food = 0 if self.child == false then self.horny = true end diff --git a/sheep.lua b/sheep.lua index 318d411..9da7a8e 100644 --- a/sheep.lua +++ b/sheep.lua @@ -62,6 +62,9 @@ mobs:register_mob("mobs:sheep", { clicker:set_wielded_item(item) end self.food = (self.food or 0) + 1 + if self.child == true then + self.hornytimer = self.hornytimer + 10 + end if self.food >= 8 then self.food = 0 if self.child == false then self.horny = true end