animalia/mobs/sheep.lua

249 lines
6 KiB
Lua
Raw Normal View History

2020-11-11 23:16:50 -08:00
-----------
-- Sheep --
-----------
2022-08-12 22:17:42 -07:00
local random = math.random
2022-02-10 18:00:06 -08:00
local follows = {}
minetest.register_on_mods_loaded(function()
for name in pairs(minetest.registered_items) do
if (name:match(":wheat")
2022-02-10 18:00:06 -08:00
or minetest.get_item_group(name, "food_wheat") > 0)
and not name:find("seed") then
table.insert(follows, name)
end
end
2022-02-10 18:00:06 -08:00
end)
2022-04-02 16:59:24 -07:00
local wool_block = "wool:white"
2022-02-10 18:00:06 -08:00
if not minetest.get_modpath("wool") then
wool_block = nil
end
local creative = minetest.settings:get_bool("creative_mode")
2020-11-25 00:27:54 -08:00
2020-11-11 23:16:50 -08:00
local palette = {
{"black", "Black", "#000000b0"},
{"blue", "Blue", "#015dbb70"},
{"brown", "Brown", "#663300a0"},
{"cyan", "Cyan", "#01ffd870"},
{"dark_green", "Dark Green", "#005b0770"},
{"dark_grey", "Dark Grey", "#303030b0"},
{"green", "Green", "#61ff0170"},
{"grey", "Grey", "#5b5b5bb0"},
{"magenta", "Magenta", "#ff05bb70"},
{"orange", "Orange", "#ff840170"},
{"pink", "Pink", "#ff65b570"},
{"red", "Red", "#ff0000a0"},
{"violet", "Violet", "#2000c970"},
{"white", "White", "#ababab00"},
{"yellow", "Yellow", "#e3ff0070"},
}
2022-02-10 18:00:06 -08:00
creatura.register_mob("animalia:sheep", {
-- Stats
max_health = 15,
armor_groups = {fleshy = 125},
damage = 0,
speed = 3,
2022-02-10 18:00:06 -08:00
tracking_range = 16,
despawn_after = 1500,
2022-02-10 18:00:06 -08:00
-- Entity Physics
stepheight = 1.1,
-- Visuals
mesh = "animalia_sheep.b3d",
2022-02-10 18:00:06 -08:00
hitbox = {
width = 0.4,
height = 0.8
},
2020-11-11 23:16:50 -08:00
visual_size = {x = 10, y = 10},
2022-02-10 18:00:06 -08:00
textures = {
"animalia_sheep.png^animalia_sheep_wool.png"
},
child_textures = {
"animalia_sheep.png"
},
animations = {
stand = {range = {x = 1, y = 60}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 70, y = 110}, speed = 40, frame_blend = 0.3, loop = true},
run = {range = {x = 70, y = 110}, speed = 50, frame_blend = 0.3, loop = true},
2020-11-11 23:16:50 -08:00
},
-- Misc
makes_footstep_sound = true,
2022-10-17 17:23:26 -07:00
flee_puncher = true,
2022-02-10 18:00:06 -08:00
catch_with_net = true,
catch_with_lasso = true,
2022-02-10 18:00:06 -08:00
sounds = {
random = {
name = "animalia_sheep_idle",
gain = 1.0,
distance = 8
},
hurt = {
name = "animalia_sheep_hurt",
2020-11-11 23:16:50 -08:00
gain = 1.0,
distance = 8
},
death = {
name = "animalia_sheep_death",
2020-11-11 23:16:50 -08:00
gain = 1.0,
distance = 8
}
},
drops = {
{name = "animalia:mutton_raw", min = 1, max = 3, chance = 1},
2022-02-10 18:00:06 -08:00
{name = wool_block, min = 1, max = 3, chance = 2}
},
follow = follows,
2020-11-11 23:16:50 -08:00
consumable_nodes = {
2022-08-12 22:17:42 -07:00
["default:dirt_with_grass"] = "default:dirt",
["default:dry_dirt_with_dry_grass"] = "default:dry_dirt"
2020-11-11 23:16:50 -08:00
},
head_data = {
offset = {x = 0, y = 0.41, z = 0},
pitch_correction = -45,
pivot_h = 0.75,
pivot_v = 0.85
},
-- Function
2022-02-10 18:00:06 -08:00
utility_stack = {
2022-08-12 22:17:42 -07:00
{
utility = "animalia:wander_group",
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
2022-08-12 22:17:42 -07:00
return 0.1, {self}
2020-11-25 00:27:54 -08:00
end
2022-02-10 18:00:06 -08:00
},
2022-08-12 22:17:42 -07:00
{
utility = "animalia:eat_turf",
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
2022-08-12 22:17:42 -07:00
if random(64) < 2 then
return 0.2, {self}
2022-02-10 18:00:06 -08:00
end
return 0
end
},
2022-08-12 22:17:42 -07:00
{
2022-02-10 18:00:06 -08:00
utility = "animalia:swim_to_land",
2022-08-12 22:17:42 -07:00
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
if self.in_liquid then
2022-08-12 22:17:42 -07:00
return 0.3, {self}
2022-02-10 18:00:06 -08:00
end
return 0
end
},
2022-10-17 17:23:26 -07:00
animalia.global_utils.basic_follow,
2022-08-12 22:17:42 -07:00
{
utility = "animalia:breed",
step_delay = 0.25,
2022-02-10 18:00:06 -08:00
get_score = function(self)
2022-02-22 20:27:38 -08:00
if self.breeding
and animalia.get_nearby_mate(self, self.name) then
2022-08-12 22:17:42 -07:00
return 0.5, {self}
end
return 0
end
},
2022-10-17 17:23:26 -07:00
animalia.global_utils.basic_flee
2022-02-10 18:00:06 -08:00
},
activate_func = function(self)
self.collected = self:recall("collected") or false
2022-02-10 18:00:06 -08:00
self.dye_color = self:recall("dye_color") or "white"
self.dye_hex = self:recall("dye_hex") or ""
2020-11-11 23:16:50 -08:00
if self.dye_color ~= "white"
2022-08-12 22:17:42 -07:00
and not self.collected then
2020-11-11 23:16:50 -08:00
self.object:set_properties({
textures = {"animalia_sheep.png^(animalia_sheep_wool.png^[colorize:" .. self.dye_hex .. ")"},
2020-11-11 23:16:50 -08:00
})
end
2022-08-12 22:17:42 -07:00
if self.collected then
2020-11-11 23:16:50 -08:00
self.object:set_properties({
textures = {"animalia_sheep.png"},
2020-11-11 23:16:50 -08:00
})
end
self.attention_span = 8
self._path = {}
2022-02-10 18:00:06 -08:00
animalia.initialize_api(self)
animalia.initialize_lasso(self)
end,
step_func = function(self)
2022-02-10 18:00:06 -08:00
animalia.step_timers(self)
animalia.head_tracking(self, 0.75, 0.75)
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.random_sound(self)
end,
death_func = function(self)
2022-02-10 18:00:06 -08:00
if self:get_utility() ~= "animalia:die" then
self:initiate_utility("animalia:die", self)
end
end,
2020-11-11 23:16:50 -08:00
on_rightclick = function(self, clicker)
2022-02-10 18:00:06 -08:00
if animalia.feed(self, clicker, false, true) then
return
end
if animalia.set_nametag(self, clicker) then
return
end
2022-02-10 18:00:06 -08:00
local tool = clicker:get_wielded_item()
local tool_name = tool:get_name()
if tool_name == "animalia:shears"
2022-08-12 22:17:42 -07:00
and not self.collected
2022-02-10 18:00:06 -08:00
and self.growth_scale > 0.9 then
2020-11-11 23:16:50 -08:00
if not minetest.get_modpath("wool") then
return
end
2022-02-10 18:00:06 -08:00
minetest.add_item(
2020-11-11 23:16:50 -08:00
self.object:get_pos(),
ItemStack( "wool:" .. self.dye_color .. " " .. math.random(1, 3) )
)
2022-08-12 22:17:42 -07:00
self.collected = self:memorize("collected", true)
2022-02-10 18:00:06 -08:00
self.dye_color = self:memorize("dye_color", "white")
self.dye_hex = self:memorize("dye_hex", "#abababc000")
2020-11-11 23:16:50 -08:00
2022-02-10 18:00:06 -08:00
tool:add_wear(650) -- 100 uses
2020-11-11 23:16:50 -08:00
2022-02-10 18:00:06 -08:00
clicker:set_wielded_item(tool)
2020-11-11 23:16:50 -08:00
self.object:set_properties({
textures = {"animalia_sheep.png"},
2020-11-11 23:16:50 -08:00
})
end
for _, color in ipairs(palette) do
2022-02-10 18:00:06 -08:00
if tool_name:find("dye:")
2022-08-12 22:17:42 -07:00
and not self.collected
2022-02-10 18:00:06 -08:00
and self.growth_scale > 0.9 then
2022-08-12 22:17:42 -07:00
local dye = tool_name:split(":")[2]
2020-11-11 23:16:50 -08:00
if color[1] == dye then
2022-02-10 18:00:06 -08:00
self.dye_color = self:memorize("dye_color", color[1])
self.dye_hex = self:memorize("dye_hex", color[3])
2020-11-11 23:16:50 -08:00
self.drops = {
{name = "animalia:mutton_raw", chance = 1, min = 1, max = 4},
2020-11-11 23:16:50 -08:00
{name = "wool:"..self.dye_color, chance = 2, min = 1, max = 2},
}
self.object:set_properties({
textures = {"animalia_sheep.png^(animalia_sheep_wool.png^[colorize:" .. color[3] .. ")"},
2020-11-11 23:16:50 -08:00
})
if not creative then
2022-02-10 18:00:06 -08:00
tool:take_item()
clicker:set_wielded_item(tool)
2020-11-11 23:16:50 -08:00
end
break
end
end
end
end,
2022-10-17 17:23:26 -07:00
on_punch = animalia.punch
2020-11-11 23:16:50 -08:00
})
2022-08-12 22:17:42 -07:00
creatura.register_spawn_egg("animalia:sheep", "f4e6cf", "e1ca9b")