1
0
Fork 0

Rearange on replace code to be more general purpous

This commit is contained in:
epCode 2023-06-04 13:20:29 -07:00 committed by epCode
parent 908ba9fba6
commit 86cd5711ca
3 changed files with 39 additions and 33 deletions

View File

@ -217,6 +217,7 @@ function mcl_mobs.register_mob(name, def)
replace_with = def.replace_with, replace_with = def.replace_with,
replace_offset = def.replace_offset or 0, replace_offset = def.replace_offset or 0,
on_replace = def.on_replace, on_replace = def.on_replace,
replace_delay = def.replace_delay or 0,
timer = 0, timer = 0,
env_damage_timer = 0, env_damage_timer = 0,
tamed = false, tamed = false,
@ -490,7 +491,7 @@ function mcl_mobs.register_egg(mob, desc, background_color, overlay_color, addeg
on_place = function(itemstack, placer, pointed_thing) on_place = function(itemstack, placer, pointed_thing)
local pos = pointed_thing.above local pos = pointed_thing.above
-- am I clicking on something with existing on_rightclick function? -- am I clicking on something with existing on_rightclick function?
local under = minetest.get_node(pointed_thing.under) local under = minetest.get_node(pointed_thing.under)
local def = minetest.registered_nodes[under.name] local def = minetest.registered_nodes[under.name]

View File

@ -513,27 +513,18 @@ function mob_class:replace_node(pos)
local oldnode = {name = what, param2 = node.param2} local oldnode = {name = what, param2 = node.param2}
local newnode = {name = with, 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 on_replace_return ~= false then
if mobs_griefing then if mobs_griefing then
self.state = "eat" minetest.after(self.replace_delay, function()
self:set_animation("eat") if self and self.object and self.object:get_velocity() and self.health > 0 then
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.set_node(pos, newnode) 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) end)
end end

View File

@ -113,29 +113,43 @@ mcl_mobs.register_mob("mobs_mc:sheep", {
view_range = 12, view_range = 12,
-- Eat grass -- Eat grass
replace_rate = 40, replace_rate = 1,
replace_delay = 1.3,
replace_what = { replace_what = {
{ "mcl_core:dirt_with_grass", "mcl_core:dirt", -1 }, { "mcl_core:dirt_with_grass", "mcl_core:dirt", -1 },
{ "mcl_flowers:tallgrass", "air", 0 }, { "mcl_flowers:tallgrass", "air", 0 },
}, },
-- Properly regrow wool after eating grass -- Properly regrow wool after eating grass
on_replace = function(self, pos, oldnode, newnode) on_replace = function(self, pos, oldnode, newnode)
if not self.color or not colors[self.color] then self.state = "eat"
self.color = "unicolor_white" self:set_animation("eat")
end self:set_velocity(0)
self.gotten = false minetest.after(self.replace_delay, function()
self.base_texture = sheep_texture(self.color) self.object:set_velocity(vector.zero())
self.object:set_properties({ textures = self.base_texture }) if self and self.object and not self.object:get_velocity() and self.health > 0 then
self.drops = { if not self.color or not colors[self.color] then
{name = "mcl_mobitems:mutton", self.color = "unicolor_white"
chance = 1, end
min = 1, self.gotten = false
max = 2,}, self.base_texture = sheep_texture(self.color)
{name = colors[self.color][1], self.object:set_properties({ textures = self.base_texture })
chance = 1, self.drops = {
min = 1, {name = "mcl_mobitems:mutton",
max = 1,}, 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, end,
-- Set random color on spawn -- Set random color on spawn