mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-11-28 05:43:43 +01:00
Rearange on replace code to be more general purpous
This commit is contained in:
parent
908ba9fba6
commit
86cd5711ca
@ -217,6 +217,7 @@ function mcl_mobs.register_mob(name, def)
|
||||
replace_with = def.replace_with,
|
||||
replace_offset = def.replace_offset or 0,
|
||||
on_replace = def.on_replace,
|
||||
replace_delay = def.replace_delay or 0,
|
||||
timer = 0,
|
||||
env_damage_timer = 0,
|
||||
tamed = false,
|
||||
|
@ -513,27 +513,18 @@ function mob_class:replace_node(pos)
|
||||
|
||||
local oldnode = {name = what, param2 = node.param2}
|
||||
local newnode = {name = with, param2 = node.param2}
|
||||
local on_replace_return = true
|
||||
local on_replace_return = false
|
||||
if self.on_replace then
|
||||
on_replace_return = self.on_replace(self, pos, oldnode, newnode)
|
||||
end
|
||||
|
||||
|
||||
if on_replace_return ~= false then
|
||||
|
||||
if mobs_griefing then
|
||||
self.state = "eat"
|
||||
self:set_animation("eat")
|
||||
self:set_velocity(0)
|
||||
minetest.after(1.3, function()
|
||||
if self and self.object and not self.dead then
|
||||
self.object:set_velocity(vector.new(0,0,0))
|
||||
minetest.after(self.replace_delay, function()
|
||||
if self and self.object and self.object:get_velocity() and self.health > 0 then
|
||||
minetest.set_node(pos, newnode)
|
||||
if self.on_replace then
|
||||
on_replace_return = self.on_replace(self, pos, oldnode, newnode)
|
||||
end
|
||||
end
|
||||
end)
|
||||
minetest.after(2.5, function()
|
||||
if self and self.object and self.state == 'eat' and not self.dead then
|
||||
self.state = "walk"
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
@ -113,29 +113,43 @@ mcl_mobs.register_mob("mobs_mc:sheep", {
|
||||
view_range = 12,
|
||||
|
||||
-- Eat grass
|
||||
replace_rate = 40,
|
||||
replace_rate = 1,
|
||||
replace_delay = 1.3,
|
||||
replace_what = {
|
||||
{ "mcl_core:dirt_with_grass", "mcl_core:dirt", -1 },
|
||||
{ "mcl_flowers:tallgrass", "air", 0 },
|
||||
},
|
||||
-- Properly regrow wool after eating grass
|
||||
on_replace = function(self, pos, oldnode, newnode)
|
||||
if not self.color or not colors[self.color] then
|
||||
self.color = "unicolor_white"
|
||||
end
|
||||
self.gotten = false
|
||||
self.base_texture = sheep_texture(self.color)
|
||||
self.object:set_properties({ textures = self.base_texture })
|
||||
self.drops = {
|
||||
{name = "mcl_mobitems:mutton",
|
||||
chance = 1,
|
||||
min = 1,
|
||||
max = 2,},
|
||||
{name = colors[self.color][1],
|
||||
chance = 1,
|
||||
min = 1,
|
||||
max = 1,},
|
||||
}
|
||||
self.state = "eat"
|
||||
self:set_animation("eat")
|
||||
self:set_velocity(0)
|
||||
minetest.after(self.replace_delay, function()
|
||||
self.object:set_velocity(vector.zero())
|
||||
if self and self.object and not self.object:get_velocity() and self.health > 0 then
|
||||
if not self.color or not colors[self.color] then
|
||||
self.color = "unicolor_white"
|
||||
end
|
||||
self.gotten = false
|
||||
self.base_texture = sheep_texture(self.color)
|
||||
self.object:set_properties({ textures = self.base_texture })
|
||||
self.drops = {
|
||||
{name = "mcl_mobitems:mutton",
|
||||
chance = 1,
|
||||
min = 1,
|
||||
max = 2,},
|
||||
{name = colors[self.color][1],
|
||||
chance = 1,
|
||||
min = 1,
|
||||
max = 1,},
|
||||
}
|
||||
end
|
||||
end)
|
||||
minetest.after(2.5, function()
|
||||
if self and self.object and self.state == 'eat' and self.health > 0 and self.object:get_velocity() then
|
||||
self.state = "walk"
|
||||
end
|
||||
end)
|
||||
end,
|
||||
|
||||
-- Set random color on spawn
|
||||
|
Loading…
Reference in New Issue
Block a user