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_start = 70,
punch_end = 100, punch_end = 100,
}, },
follow = "farming:wheat", follow = {"farming:wheat", "default:grass_1"},
view_range = 8, view_range = 8,
replace_rate = 10, replace_rate = 10,
-- replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
replace_what = { replace_what = {
{"group:grass", "air", 0}, {"group:grass", "air", 0},
{"default:dirt_with_grass", "default:dirt", -1} {"default:dirt_with_grass", "default:dirt", -1}
}, },
replace_with = "air",
fear_height = 2, fear_height = 2,
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
-- feed or tame -- 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:protect(self, clicker) then return end
if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) 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 return
end end
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_start = 81,
walk_end = 100, walk_end = 100,
}, },
follow = {"farming:wheat", "default:grass_5"}, follow = {"farming:wheat", "default:grass_1"},
view_range = 8, view_range = 8,
replace_rate = 10, replace_rate = 10,
replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"}, replace_what = {
replace_with = "air", {"group:grass", "air", -1},
replace_offset = -1, {"default:dirt_with_grass", "default:dirt", -2}
},
fear_height = 3, fear_height = 3,
--[[
on_replace = function(self, pos, oldnode, newnode) 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, end,
]]
on_rightclick = function(self, clicker) on_rightclick = function(self, clicker)
--are we feeding? --are we feeding?
if mobs:feed_tame(self, clicker, 8, true, true) then if mobs:feed_tame(self, clicker, 8, true, true) then
--if full grow fuzz --if fed 7x grass or wheat then sheep regrows wool
if self.gotten == false then if self.food > 6 then
self.food = 0
self.gotten = false
self.object:set_properties({ self.object:set_properties({
textures = {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"}, textures = {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},