Fix wool farm crash

This commit is contained in:
ancientmarinerdev 2023-06-19 17:49:20 +01:00
parent 088f8dec2f
commit 7d51519f4d
3 changed files with 29 additions and 8 deletions

View file

@ -6,6 +6,8 @@ local S = minetest.get_translator("mobs_mc")
--################### SHEEP --################### SHEEP
--################### --###################
local WOOL_REPLACE_RATE = 80
local colors = { local colors = {
-- group = { wool, textures } -- group = { wool, textures }
unicolor_white = { "mcl_wool:white", "#FFFFFF00" }, unicolor_white = { "mcl_wool:white", "#FFFFFF00" },
@ -113,7 +115,7 @@ mcl_mobs.register_mob("mobs_mc:sheep", {
view_range = 12, view_range = 12,
-- Eat grass -- Eat grass
replace_rate = 80, replace_rate = WOOL_REPLACE_RATE,
replace_delay = 1.3, 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 },
@ -121,25 +123,42 @@ mcl_mobs.register_mob("mobs_mc:sheep", {
}, },
-- 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)
self.state = "eat"
self:set_animation("eat")
self:set_velocity(0)
minetest.after(self.replace_delay, function()
if self and self.object and self.object:get_velocity() and self.health > 0 then
self.object:set_velocity(vector.zero())
if not self.color or not colors[self.color] then if not self.color or not colors[self.color] then
self.color = "unicolor_white" self.color = "unicolor_white"
end end
self.gotten = false
self.base_texture = sheep_texture(self.color) self.base_texture = sheep_texture(self.color)
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()
if self and self.object and self.object:get_velocity() and self.health > 0 then
self.object:set_velocity(vector.zero())
self.gotten = false
self.object:set_properties({ textures = self.base_texture }) self.object:set_properties({ textures = self.base_texture })
end end
end) end)
minetest.after(2.5, function() minetest.after(2.5, function()
if self and self.object and self.state == 'eat' and self.health > 0 and self.object:get_velocity() then if self and self.object and self.state == 'eat' and self.health > 0 then
self.state = "walk" self.state = "walk"
end end
end) end)
end, end,
-- Set random color on spawn -- Set random color on spawn

View file

@ -178,7 +178,9 @@ local dispenserdef = {
local pos = obj:get_pos() local pos = obj:get_pos()
local used, texture = false local used, texture = false
if entname == "mobs_mc:sheep" then if entname == "mobs_mc:sheep" then
if entity.drops[2] then
minetest.add_item(pos, entity.drops[2].name .. " " .. math.random(1, 3)) minetest.add_item(pos, entity.drops[2].name .. " " .. math.random(1, 3))
end
if not entity.color then if not entity.color then
entity.color = "unicolor_white" entity.color = "unicolor_white"
end end

View file

@ -177,7 +177,7 @@ end
function mesecon.effector_get_rules(node) function mesecon.effector_get_rules(node)
local effector = mesecon.get_effector(node.name) local effector = mesecon.get_effector(node.name)
if effector then if effector and effector.rules then
local rules = effector.rules local rules = effector.rules
if type(rules) == "function" then if type(rules) == "function" then
return rules(node) return rules(node)