From 8d5fb3453448e2b032e248e8172021d45553ec46 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 5 Feb 2025 07:58:27 +0000 Subject: [PATCH] add mobs_animal.eat_grass_block setting --- cow.lua | 14 ++++++++++---- settingtypes.txt | 2 ++ sheep.lua | 14 ++++++++++---- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/cow.lua b/cow.lua index 2204a5e..a953d16 100644 --- a/cow.lua +++ b/cow.lua @@ -1,6 +1,15 @@ local S = minetest.get_translator("mobs_animal") +-- should cows eat grass blocks and mess up the environment? + +local eat_gb = minetest.settings:get_bool("mobs_animal.eat_grass_block") ~= false +local replace_what = { {"group:grass", "air", 0} } + +if eat_gb then + table.insert(replace_what, {"default:dirt_with_grass", "default:dirt", -1}) +end + -- Cow by sirrobzeroone mobs:register_mob("mobs_animal:cow", { @@ -51,10 +60,7 @@ mobs:register_mob("mobs_animal:cow", { }, view_range = 8, replace_rate = 10, - replace_what = { - {"group:grass", "air", 0}, - {"default:dirt_with_grass", "default:dirt", -1} - }, + replace_what = replace_what, --[[ pick_up = {"default:grass_1", "default:dry_grass_1"}, on_pick_up = function(self, entity) diff --git a/settingtypes.txt b/settingtypes.txt index fbc8178..de757f6 100644 --- a/settingtypes.txt +++ b/settingtypes.txt @@ -9,3 +9,5 @@ mobs_animal.rat (Enable Rat) bool true mobs_animal.sheep (Enable Sheep) bool true mobs_animal.warthog (Enable Warthog) bool true mobs_animal.hairball (Enable Kitten Hairball drops) bool true + +mobs_animal.eat_grass_block (Enable Cow/Sheep eating grass blocks) bool true diff --git a/sheep.lua b/sheep.lua index 7b8d14e..7d062c2 100644 --- a/sheep.lua +++ b/sheep.lua @@ -4,6 +4,15 @@ local S = minetest.get_translator("mobs_animal") local random = math.random +-- should sheep eat grass blocks and mess up the environment? + +local eat_gb = minetest.settings:get_bool("mobs_animal.eat_grass_block") ~= false +local replace_what = { {"group:grass", "air", -1} } + +if eat_gb then + table.insert(replace_what, {"default:dirt_with_grass", "default:dirt", -2}) +end + -- sheep colour table local all_colours = { @@ -115,10 +124,7 @@ for _, col in ipairs(all_colours) do }, view_range = 8, replace_rate = 10, - replace_what = { - {"group:grass", "air", -1}, - {"default:dirt_with_grass", "default:dirt", -2} - }, + replace_what = replace_what, fear_height = 3, on_replace = function(self, pos, oldnode, newnode)