2017-07-05 03:15:46 +02:00
|
|
|
--License for code WTFPL and otherwise stated in readmes
|
|
|
|
|
2022-02-13 21:40:12 +01:00
|
|
|
local S = minetest.get_translator("mobs_mc")
|
2017-07-05 03:15:46 +02:00
|
|
|
|
|
|
|
--###################
|
|
|
|
--################### SHEEP
|
|
|
|
--###################
|
|
|
|
|
2023-06-19 18:49:20 +02:00
|
|
|
local WOOL_REPLACE_RATE = 80
|
|
|
|
|
2017-07-05 03:15:46 +02:00
|
|
|
local colors = {
|
|
|
|
-- group = { wool, textures }
|
2022-05-25 23:25:15 +02:00
|
|
|
unicolor_white = { "mcl_wool:white", "#FFFFFF00" },
|
|
|
|
unicolor_dark_orange = { "mcl_wool:brown", "#502A00D0" },
|
|
|
|
unicolor_grey = { "mcl_wool:silver", "#5B5B5BD0" },
|
|
|
|
unicolor_darkgrey = { "mcl_wool:grey", "#303030D0" },
|
|
|
|
unicolor_blue = { "mcl_wool:blue", "#0000CCD0" },
|
|
|
|
unicolor_dark_green = { "mcl_wool:green", "#005000D0" },
|
|
|
|
unicolor_green = { "mcl_wool:lime", "#50CC00D0" },
|
|
|
|
unicolor_violet = { "mcl_wool:purple" , "#5000CCD0" },
|
|
|
|
unicolor_light_red = { "mcl_wool:pink", "#FF5050D0" },
|
|
|
|
unicolor_yellow = { "mcl_wool:yellow", "#CCCC00D0" },
|
|
|
|
unicolor_orange = { "mcl_wool:orange", "#CC5000D0" },
|
|
|
|
unicolor_red = { "mcl_wool:red", "#CC0000D0" },
|
|
|
|
unicolor_cyan = { "mcl_wool:cyan", "#00CCCCD0" },
|
|
|
|
unicolor_red_violet = { "mcl_wool:magenta", "#CC0050D0" },
|
|
|
|
unicolor_black = { "mcl_wool:black", "#000000D0" },
|
|
|
|
unicolor_light_blue = { "mcl_wool:light_blue", "#5050FFD0" },
|
2017-07-05 03:15:46 +02:00
|
|
|
}
|
|
|
|
|
2021-03-25 09:24:38 +01:00
|
|
|
local rainbow_colors = {
|
|
|
|
"unicolor_light_red",
|
|
|
|
"unicolor_red",
|
|
|
|
"unicolor_orange",
|
|
|
|
"unicolor_yellow",
|
|
|
|
"unicolor_green",
|
|
|
|
"unicolor_dark_green",
|
|
|
|
"unicolor_light_blue",
|
|
|
|
"unicolor_blue",
|
|
|
|
"unicolor_violet",
|
|
|
|
"unicolor_red_violet"
|
|
|
|
}
|
|
|
|
|
2017-07-05 03:15:46 +02:00
|
|
|
local sheep_texture = function(color_group)
|
2019-03-15 00:26:06 +01:00
|
|
|
if not color_group then
|
|
|
|
color_group = "unicolor_white"
|
|
|
|
end
|
2018-05-30 18:05:49 +02:00
|
|
|
return {
|
|
|
|
"mobs_mc_sheep_fur.png^[colorize:"..colors[color_group][2],
|
|
|
|
"mobs_mc_sheep.png",
|
|
|
|
}
|
2017-07-05 03:15:46 +02:00
|
|
|
end
|
|
|
|
|
2018-05-30 18:05:49 +02:00
|
|
|
local gotten_texture = { "blank.png", "mobs_mc_sheep.png" }
|
|
|
|
|
2017-07-05 03:15:46 +02:00
|
|
|
--mcsheep
|
2022-11-09 04:09:58 +01:00
|
|
|
mcl_mobs.register_mob("mobs_mc:sheep", {
|
2021-04-25 17:30:15 +02:00
|
|
|
description = S("Sheep"),
|
2017-07-05 03:15:46 +02:00
|
|
|
type = "animal",
|
2020-04-11 02:46:03 +02:00
|
|
|
spawn_class = "passive",
|
2023-01-04 22:11:55 +01:00
|
|
|
passive = true,
|
2017-07-05 03:15:46 +02:00
|
|
|
hp_min = 8,
|
|
|
|
hp_max = 8,
|
2020-12-06 15:46:42 +01:00
|
|
|
xp_min = 1,
|
|
|
|
xp_max = 3,
|
2017-07-05 03:15:46 +02:00
|
|
|
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
|
2022-10-06 22:53:40 +02:00
|
|
|
head_swivel = "head.control",
|
2024-11-11 17:29:07 +01:00
|
|
|
head_eye_height = 1.0,
|
2024-11-19 21:48:21 +01:00
|
|
|
head_bone_position = vector.new( 0, 3.7, -.9 ), -- for minetest <= 5.8
|
2022-10-06 03:30:02 +02:00
|
|
|
curiosity = 6,
|
|
|
|
head_yaw="z",
|
2017-07-05 03:15:46 +02:00
|
|
|
visual = "mesh",
|
|
|
|
mesh = "mobs_mc_sheepfur.b3d",
|
|
|
|
textures = { sheep_texture("unicolor_white") },
|
2018-05-30 18:05:49 +02:00
|
|
|
gotten_texture = gotten_texture,
|
2017-07-05 03:15:46 +02:00
|
|
|
color = "unicolor_white",
|
|
|
|
makes_footstep_sound = true,
|
|
|
|
walk_velocity = 1,
|
2022-07-19 05:20:17 +02:00
|
|
|
runaway = true,
|
|
|
|
runaway_from = {"mobs_mc:wolf"},
|
2017-07-05 03:15:46 +02:00
|
|
|
drops = {
|
2022-05-25 23:25:15 +02:00
|
|
|
{name = "mcl_mobitems:mutton",
|
2017-07-05 03:15:46 +02:00
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
2020-12-23 17:41:42 +01:00
|
|
|
max = 2,
|
|
|
|
looting = "common",},
|
2017-07-05 03:15:46 +02:00
|
|
|
{name = colors["unicolor_white"][1],
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
2020-12-23 17:41:42 +01:00
|
|
|
max = 1,
|
|
|
|
looting = "common",},
|
2017-07-05 03:15:46 +02:00
|
|
|
},
|
|
|
|
fear_height = 4,
|
|
|
|
sounds = {
|
|
|
|
random = "mobs_sheep",
|
|
|
|
death = "mobs_sheep",
|
|
|
|
damage = "mobs_sheep",
|
2020-12-05 23:37:12 +01:00
|
|
|
sounds = "mobs_mc_animal_eat_generic",
|
2017-07-05 03:15:46 +02:00
|
|
|
distance = 16,
|
|
|
|
},
|
|
|
|
animation = {
|
2022-09-28 21:16:01 +02:00
|
|
|
stand_start = 0, stand_end = 0,
|
|
|
|
walk_start = 0, walk_end = 40, walk_speed = 30,
|
|
|
|
run_start = 0, run_end = 40, run_speed = 40,
|
2023-05-30 21:03:13 +02:00
|
|
|
eat_start = 40, eat_end = 80, eat_loop = false,
|
2022-09-28 21:16:01 +02:00
|
|
|
},
|
|
|
|
child_animations = {
|
|
|
|
stand_start = 81, stand_end = 81,
|
|
|
|
walk_start = 81, walk_end = 121, walk_speed = 45,
|
|
|
|
run_start = 81, run_end = 121, run_speed = 60,
|
2023-05-30 21:03:13 +02:00
|
|
|
eat_start = 121, eat_start = 161, eat_loop = false,
|
2017-07-05 03:15:46 +02:00
|
|
|
},
|
2023-12-24 05:48:41 +01:00
|
|
|
follow = { "mcl_farming:wheat_item", "mcl_shepherd:shepherd_staff" },
|
2017-07-05 03:15:46 +02:00
|
|
|
view_range = 12,
|
|
|
|
|
|
|
|
-- Eat grass
|
2023-06-19 18:49:20 +02:00
|
|
|
replace_rate = WOOL_REPLACE_RATE,
|
2023-06-04 22:20:29 +02:00
|
|
|
replace_delay = 1.3,
|
2022-05-25 23:25:15 +02:00
|
|
|
replace_what = {
|
|
|
|
{ "mcl_core:dirt_with_grass", "mcl_core:dirt", -1 },
|
|
|
|
{ "mcl_flowers:tallgrass", "air", 0 },
|
|
|
|
},
|
2017-07-05 03:15:46 +02:00
|
|
|
-- Properly regrow wool after eating grass
|
|
|
|
on_replace = function(self, pos, oldnode, newnode)
|
2023-06-19 18:49:20 +02:00
|
|
|
if not self.color or not colors[self.color] then
|
|
|
|
self.color = "unicolor_white"
|
|
|
|
end
|
|
|
|
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,},
|
|
|
|
}
|
|
|
|
|
2023-06-04 22:20:29 +02:00
|
|
|
self.state = "eat"
|
|
|
|
self:set_animation("eat")
|
|
|
|
self:set_velocity(0)
|
2023-06-19 18:49:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2023-06-04 22:20:29 +02:00
|
|
|
minetest.after(self.replace_delay, function()
|
2023-06-05 01:24:37 +02:00
|
|
|
if self and self.object and self.object:get_velocity() and self.health > 0 then
|
2023-06-05 16:03:45 +02:00
|
|
|
self.object:set_velocity(vector.zero())
|
2023-06-04 22:20:29 +02:00
|
|
|
self.gotten = false
|
|
|
|
self.object:set_properties({ textures = self.base_texture })
|
|
|
|
end
|
|
|
|
end)
|
2023-06-19 18:49:20 +02:00
|
|
|
|
2023-06-04 22:20:29 +02:00
|
|
|
minetest.after(2.5, function()
|
2023-06-19 18:49:20 +02:00
|
|
|
if self and self.object and self.state == 'eat' and self.health > 0 then
|
2023-06-04 22:20:29 +02:00
|
|
|
self.state = "walk"
|
|
|
|
end
|
|
|
|
end)
|
2023-06-19 18:49:20 +02:00
|
|
|
|
2017-07-05 03:15:46 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
-- Set random color on spawn
|
2021-03-25 09:24:38 +01:00
|
|
|
do_custom = function(self, dtime)
|
2017-07-05 03:15:46 +02:00
|
|
|
if not self.initial_color_set then
|
|
|
|
local r = math.random(0,100000)
|
2022-02-13 21:40:12 +01:00
|
|
|
local textures
|
2017-07-05 03:15:46 +02:00
|
|
|
if r <= 81836 then
|
|
|
|
-- 81.836%
|
|
|
|
self.color = "unicolor_white"
|
|
|
|
elseif r <= 81836 + 5000 then
|
|
|
|
-- 5%
|
|
|
|
self.color = "unicolor_grey"
|
|
|
|
elseif r <= 81836 + 5000 + 5000 then
|
|
|
|
-- 5%
|
|
|
|
self.color = "unicolor_darkgrey"
|
|
|
|
elseif r <= 81836 + 5000 + 5000 + 5000 then
|
|
|
|
-- 5%
|
|
|
|
self.color = "unicolor_black"
|
|
|
|
elseif r <= 81836 + 5000 + 5000 + 5000 + 3000 then
|
|
|
|
-- 3%
|
|
|
|
self.color = "unicolor_dark_orange"
|
|
|
|
else
|
|
|
|
-- 0.164%
|
|
|
|
self.color = "unicolor_light_red"
|
|
|
|
end
|
|
|
|
self.base_texture = sheep_texture(self.color)
|
|
|
|
self.object:set_properties({ textures = self.base_texture })
|
|
|
|
self.drops = {
|
2022-05-25 23:25:15 +02:00
|
|
|
{name = "mcl_mobitems:mutton",
|
2017-07-05 03:15:46 +02:00
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 2,},
|
|
|
|
{name = colors[self.color][1],
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,},
|
|
|
|
}
|
|
|
|
self.initial_color_set = true
|
|
|
|
end
|
2021-03-25 09:24:38 +01:00
|
|
|
|
2021-03-25 17:34:03 +01:00
|
|
|
local is_kay27 = self.nametag == "kay27"
|
2021-03-25 09:24:38 +01:00
|
|
|
|
|
|
|
if self.color_change_timer then
|
|
|
|
local old_color = self.color
|
2021-03-25 17:34:03 +01:00
|
|
|
if is_kay27 then
|
2021-03-25 09:24:38 +01:00
|
|
|
self.color_change_timer = self.color_change_timer - dtime
|
|
|
|
if self.color_change_timer < 0 then
|
|
|
|
self.color_change_timer = 0.5
|
|
|
|
self.color_index = (self.color_index + 1) % #rainbow_colors
|
|
|
|
self.color = rainbow_colors[self.color_index + 1]
|
|
|
|
end
|
|
|
|
else
|
|
|
|
self.color_change_timer = nil
|
|
|
|
self.color_index = nil
|
|
|
|
self.color = self.initial_color
|
|
|
|
end
|
|
|
|
|
|
|
|
if old_color ~= self.color then
|
|
|
|
self.base_texture = sheep_texture(self.color)
|
|
|
|
self.object:set_properties({textures = self.base_texture})
|
|
|
|
end
|
2021-03-25 17:34:03 +01:00
|
|
|
elseif is_kay27 then
|
2021-03-25 09:24:38 +01:00
|
|
|
self.initial_color = self.color
|
|
|
|
self.color_change_timer = 0
|
|
|
|
self.color_index = -1
|
|
|
|
end
|
2017-07-05 03:15:46 +02:00
|
|
|
end,
|
2021-03-25 09:24:38 +01:00
|
|
|
|
2017-07-05 03:15:46 +02:00
|
|
|
on_rightclick = function(self, clicker)
|
|
|
|
local item = clicker:get_wielded_item()
|
|
|
|
|
2022-11-09 04:57:48 +01:00
|
|
|
if self:feed_tame(clicker, 1, true, false) then return end
|
2022-05-25 14:44:49 +02:00
|
|
|
if mcl_mobs:protect(self, clicker) then return end
|
2017-07-05 03:15:46 +02:00
|
|
|
|
2023-08-13 06:02:15 +02:00
|
|
|
if minetest.get_item_group(item:get_name(), "shears") > 0 and not self.gotten and not self.child then
|
2017-07-05 03:15:46 +02:00
|
|
|
self.gotten = true
|
2019-02-01 06:33:07 +01:00
|
|
|
local pos = self.object:get_pos()
|
2020-12-06 01:21:02 +01:00
|
|
|
minetest.sound_play("mcl_tools_shears_cut", {pos = pos}, true)
|
2017-07-05 03:15:46 +02:00
|
|
|
pos.y = pos.y + 0.5
|
|
|
|
if not self.color then
|
|
|
|
self.color = "unicolor_white"
|
|
|
|
end
|
|
|
|
minetest.add_item(pos, ItemStack(colors[self.color][1].." "..math.random(1,3)))
|
2018-05-30 18:05:49 +02:00
|
|
|
self.base_texture = gotten_texture
|
2017-07-05 03:15:46 +02:00
|
|
|
self.object:set_properties({
|
2018-05-30 18:05:49 +02:00
|
|
|
textures = self.base_texture,
|
2017-07-05 03:15:46 +02:00
|
|
|
})
|
2020-07-10 16:08:40 +02:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2022-05-25 23:25:15 +02:00
|
|
|
item:add_wear(mobs_mc.shears_wear)
|
2024-05-22 20:55:07 +02:00
|
|
|
tt.reload_itemstack_description(item) -- update tooltip
|
2017-07-05 03:15:46 +02:00
|
|
|
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
-- Dye sheep
|
|
|
|
if minetest.get_item_group(item:get_name(), "dye") == 1 and not self.gotten then
|
|
|
|
minetest.log("verbose", "[mobs_mc] " ..item:get_name() .. " " .. minetest.get_item_group(item:get_name(), "dye"))
|
|
|
|
for group, colordata in pairs(colors) do
|
|
|
|
if minetest.get_item_group(item:get_name(), group) == 1 then
|
2020-07-10 16:08:40 +02:00
|
|
|
if not minetest.is_creative_enabled(clicker:get_player_name()) then
|
2019-07-31 18:14:11 +02:00
|
|
|
item:take_item()
|
|
|
|
clicker:set_wielded_item(item)
|
|
|
|
end
|
2017-07-05 03:15:46 +02:00
|
|
|
self.base_texture = sheep_texture(group)
|
|
|
|
self.object:set_properties({
|
|
|
|
textures = self.base_texture,
|
|
|
|
})
|
|
|
|
self.color = group
|
|
|
|
self.drops = {
|
2022-05-25 23:25:15 +02:00
|
|
|
{name = "mcl_mobitems:mutton",
|
2017-07-05 03:15:46 +02:00
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 2,},
|
|
|
|
{name = colordata[1],
|
|
|
|
chance = 1,
|
|
|
|
min = 1,
|
|
|
|
max = 1,},
|
|
|
|
}
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
2022-05-25 14:44:49 +02:00
|
|
|
if mcl_mobs:capture_mob(self, clicker, 0, 5, 70, false, nil) then return end
|
2017-07-05 03:15:46 +02:00
|
|
|
end,
|
2018-05-31 04:38:37 +02:00
|
|
|
on_breed = function(parent1, parent2)
|
2018-05-31 05:45:57 +02:00
|
|
|
-- Breed sheep and choose a fur color for the child.
|
2018-05-31 04:38:37 +02:00
|
|
|
local pos = parent1.object:get_pos()
|
2022-11-27 21:14:19 +01:00
|
|
|
local child = mcl_mobs.spawn_child(pos, parent1.name)
|
2018-05-31 04:38:37 +02:00
|
|
|
if child then
|
|
|
|
local ent_c = child:get_luaentity()
|
2018-05-31 05:45:57 +02:00
|
|
|
local color1 = parent1.color
|
|
|
|
local color2 = parent2.color
|
|
|
|
|
|
|
|
local dye1 = mcl_dye.unicolor_to_dye(color1)
|
|
|
|
local dye2 = mcl_dye.unicolor_to_dye(color2)
|
|
|
|
local output
|
|
|
|
-- Check if parent colors could be mixed as dyes
|
|
|
|
if dye1 and dye2 then
|
|
|
|
output = minetest.get_craft_result({items = {dye1, dye2}, method="normal"})
|
|
|
|
end
|
|
|
|
local mixed = false
|
|
|
|
if output and not output.item:is_empty() then
|
|
|
|
-- Try to mix dyes and use that as new fur color
|
|
|
|
local new_dye = output.item:get_name()
|
|
|
|
local groups = minetest.registered_items[new_dye].groups
|
|
|
|
for k, v in pairs(groups) do
|
|
|
|
if string.sub(k, 1, 9) == "unicolor_" then
|
2019-03-15 00:26:06 +01:00
|
|
|
ent_c.color = k
|
2018-05-31 05:45:57 +02:00
|
|
|
ent_c.base_texture = sheep_texture(k)
|
|
|
|
mixed = true
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Colors not mixable
|
|
|
|
if not mixed then
|
|
|
|
-- Choose color randomly from one of the parents
|
|
|
|
local p = math.random(1, 2)
|
2019-03-15 00:26:06 +01:00
|
|
|
if p == 1 and color1 then
|
|
|
|
ent_c.color = color1
|
2018-05-31 05:45:57 +02:00
|
|
|
else
|
2019-03-15 00:26:06 +01:00
|
|
|
ent_c.color = color2
|
2018-05-31 05:45:57 +02:00
|
|
|
end
|
2019-03-15 00:26:06 +01:00
|
|
|
ent_c.base_texture = sheep_texture(ent_c.color)
|
2018-05-31 04:38:37 +02:00
|
|
|
end
|
|
|
|
child:set_properties({textures = ent_c.base_texture})
|
|
|
|
ent_c.initial_color_set = true
|
2018-05-31 17:32:13 +02:00
|
|
|
ent_c.tamed = true
|
|
|
|
ent_c.owner = parent1.owner
|
2018-05-31 04:38:37 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end,
|
2017-07-05 03:15:46 +02:00
|
|
|
})
|
2022-05-25 14:44:49 +02:00
|
|
|
mcl_mobs:spawn_specific(
|
2021-04-08 13:39:18 +02:00
|
|
|
"mobs_mc:sheep",
|
|
|
|
"overworld",
|
|
|
|
"ground",
|
|
|
|
{
|
2022-03-22 15:16:48 +01:00
|
|
|
"flat",
|
|
|
|
"IcePlainsSpikes",
|
|
|
|
"ColdTaiga",
|
|
|
|
"ColdTaiga_beach",
|
|
|
|
"ColdTaiga_beach_water",
|
|
|
|
"MegaTaiga",
|
|
|
|
"MegaSpruceTaiga",
|
|
|
|
"ExtremeHills",
|
|
|
|
"ExtremeHills_beach",
|
|
|
|
"ExtremeHillsM",
|
|
|
|
"ExtremeHills+",
|
|
|
|
"ExtremeHills+_snowtop",
|
|
|
|
"StoneBeach",
|
|
|
|
"Plains",
|
|
|
|
"Plains_beach",
|
|
|
|
"SunflowerPlains",
|
|
|
|
"Taiga",
|
|
|
|
"Taiga_beach",
|
|
|
|
"Forest",
|
|
|
|
"Forest_beach",
|
|
|
|
"FlowerForest",
|
|
|
|
"FlowerForest_beach",
|
|
|
|
"BirchForest",
|
|
|
|
"BirchForestM",
|
|
|
|
"RoofedForest",
|
|
|
|
"Savanna",
|
|
|
|
"Savanna_beach",
|
|
|
|
"SavannaM",
|
|
|
|
"Jungle",
|
|
|
|
"Jungle_shore",
|
|
|
|
"JungleM",
|
|
|
|
"JungleM_shore",
|
|
|
|
"JungleEdge",
|
|
|
|
"JungleEdgeM",
|
|
|
|
"Swampland",
|
|
|
|
"Swampland_shore"
|
2021-04-08 13:39:18 +02:00
|
|
|
},
|
2022-07-17 15:33:06 +02:00
|
|
|
9,
|
2021-04-25 17:30:15 +02:00
|
|
|
minetest.LIGHT_MAX+1,
|
|
|
|
30,
|
2023-11-27 10:47:55 +01:00
|
|
|
120,
|
2021-04-25 17:30:15 +02:00
|
|
|
3,
|
2022-05-25 23:25:15 +02:00
|
|
|
mcl_vars.mg_overworld_min,
|
|
|
|
mcl_vars.mg_overworld_max)
|
2017-07-05 03:15:46 +02:00
|
|
|
|
|
|
|
-- spawn eggs
|
2022-11-09 04:09:58 +01:00
|
|
|
mcl_mobs.register_egg("mobs_mc:sheep", S("Sheep"), "#e7e7e7", "#ffb5b5", 0)
|