1
0
Fork 0
MineClone2/mods/ENTITIES/mobs_mc/sheep.lua

336 lines
8.8 KiB
Lua
Raw Normal View History

2017-07-05 01:15:46 +00:00
--License for code WTFPL and otherwise stated in readmes
local S = minetest.get_translator("mobs_mc")
2017-07-05 01:15:46 +00:00
--###################
--################### SHEEP
--###################
local colors = {
-- group = { wool, textures }
unicolor_white = { mobs_mc.items.wool_white, "#FFFFFF00" },
unicolor_dark_orange = { mobs_mc.items.wool_brown, "#502A00D0" },
unicolor_grey = { mobs_mc.items.wool_light_grey, "#5B5B5BD0" },
unicolor_darkgrey = { mobs_mc.items.wool_grey, "#303030D0" },
unicolor_blue = { mobs_mc.items.wool_blue, "#0000CCD0" },
unicolor_dark_green = { mobs_mc.items.wool_green, "#005000D0" },
unicolor_green = { mobs_mc.items.wool_lime, "#50CC00D0" },
unicolor_violet = { mobs_mc.items.wool_purple , "#5000CCD0" },
unicolor_light_red = { mobs_mc.items.wool_pink, "#FF5050D0" },
unicolor_yellow = { mobs_mc.items.wool_yellow, "#CCCC00D0" },
unicolor_orange = { mobs_mc.items.wool_orange, "#CC5000D0" },
unicolor_red = { mobs_mc.items.wool_red, "#CC0000D0" },
unicolor_cyan = { mobs_mc.items.wool_cyan, "#00CCCCD0" },
unicolor_red_violet = { mobs_mc.items.wool_magenta, "#CC0050D0" },
unicolor_black = { mobs_mc.items.wool_black, "#000000D0" },
}
2021-03-25 08:24:38 +00: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 01:15:46 +00:00
if minetest.get_modpath("mcl_wool") ~= nil then
colors["unicolor_light_blue"] = { mobs_mc.items.wool_light_blue, "#5050FFD0" }
end
local sheep_texture = function(color_group)
if not color_group then
color_group = "unicolor_white"
end
2018-05-30 16:05:49 +00:00
return {
"mobs_mc_sheep_fur.png^[colorize:"..colors[color_group][2],
"mobs_mc_sheep.png",
}
2017-07-05 01:15:46 +00:00
end
2018-05-30 16:05:49 +00:00
local gotten_texture = { "blank.png", "mobs_mc_sheep.png" }
2017-07-05 01:15:46 +00:00
--mcsheep
mobs:register_mob("mobs_mc:sheep", {
type = "animal",
2020-04-11 00:46:03 +00:00
spawn_class = "passive",
2017-07-05 01:15:46 +00:00
hp_min = 8,
hp_max = 8,
2020-12-06 14:46:42 +00:00
xp_min = 1,
xp_max = 3,
2017-07-05 01:15:46 +00:00
collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
2021-04-22 03:25:10 +00:00
rotate = 270,
2017-07-05 01:15:46 +00:00
visual = "mesh",
visual_size = {x=3, y=3},
mesh = "mobs_mc_sheepfur.b3d",
textures = { sheep_texture("unicolor_white") },
2018-05-30 16:05:49 +00:00
gotten_texture = gotten_texture,
2017-07-05 01:15:46 +00:00
color = "unicolor_white",
makes_footstep_sound = true,
walk_velocity = 1,
drops = {
{name = mobs_mc.items.mutton_raw,
chance = 1,
min = 1,
2020-12-23 16:41:42 +00:00
max = 2,
looting = "common",},
2017-07-05 01:15:46 +00:00
{name = colors["unicolor_white"][1],
chance = 1,
min = 1,
2020-12-23 16:41:42 +00:00
max = 1,
looting = "common",},
2017-07-05 01:15:46 +00:00
},
fear_height = 4,
sounds = {
random = "mobs_sheep",
death = "mobs_sheep",
damage = "mobs_sheep",
2020-12-05 22:37:12 +00:00
sounds = "mobs_mc_animal_eat_generic",
2017-07-05 01:15:46 +00:00
distance = 16,
},
animation = {
speed_normal = 25, run_speed = 65,
stand_start = 40, stand_end = 80,
2017-07-05 01:15:46 +00:00
walk_start = 0, walk_end = 40,
run_start = 0, run_end = 40,
},
follow = mobs_mc.follow.sheep,
view_range = 12,
-- Eat grass
replace_rate = 20,
replace_what = mobs_mc.replace.sheep,
-- Properly regrow wool after eating grass
on_replace = function(self, pos, oldnode, newnode)
2017-07-07 12:40:38 +00:00
if not self.color or not colors[self.color] then
self.color = "unicolor_white"
end
2017-07-12 20:09:37 +00:00
self.gotten = false
2018-05-31 01:43:48 +00:00
self.base_texture = sheep_texture(self.color)
self.object:set_properties({ textures = self.base_texture })
2017-07-05 01:15:46 +00:00
self.drops = {
2018-05-30 16:05:49 +00:00
{name = mobs_mc.items.mutton_raw,
chance = 1,
min = 1,
max = 2,},
{name = colors[self.color][1],
chance = 1,
min = 1,
max = 1,},
2017-07-05 01:15:46 +00:00
}
end,
-- Set random color on spawn
2021-03-25 08:24:38 +00:00
do_custom = function(self, dtime)
2017-07-05 01:15:46 +00:00
if not self.initial_color_set then
local r = math.random(0,100000)
local textures
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 = {
{name = mobs_mc.items.mutton_raw,
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 08:24:38 +00:00
local is_kay27 = self.nametag == "kay27"
2021-03-25 08:24:38 +00:00
if self.color_change_timer then
local old_color = self.color
if is_kay27 then
2021-03-25 08:24:38 +00: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
elseif is_kay27 then
2021-03-25 08:24:38 +00:00
self.initial_color = self.color
self.color_change_timer = 0
self.color_index = -1
end
2017-07-05 01:15:46 +00:00
end,
2021-03-25 08:24:38 +00:00
2017-07-05 01:15:46 +00:00
on_rightclick = function(self, clicker)
local item = clicker:get_wielded_item()
if mobs:feed_tame(self, clicker, 1, true, true) then return end
2018-05-31 01:45:38 +00:00
if item:get_name() == mobs_mc.items.shears and not self.gotten and not self.child then
2017-07-05 01:15:46 +00:00
self.gotten = true
2019-02-01 05:33:07 +00:00
local pos = self.object:get_pos()
2020-12-06 00:21:02 +00:00
minetest.sound_play("mcl_tools_shears_cut", {pos = pos}, true)
2017-07-05 01:15:46 +00: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 16:05:49 +00:00
self.base_texture = gotten_texture
2017-07-05 01:15:46 +00:00
self.object:set_properties({
2018-05-30 16:05:49 +00:00
textures = self.base_texture,
2017-07-05 01:15:46 +00:00
})
2020-07-10 14:08:40 +00:00
if not minetest.is_creative_enabled(clicker:get_player_name()) then
2017-07-05 01:15:46 +00:00
item:add_wear(mobs_mc.misc.shears_wear)
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
end
self.drops = {
{name = mobs_mc.items.mutton_raw,
chance = 1,
min = 1,
max = 2,},
}
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 14:08:40 +00:00
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end
2017-07-05 01:15:46 +00:00
self.base_texture = sheep_texture(group)
self.object:set_properties({
textures = self.base_texture,
})
self.color = group
self.drops = {
{name = mobs_mc.items.mutton_raw,
chance = 1,
min = 1,
max = 2,},
{name = colordata[1],
chance = 1,
min = 1,
max = 1,},
}
break
end
end
return
end
end,
2018-05-31 02:38:37 +00:00
on_breed = function(parent1, parent2)
-- Breed sheep and choose a fur color for the child.
2018-05-31 02:38:37 +00:00
local pos = parent1.object:get_pos()
local child = mobs:spawn_child(pos, parent1.name)
if child then
local ent_c = child:get_luaentity()
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
ent_c.color = k
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)
if p == 1 and color1 then
ent_c.color = color1
else
ent_c.color = color2
end
ent_c.base_texture = sheep_texture(ent_c.color)
2018-05-31 02:38:37 +00:00
end
child:set_properties({textures = ent_c.base_texture})
ent_c.initial_color_set = true
ent_c.tamed = true
ent_c.owner = parent1.owner
2018-05-31 02:38:37 +00:00
return false
end
end,
2017-07-05 01:15:46 +00:00
})
2021-04-08 11:39:18 +00:00
mobs:spawn_specific(
"mobs_mc:sheep",
"overworld",
"ground",
{
"FlowerForest",
"Swampland",
"Taiga",
"ExtremeHills",
"BirchForest",
"MegaSpruceTaiga",
"MegaTaiga",
"ExtremeHills+",
"Forest",
"Plains",
"ColdTaiga",
"SunflowerPlains",
"RoofedForest",
"MesaPlateauFM_grasstop",
"ExtremeHillsM",
"BirchForestM",
},
0,
minetest.LIGHT_MAX+1,
30,
15000,
3,
mobs_mc.spawn_height.overworld_min,
mobs_mc.spawn_height.overworld_max)
2017-07-05 01:15:46 +00:00
-- spawn eggs
mobs:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0)