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

add on_replace functions to cow and sheep to replace milk and wool when eating

This commit is contained in:
TenPlus1 2018-11-26 17:47:15 +00:00
parent 10028cd63d
commit 01d7e07f2a
2 changed files with 47 additions and 13 deletions

27
cow.lua
View File

@ -49,20 +49,29 @@ mobs:register_mob("mobs_animal:cow", {
punch_start = 70,
punch_end = 100,
},
follow = "farming:wheat",
follow = {"farming:wheat", "default:grass_1"},
view_range = 8,
replace_rate = 10,
-- replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_what = {
{"group:grass", "air", 0},
{"default:dirt_with_grass", "default:dirt", -1}
},
replace_with = "air",
fear_height = 2,
on_rightclick = function(self, clicker)
-- feed or tame
if mobs:feed_tame(self, clicker, 8, true, true) then return end
if mobs:feed_tame(self, clicker, 8, true, true) then
-- if fed 7x wheat or grass then cow can be milked again
if self.food > 6 then
self.food = 0
self.gotten = false
end
return
end
if mobs:protect(self, clicker) then return end
if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
@ -101,6 +110,16 @@ mobs:register_mob("mobs_animal:cow", {
return
end
end,
on_replace = function(self, pos, oldnode, newnode)
self.food = (self.food or 0) + 1
-- if cow replaces 8x grass then it can be milked again
if self.food >= 8 then
self.food = 0
self.gotten = false
end
end,
})

View File

@ -65,25 +65,40 @@ stepheight = 0.6,
walk_start = 81,
walk_end = 100,
},
follow = {"farming:wheat", "default:grass_5"},
follow = {"farming:wheat", "default:grass_1"},
view_range = 8,
replace_rate = 10,
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_with = "air",
replace_offset = -1,
replace_what = {
{"group:grass", "air", -1},
{"default:dirt_with_grass", "default:dirt", -2}
},
fear_height = 3,
--[[
on_replace = function(self, pos, oldnode, newnode)
print ("---- replaced") ; return false -- false to keep node, true to replace
self.food = (self.food or 0) + 1
-- if sheep replaces 8x grass then it regrows wool
if self.food >= 8 then
self.food = 0
self.gotten = false
self.object:set_properties({
textures = {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},
mesh = "mobs_sheep.b3d",
})
end
end,
]]
on_rightclick = function(self, clicker)
--are we feeding?
if mobs:feed_tame(self, clicker, 8, true, true) then
--if full grow fuzz
if self.gotten == false then
--if fed 7x grass or wheat then sheep regrows wool
if self.food > 6 then
self.food = 0
self.gotten = false
self.object:set_properties({
textures = {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},