animalia/mobs/sheep.lua

230 lines
5.3 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
2020-11-11 23:16:50 -08:00
local palette = {
2023-03-15 14:27:40 -07:00
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"},
2020-11-11 23:16:50 -08:00
}
2022-02-10 18:00:06 -08:00
creatura.register_mob("animalia:sheep", {
2023-03-15 14:27:40 -07:00
-- Engine Props
2020-11-11 23:16:50 -08:00
visual_size = {x = 10, y = 10},
2023-03-15 14:27:40 -07:00
mesh = "animalia_sheep.b3d",
2022-02-10 18:00:06 -08:00
textures = {
"animalia_sheep.png^animalia_sheep_wool.png"
},
child_textures = {
"animalia_sheep.png"
},
makes_footstep_sound = true,
2023-03-15 14:27:40 -07:00
-- Creatura Props
max_health = 15,
armor_groups = {fleshy = 100},
damage = 0,
speed = 3,
tracking_range = 12,
max_boids = 4,
despawn_after = 500,
stepheight = 1.1,
2022-02-10 18:00:06 -08:00
sounds = {
random = {
2023-03-15 14:27:40 -07:00
name = "animalia_sheep",
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
}
},
2023-03-15 14:27:40 -07:00
hitbox = {
width = 0.4,
height = 0.8
},
animations = {
stand = {range = {x = 1, y = 59}, speed = 10, frame_blend = 0.3, loop = true},
walk = {range = {x = 70, y = 89}, speed = 30, frame_blend = 0.3, loop = true},
run = {range = {x = 100, y = 119}, speed = 40, frame_blend = 0.3, loop = true},
eat = {range = {x = 130, y = 150}, speed = 20, frame_blend = 0.3, loop = false}
},
follow = animalia.food_wheat,
drops = {
{name = "animalia:mutton_raw", min = 1, max = 3, chance = 1},
2023-03-15 14:27:40 -07:00
minetest.get_modpath("wool") and {name = "wool:white", min = 1, max = 3, chance = 2} or nil
},
2023-03-15 14:27:40 -07:00
-- Animalia Props
group_wander = true,
flee_puncher = true,
catch_with_net = true,
catch_with_lasso = true,
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
},
2023-03-15 14:27:40 -07:00
-- Functions
2022-02-10 18:00:06 -08:00
utility_stack = {
2022-08-12 22:17:42 -07:00
{
2023-03-15 14:27:40 -07:00
utility = "animalia:wander",
2022-08-12 22:17:42 -07:00
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
},
2023-03-15 14:27:40 -07:00
activate_func = function(self)
2023-03-15 14:27:40 -07:00
animalia.initialize_api(self)
animalia.initialize_lasso(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"
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
})
2023-03-15 14:27:40 -07:00
elseif self.dye_color ~= "white" then
self.object:set_properties({
textures = {"animalia_sheep.png^(animalia_sheep_wool.png^[multiply:" .. palette[self.dye_color][2] .. ")"},
})
2020-11-11 23:16:50 -08:00
end
end,
2023-03-15 14:27:40 -07:00
step_func = function(self)
2022-02-10 18:00:06 -08:00
animalia.step_timers(self)
2023-03-15 14:27:40 -07:00
animalia.head_tracking(self)
2022-02-10 18:00:06 -08:00
animalia.do_growth(self, 60)
animalia.update_lasso_effects(self)
animalia.random_sound(self)
end,
2023-03-15 14:27:40 -07:00
death_func = animalia.death_func,
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
2023-03-15 14:27:40 -07:00
if self.collected
or self.growth_scale < 1 then
return
end
2022-02-10 18:00:06 -08:00
local tool = clicker:get_wielded_item()
local tool_name = tool:get_name()
2023-03-15 14:27:40 -07:00
local creative = minetest.is_creative_enabled(clicker)
if tool_name == "animalia:shears" 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(),
2023-03-15 14:27:40 -07:00
ItemStack("wool:" .. self.dye_color .. " " .. random(1, 3))
2020-11-11 23:16:50 -08:00
)
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")
2020-11-11 23:16:50 -08:00
self.object:set_properties({
textures = {"animalia_sheep.png"},
2020-11-11 23:16:50 -08:00
})
2023-03-15 14:27:40 -07:00
if not creative then
tool:add_wear(650)
clicker:set_wielded_item(tool)
end
2020-11-11 23:16:50 -08:00
end
2023-03-15 14:27:40 -07:00
if tool_name:match("^dye:") then
local dye_color = tool_name:split(":")[2]
if palette[dye_color] then
self.dye_color = self:memorize("dye_color", dye_color)
self.drops = {
{name = "animalia:mutton_raw", chance = 1, min = 1, max = 4},
{name = "wool:" .. dye_color, chance = 2, min = 1, max = 2},
}
self.object:set_properties({
textures = {"animalia_sheep.png^(animalia_sheep_wool.png^[multiply:" .. palette[dye_color][2] .. ")"},
})
if not creative then
tool:take_item()
clicker:set_wielded_item(tool)
2020-11-11 23:16:50 -08:00
end
end
end
end,
2023-03-15 14:27:40 -07:00
2022-10-17 17:23:26 -07:00
on_punch = animalia.punch
2020-11-11 23:16:50 -08:00
})
2023-03-15 14:27:40 -07:00
creatura.register_spawn_item("animalia:sheep", {
col1 = "f4e6cf",
col2 = "e1ca9b"
})