0
0
Fork 0

Split off breeding

This commit is contained in:
cora 2022-11-09 04:57:48 +01:00
parent 70834d0f5d
commit e82c318f0c
15 changed files with 161 additions and 151 deletions

View File

@ -1,5 +1,6 @@
local mob_class = mcl_mobs.mob_class
local mob_class_meta = {__index = mcl_mobs.mob_class}
local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
-- API for Mobs Redo: MineClone 2 Edition (MRM)
local MAX_MOB_NAME_LENGTH = 30
local HORNY_TIME = 30
@ -753,7 +754,7 @@ local breed = function(self)
end
end
local child = mcl_mobs:spawn_child(pos, parent1.name)
local child = mcl_mobs.spawn_child(pos, parent1.name)
local ent_c = child:get_luaentity()
@ -4062,141 +4063,6 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
end
-- No-op in MCL2 (capturing mobs is not possible).
-- Provided for compability with Mobs Redo
function mcl_mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
return false
end
-- No-op in MCL2 (protecting mobs is not possible).
function mcl_mobs:protect(self, clicker)
return false
end
-- feeding, taming and breeding (thanks blert2112)
function mcl_mobs:feed_tame(self, clicker, feed_count, breed, tame, notake)
if not self.follow then
return false
end
-- can eat/tame with item in hand
if self.nofollow or follow_holding(self, clicker) then
local consume_food = false
-- tame if not still a baby
if tame and not self.child then
if not self.owner or self.owner == "" then
self.tamed = true
self.owner = clicker:get_player_name()
consume_food = true
end
end
-- increase health
if self.health < self.hp_max and not consume_food then
consume_food = true
self.health = math.min(self.health + 4, self.hp_max)
if self.htimer < 1 then
self.htimer = 5
end
self.object:set_hp(self.health)
end
-- make children grow quicker
if not consume_food and self.child == true then
consume_food = true
-- deduct 10% of the time to adulthood
self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1)
end
-- breed animals
if breed and not consume_food and self.hornytimer == 0 and not self.horny then
self.food = (self.food or 0) + 1
consume_food = true
if self.food >= feed_count then
self.food = 0
self.horny = true
end
end
self:update_tag()
-- play a sound if the animal used the item and take the item if not in creative
if consume_food then
-- don't consume food if clicker is in creative
if not minetest.is_creative_enabled(clicker:get_player_name()) and not notake then
local item = clicker:get_wielded_item()
item:take_item()
clicker:set_wielded_item(item)
end
-- always play the eat sound if food is used, even in creative
self:mob_sound("eat", nil, true)
else
-- make sound when the mob doesn't want food
self:mob_sound("random", true)
end
return true
end
return false
end
-- Spawn a child
function mcl_mobs:spawn_child(pos, mob_type)
local child = minetest.add_entity(pos, mob_type)
if not child then
return
end
local ent = child:get_luaentity()
mcl_mobs.effect(pos, 15, "mcl_particles_smoke.png", 1, 2, 2, 15, 5)
ent.child = true
local textures
-- using specific child texture (if found)
if ent.child_texture then
textures = ent.child_texture[1]
end
-- and resize to half height
child:set_properties({
textures = textures,
visual_size = {
x = ent.base_size.x * .5,
y = ent.base_size.y * .5,
},
collisionbox = {
ent.base_colbox[1] * .5,
ent.base_colbox[2] * .5,
ent.base_colbox[3] * .5,
ent.base_colbox[4] * .5,
ent.base_colbox[5] * .5,
ent.base_colbox[6] * .5,
},
selectionbox = {
ent.base_selbox[1] * .5,
ent.base_selbox[2] * .5,
ent.base_selbox[3] * .5,
ent.base_selbox[4] * .5,
ent.base_selbox[5] * .5,
ent.base_selbox[6] * .5,
},
})
ent.animation = ent._child_animations
ent._current_animation = nil
set_animation(ent, "stand")
return child
end
local timer = 0
minetest.register_globalstep(function(dtime)
timer = timer + dtime

View File

@ -0,0 +1,142 @@
local math, vector, minetest, mcl_mobs = math, vector, minetest, mcl_mobs
local mob_class = mcl_mobs.mob_class
local MAX_MOB_NAME_LENGTH = 30
local HORNY_TIME = 30
local HORNY_AGAIN_TIME = 300
local CHILD_GROW_TIME = 60*20
-- No-op in MCL2 (capturing mobs is not possible).
-- Provided for compability with Mobs Redo
function mcl_mobs:capture_mob(self, clicker, chance_hand, chance_net, chance_lasso, force_take, replacewith)
return false
end
-- No-op in MCL2 (protecting mobs is not possible).
function mcl_mobs:protect(self, clicker)
return false
end
-- feeding, taming and breeding (thanks blert2112)
function mob_class:feed_tame(clicker, feed_count, breed, tame, notake)
if not self.follow then
return false
end
-- can eat/tame with item in hand
if self.nofollow or follow_holding(self, clicker) then
local consume_food = false
-- tame if not still a baby
if tame and not self.child then
if not self.owner or self.owner == "" then
self.tamed = true
self.owner = clicker:get_player_name()
consume_food = true
end
end
-- increase health
if self.health < self.hp_max and not consume_food then
consume_food = true
self.health = math.min(self.health + 4, self.hp_max)
if self.htimer < 1 then
self.htimer = 5
end
self.object:set_hp(self.health)
end
-- make children grow quicker
if not consume_food and self.child == true then
consume_food = true
-- deduct 10% of the time to adulthood
self.hornytimer = self.hornytimer + ((CHILD_GROW_TIME - self.hornytimer) * 0.1)
end
-- breed animals
if breed and not consume_food and self.hornytimer == 0 and not self.horny then
self.food = (self.food or 0) + 1
consume_food = true
if self.food >= feed_count then
self.food = 0
self.horny = true
end
end
self:update_tag()
-- play a sound if the animal used the item and take the item if not in creative
if consume_food then
-- don't consume food if clicker is in creative
if not minetest.is_creative_enabled(clicker:get_player_name()) and not notake then
local item = clicker:get_wielded_item()
item:take_item()
clicker:set_wielded_item(item)
end
-- always play the eat sound if food is used, even in creative
self:mob_sound("eat", nil, true)
else
-- make sound when the mob doesn't want food
self:mob_sound("random", true)
end
return true
end
return false
end
-- Spawn a child
function mcl_mobs.spawn_child(pos, mob_type)
local child = minetest.add_entity(pos, mob_type)
if not child then
return
end
local ent = child:get_luaentity()
mcl_mobs.effect(pos, 15, "mcl_particles_smoke.png", 1, 2, 2, 15, 5)
ent.child = true
local textures
-- using specific child texture (if found)
if ent.child_texture then
textures = ent.child_texture[1]
end
-- and resize to half height
child:set_properties({
textures = textures,
visual_size = {
x = ent.base_size.x * .5,
y = ent.base_size.y * .5,
},
collisionbox = {
ent.base_colbox[1] * .5,
ent.base_colbox[2] * .5,
ent.base_colbox[3] * .5,
ent.base_colbox[4] * .5,
ent.base_colbox[5] * .5,
ent.base_colbox[6] * .5,
},
selectionbox = {
ent.base_selbox[1] * .5,
ent.base_selbox[2] * .5,
ent.base_selbox[3] * .5,
ent.base_selbox[4] * .5,
ent.base_selbox[5] * .5,
ent.base_selbox[6] * .5,
},
})
ent.animation = ent._child_animations
ent._current_animation = nil
ent:set_animation("stand")
return child
end

View File

@ -9,6 +9,8 @@ dofile(path .. "/physics.lua")
-- Mob API
dofile(path .. "/api.lua")
dofile(path .. "/breeding.lua")
-- Spawning Algorithm
dofile(path .. "/spawning.lua")

View File

@ -83,7 +83,7 @@ mcl_mobs.register_mob("mobs_mc:chicken", {
fear_height = 4,
on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end
if mcl_mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end
end,

View File

@ -59,7 +59,7 @@ local cow_def = {
run_start = 41, run_end = 81, run_speed = 60,
},
on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end
if self.child then
@ -97,7 +97,7 @@ mooshroom_def.spawn_in_group_min = 4
mooshroom_def.spawn_in_group = 8
mooshroom_def.textures = { {"mobs_mc_mooshroom.png", "mobs_mc_mushroom_red.png"}, {"mobs_mc_mooshroom_brown.png", "mobs_mc_mushroom_brown.png" } }
mooshroom_def.on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end
if self.child then

View File

@ -337,7 +337,7 @@ local horse = {
elseif (iname == "mcl_farming:carrot_item_gold") then
heal = 4
end
if heal > 0 and mcl_mobs:feed_tame(self, clicker, heal, true, false) then
if heal > 0 and self:feed_tame(clicker, heal, true, false) then
return
end
end
@ -352,7 +352,7 @@ local horse = {
elseif (iname == "mcl_farming:hay_block") then
heal = 20
end
if heal > 0 and mcl_mobs:feed_tame(self, clicker, heal, false, false) then
if heal > 0 and self:feed_tame(clicker, heal, false, false) then
return
end

View File

@ -156,7 +156,7 @@ mcl_mobs.register_mob("mobs_mc:llama", {
local item = clicker:get_wielded_item()
if item:get_name() == "mcl_farming:hay_block" then
-- Breed with hay bale
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
elseif not self._has_chest and item:get_name() == "mcl_chests:chest" then
item:take_item()
clicker:set_wielded_item(item)
@ -173,7 +173,7 @@ mcl_mobs.register_mob("mobs_mc:llama", {
return
else
-- Feed with anything else
if mcl_mobs:feed_tame(self, clicker, 1, false, true) then return end
if self:feed_tame(clicker, 1, false, true) then return end
end
if mcl_mobs:protect(self, clicker) then return end

View File

@ -130,7 +130,7 @@ cat.sounds = {
distance = 16,
}
cat.on_rightclick = function(self, clicker)
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:capture_mob(self, clicker, 0, 60, 5, false, nil) then return end
if mcl_mobs:protect(self, clicker) then return end

View File

@ -207,7 +207,7 @@ mcl_mobs.register_mob("mobs_mc:parrot", {
return
end
-- Feed to tame, but not breed
if mcl_mobs:feed_tame(self, clicker, 1, false, true) then return end
if self:feed_tame(clicker, 1, false, true) then return end
perch(self,clicker)
end,
do_custom = function(self,dtime)

View File

@ -108,7 +108,7 @@ mcl_mobs.register_mob("mobs_mc:pig", {
local wielditem = clicker:get_wielded_item()
-- Feed pig
if wielditem:get_name() ~= "mcl_mobitems:carrot_on_a_stick" then
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
end
if mcl_mobs:protect(self, clicker) then return end

View File

@ -83,7 +83,7 @@ local rabbit = {
},
on_rightclick = function(self, clicker)
-- Feed, tame protect or capture
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end
if mcl_mobs:capture_mob(self, clicker, 0, 50, 80, false, nil) then return end
end,

View File

@ -205,7 +205,7 @@ mcl_mobs.register_mob("mobs_mc:sheep", {
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then return end
if self:feed_tame(clicker, 1, true, false) then return end
if mcl_mobs:protect(self, clicker) then return end
if item:get_name() == "mcl_tools:shears" and not self.gotten and not self.child then

View File

@ -123,7 +123,7 @@ local strider = {
local wielditem = clicker:get_wielded_item()
if wielditem:get_name() ~= "mcl_crimson:warped_fungus" then
if mcl_mobs:feed_tame(self, clicker, 1, true, true) then return end
if self:feed_tame(clicker, 1, true, true) then return end
end
if self.child then

View File

@ -1963,7 +1963,7 @@ mcl_mobs.register_mob("mobs_mc:villager", {
end
end
if clicker and not self.horny then
mcl_mobs:feed_tame(self, clicker, 1, true, false, true)
self:feed_tame(clicker, 1, true, false, true)
it:take_item(1)
end
return it

View File

@ -167,7 +167,7 @@ end
dog.on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if mcl_mobs:feed_tame(self, clicker, 1, true, false) then
if self:feed_tame(clicker, 1, true, false) then
return
elseif mcl_mobs:protect(self, clicker) then
return