From ff1be9a95be42b876b27677f5c05a2c4a152fe54 Mon Sep 17 00:00:00 2001 From: Wuzzy Date: Mon, 11 Mar 2024 12:12:13 +0100 Subject: [PATCH] Mobs: Separate taming level and horny level --- mods/rp_mobs/API.md | 5 +++-- mods/rp_mobs/feed_tame.lua | 34 +++++++++++++++++++++------------- mods/rp_mobs_mobs/boar.lua | 2 +- mods/rp_mobs_mobs/sheep.lua | 2 +- mods/rp_mobs_mobs/skunk.lua | 2 +- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/mods/rp_mobs/API.md b/mods/rp_mobs/API.md index 7ce36d94..9cc50fc6 100644 --- a/mods/rp_mobs/API.md +++ b/mods/rp_mobs/API.md @@ -233,9 +233,10 @@ These fields are available: ### Status * `_tamed`: `true` if mob is tame -* `_tb_level`: tame/breed level. Starts at 0 and increases for any food given, used to trigger taming/breeding +* `_tame_level`: tame level. Starts at 0 and increases for any food given, used to trigger taming +* `_horny_level`: 'horny' level. Starts at 0 and increases for any food given to an adult, used to trigger horny mode * `_child`: `true` if mob is a child -* `_horny`: `true` if mob is “horny”. If another horny mob is nearby, they will mate and spawn a child +* `_horny`: `true` if mob is “horny”. If another horny mob is nearby, they will mate and spawn a child soon * `_pregnant`: `true` if mob is pregnant and about to spawn a child ### Damage diff --git a/mods/rp_mobs/feed_tame.lua b/mods/rp_mobs/feed_tame.lua index cb299be9..d542dd32 100644 --- a/mods/rp_mobs/feed_tame.lua +++ b/mods/rp_mobs/feed_tame.lua @@ -2,7 +2,8 @@ local DEFAULT_ADD_CHILD_GROW_TIMER = 20 -- Entity variables to persist: rp_mobs.add_persisted_entity_vars({ - "_tb_level", -- tame/breed level. Increases when a mob was fed; used to trigger taming and breeding + "_tame_level", -- Tame level. Increases when a mob was fed; used to trigger taming + "_horny_level", -- Horny level. Increases when an adult mob was fed; used to trigger breeding "_tamed", -- true if mob is tame }) --[[ NOT persisted variables: @@ -10,8 +11,12 @@ rp_mobs.add_persisted_entity_vars({ ]] -local feed_handling = function(mob, feeder_name, food_points, food_till_tamed, can_breed, add_child_grow_timer) -- Check if a mob is fed - mob._tb_level = (mob._tb_level or 0) + food_points +local feed_handling = function(mob, feeder_name, food_points, food_till_tamed, food_till_horny, add_child_grow_timer) -- Check if a mob is fed + -- Increase tame and horny level + mob._tame_level = (mob._tame_level or 0) + food_points + if not mob._child and not mob._horny then + mob._horny_level = (mob._horny_level or 0) + food_points + end -- Remember name of feeder for achievements if feeder_name then @@ -25,12 +30,8 @@ local feed_handling = function(mob, feeder_name, food_points, food_till_tamed, c end -- Tame mob if threshold was reached - if food_till_tamed and mob._tb_level >= food_till_tamed then - mob._tb_level = 0 - - if can_breed and mob._horny_timer == 0 then - rp_mobs.make_horny(mob, true) - end + if food_till_tamed and mob._tame_level >= food_till_tamed then + mob._tame_level = 0 if (not mob._tamed) and feeder_name ~= nil then mob._tamed = true @@ -41,18 +42,25 @@ local feed_handling = function(mob, feeder_name, food_points, food_till_tamed, c end end end + + -- Make mob horny if threshold was reached + if food_till_horny and mob._horny_level >= food_till_horny and mob._horny_timer == 0 and not mob._child and not mob._horny then + mob._horny_level = 0 + + rp_mobs.make_horny(mob, true) + end end -- Let a player feed a mob with their wielded item and optionally tame it and make it horny -- * mob: The mob that is fed -- * feeder: Player who feeds the mob -- * allowed_foods: List of allowed food items --- * food_till_tamed: How many food points the mob needs until it is tamed --- * can_breed: true if feeding may cause this mob to become horny, false otherwise +-- * food_till_tamed: How many food points the mob needs until it is tamed (nil = no taming) +-- * food_till_horny: How many food points the mob needs until it becomes horny (nil = no horny) -- * add_child_growth_timer: (optional) By how many seconds the child growth timer is increased (default: 20) -- * effect: (optional) true to show particle effects, false otherwise (default: true) -- * eat_sound: (optional) Name of sound to play for the mob eating (default: "mobs_eat") -rp_mobs.feed_tame_breed = function(mob, feeder, allowed_foods, food_till_tamed, can_breed, add_child_grow_timer, effect, eat_sound) +rp_mobs.feed_tame_breed = function(mob, feeder, allowed_foods, food_till_tamed, food_till_horny, add_child_grow_timer, effect, eat_sound) if not rp_mobs.is_alive(mob) then return false end @@ -126,7 +134,7 @@ rp_mobs.feed_tame_breed = function(mob, feeder, allowed_foods, food_till_tamed, }) end - feed_handling(mob, feeder_name, food_points, food_till_tamed, can_breed, add_child_grow_timer) + feed_handling(mob, feeder_name, food_points, food_till_tamed, food_till_horny, add_child_grow_timer) return true else diff --git a/mods/rp_mobs_mobs/boar.lua b/mods/rp_mobs_mobs/boar.lua index 299a80fd..ebd3b826 100644 --- a/mods/rp_mobs_mobs/boar.lua +++ b/mods/rp_mobs_mobs/boar.lua @@ -95,7 +95,7 @@ rp_mobs.register_mob("rp_mobs_mobs:boar", { rp_mobs.handle_breeding(self, dtime) end, on_rightclick = function(self, clicker) - rp_mobs.feed_tame_breed(self, clicker, FOOD, 8, true) + rp_mobs.feed_tame_breed(self, clicker, FOOD, 8, 8) rp_mobs.call_on_capture(self, clicker) end, _on_capture = function(self, capturer) diff --git a/mods/rp_mobs_mobs/sheep.lua b/mods/rp_mobs_mobs/sheep.lua index 82cc6c91..3b844000 100644 --- a/mods/rp_mobs_mobs/sheep.lua +++ b/mods/rp_mobs_mobs/sheep.lua @@ -184,7 +184,7 @@ rp_mobs.register_mob("rp_mobs_mobs:sheep", { end -- Are we feeding? - if rp_mobs.feed_tame_breed(self, clicker, FOOD, 8, true) then + if rp_mobs.feed_tame_breed(self, clicker, FOOD, 8, 8) then -- Update wool status if shorn if not self._custom_state.shorn then self.object:set_properties({ diff --git a/mods/rp_mobs_mobs/skunk.lua b/mods/rp_mobs_mobs/skunk.lua index fb53d70c..cfc2a9a3 100644 --- a/mods/rp_mobs_mobs/skunk.lua +++ b/mods/rp_mobs_mobs/skunk.lua @@ -88,7 +88,7 @@ rp_mobs.register_mob("rp_mobs_mobs:skunk", { rp_mobs.handle_breeding(self, dtime) end, on_rightclick = function(self, clicker) - rp_mobs.feed_tame_breed(self, clicker, FOOD, 6, true) + rp_mobs.feed_tame_breed(self, clicker, FOOD, 6, 6) rp_mobs.call_on_capture(self, clicker) end, _on_capture = function(self, capturer)