Add wool sound for beds
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / sheep.lua
blobbf321bcc71c2f014f2bdf9a991e49b2b1a836b66
1 --License for code WTFPL and otherwise stated in readmes
3 local S = minetest.get_translator("mobs_mc")
5 --###################
6 --################### SHEEP
7 --###################
9 local colors = {
10 -- group = { wool, textures }
11 unicolor_white = { mobs_mc.items.wool_white, "#FFFFFF00" },
12 unicolor_dark_orange = { mobs_mc.items.wool_brown, "#502A00D0" },
13 unicolor_grey = { mobs_mc.items.wool_light_grey, "#5B5B5BD0" },
14 unicolor_darkgrey = { mobs_mc.items.wool_grey, "#303030D0" },
15 unicolor_blue = { mobs_mc.items.wool_blue, "#0000CCD0" },
16 unicolor_dark_green = { mobs_mc.items.wool_green, "#005000D0" },
17 unicolor_green = { mobs_mc.items.wool_lime, "#50CC00D0" },
18 unicolor_violet = { mobs_mc.items.wool_purple , "#5000CCD0" },
19 unicolor_light_red = { mobs_mc.items.wool_pink, "#FF5050D0" },
20 unicolor_yellow = { mobs_mc.items.wool_yellow, "#CCCC00D0" },
21 unicolor_orange = { mobs_mc.items.wool_orange, "#CC5000D0" },
22 unicolor_red = { mobs_mc.items.wool_red, "#CC0000D0" },
23 unicolor_cyan = { mobs_mc.items.wool_cyan, "#00CCCCD0" },
24 unicolor_red_violet = { mobs_mc.items.wool_magenta, "#CC0050D0" },
25 unicolor_black = { mobs_mc.items.wool_black, "#000000D0" },
28 if minetest.get_modpath("mcl_wool") ~= nil then
29 colors["unicolor_light_blue"] = { mobs_mc.items.wool_light_blue, "#5050FFD0" }
30 end
32 local sheep_texture = function(color_group)
33 if not color_group then
34 color_group = "unicolor_white"
35 end
36 return {
37 "mobs_mc_sheep_fur.png^[colorize:"..colors[color_group][2],
38 "mobs_mc_sheep.png",
40 end
42 local gotten_texture = { "blank.png", "mobs_mc_sheep.png" }
44 --mcsheep
45 mobs:register_mob("mobs_mc:sheep", {
46 type = "animal",
47 hp_min = 8,
48 hp_max = 8,
50 collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
52 visual = "mesh",
53 visual_size = {x=3, y=3},
54 mesh = "mobs_mc_sheepfur.b3d",
55 textures = { sheep_texture("unicolor_white") },
56 gotten_texture = gotten_texture,
57 color = "unicolor_white",
58 makes_footstep_sound = true,
59 walk_velocity = 1,
60 drops = {
61 {name = mobs_mc.items.mutton_raw,
62 chance = 1,
63 min = 1,
64 max = 2,},
65 {name = colors["unicolor_white"][1],
66 chance = 1,
67 min = 1,
68 max = 1,},
70 water_damage = 1,
71 lava_damage = 4,
72 light_damage = 0,
73 fear_height = 4,
74 sounds = {
75 random = "mobs_sheep",
76 death = "mobs_sheep",
77 damage = "mobs_sheep",
78 distance = 16,
80 animation = {
81 speed_normal = 25, speed_run = 50,
82 stand_start = 40, stand_end = 80,
83 walk_start = 0, walk_end = 40,
84 run_start = 0, run_end = 40,
86 follow = mobs_mc.follow.sheep,
87 view_range = 12,
89 -- Eat grass
90 replace_rate = 20,
91 replace_what = mobs_mc.replace.sheep,
92 -- Properly regrow wool after eating grass
93 on_replace = function(self, pos, oldnode, newnode)
94 if not self.color or not colors[self.color] then
95 self.color = "unicolor_white"
96 end
97 self.gotten = false
98 self.base_texture = sheep_texture(self.color)
99 self.object:set_properties({ textures = self.base_texture })
100 self.drops = {
101 {name = mobs_mc.items.mutton_raw,
102 chance = 1,
103 min = 1,
104 max = 2,},
105 {name = colors[self.color][1],
106 chance = 1,
107 min = 1,
108 max = 1,},
110 end,
112 -- Set random color on spawn
113 do_custom = function(self)
114 if not self.initial_color_set then
115 local r = math.random(0,100000)
116 local textures
117 if r <= 81836 then
118 -- 81.836%
119 self.color = "unicolor_white"
120 elseif r <= 81836 + 5000 then
121 -- 5%
122 self.color = "unicolor_grey"
123 elseif r <= 81836 + 5000 + 5000 then
124 -- 5%
125 self.color = "unicolor_darkgrey"
126 elseif r <= 81836 + 5000 + 5000 + 5000 then
127 -- 5%
128 self.color = "unicolor_black"
129 elseif r <= 81836 + 5000 + 5000 + 5000 + 3000 then
130 -- 3%
131 self.color = "unicolor_dark_orange"
132 else
133 -- 0.164%
134 self.color = "unicolor_light_red"
136 self.base_texture = sheep_texture(self.color)
137 self.object:set_properties({ textures = self.base_texture })
138 self.drops = {
139 {name = mobs_mc.items.mutton_raw,
140 chance = 1,
141 min = 1,
142 max = 2,},
143 {name = colors[self.color][1],
144 chance = 1,
145 min = 1,
146 max = 1,},
148 self.initial_color_set = true
150 end,
152 on_rightclick = function(self, clicker)
153 local item = clicker:get_wielded_item()
155 if mobs:feed_tame(self, clicker, 1, true, true) then return end
156 if mobs:protect(self, clicker) then return end
158 if item:get_name() == mobs_mc.items.shears and not self.gotten and not self.child then
159 self.gotten = true
160 local pos = self.object:get_pos()
161 minetest.sound_play("shears", {pos = pos})
162 pos.y = pos.y + 0.5
163 if not self.color then
164 self.color = "unicolor_white"
166 minetest.add_item(pos, ItemStack(colors[self.color][1].." "..math.random(1,3)))
167 self.base_texture = gotten_texture
168 self.object:set_properties({
169 textures = self.base_texture,
171 if not minetest.settings:get_bool("creative_mode") then
172 item:add_wear(mobs_mc.misc.shears_wear)
173 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
175 self.drops = {
176 {name = mobs_mc.items.mutton_raw,
177 chance = 1,
178 min = 1,
179 max = 2,},
181 return
183 -- Dye sheep
184 if minetest.get_item_group(item:get_name(), "dye") == 1 and not self.gotten then
185 minetest.log("verbose", "[mobs_mc] " ..item:get_name() .. " " .. minetest.get_item_group(item:get_name(), "dye"))
186 for group, colordata in pairs(colors) do
187 if minetest.get_item_group(item:get_name(), group) == 1 then
188 self.base_texture = sheep_texture(group)
189 self.object:set_properties({
190 textures = self.base_texture,
192 self.color = group
193 self.drops = {
194 {name = mobs_mc.items.mutton_raw,
195 chance = 1,
196 min = 1,
197 max = 2,},
198 {name = colordata[1],
199 chance = 1,
200 min = 1,
201 max = 1,},
203 break
206 return
208 if mobs:capture_mob(self, clicker, 0, 5, 70, false, nil) then return end
209 end,
210 on_breed = function(parent1, parent2)
211 -- Breed sheep and choose a fur color for the child.
212 local pos = parent1.object:get_pos()
213 local child = mobs:spawn_child(pos, parent1.name)
214 if child then
215 local ent_c = child:get_luaentity()
216 local color1 = parent1.color
217 local color2 = parent2.color
219 local dye1 = mcl_dye.unicolor_to_dye(color1)
220 local dye2 = mcl_dye.unicolor_to_dye(color2)
221 local output
222 -- Check if parent colors could be mixed as dyes
223 if dye1 and dye2 then
224 output = minetest.get_craft_result({items = {dye1, dye2}, method="normal"})
226 local mixed = false
227 if output and not output.item:is_empty() then
228 -- Try to mix dyes and use that as new fur color
229 local new_dye = output.item:get_name()
230 local groups = minetest.registered_items[new_dye].groups
231 for k, v in pairs(groups) do
232 if string.sub(k, 1, 9) == "unicolor_" then
233 ent_c.color = k
234 ent_c.base_texture = sheep_texture(k)
235 mixed = true
236 break
241 -- Colors not mixable
242 if not mixed then
243 -- Choose color randomly from one of the parents
244 local p = math.random(1, 2)
245 if p == 1 and color1 then
246 ent_c.color = color1
247 else
248 ent_c.color = color2
250 ent_c.base_texture = sheep_texture(ent_c.color)
252 child:set_properties({textures = ent_c.base_texture})
253 ent_c.initial_color_set = true
254 ent_c.tamed = true
255 ent_c.owner = parent1.owner
256 return false
258 end,
260 mobs:spawn_specific("mobs_mc:sheep", mobs_mc.spawn.grassland, {"air"}, 0, minetest.LIGHT_MAX+1, 30, 15000, 3, mobs_mc.spawn_height.overworld_min, mobs_mc.spawn_height.overworld_max)
262 -- compatibility
263 mobs:alias_mob("mobs_animal:sheep", "mobs_mc:sheep")
264 -- spawn eggs
265 mobs:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0)
267 if minetest.settings:get_bool("log_mods") then
268 minetest.log("action", "MC Sheep loaded")