Update helptext of obsidian
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / sheep.lua
blob374ea4b59000e831c1bc3b0210dd4c11650e2ed4
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 spawn_class = "passive",
48 hp_min = 8,
49 hp_max = 8,
51 collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
53 visual = "mesh",
54 visual_size = {x=3, y=3},
55 mesh = "mobs_mc_sheepfur.b3d",
56 textures = { sheep_texture("unicolor_white") },
57 gotten_texture = gotten_texture,
58 color = "unicolor_white",
59 makes_footstep_sound = true,
60 walk_velocity = 1,
61 drops = {
62 {name = mobs_mc.items.mutton_raw,
63 chance = 1,
64 min = 1,
65 max = 2,},
66 {name = colors["unicolor_white"][1],
67 chance = 1,
68 min = 1,
69 max = 1,},
71 fear_height = 4,
72 sounds = {
73 random = "mobs_sheep",
74 death = "mobs_sheep",
75 damage = "mobs_sheep",
76 distance = 16,
78 animation = {
79 speed_normal = 25, run_speed = 65,
80 stand_start = 40, stand_end = 80,
81 walk_start = 0, walk_end = 40,
82 run_start = 0, run_end = 40,
84 follow = mobs_mc.follow.sheep,
85 view_range = 12,
87 -- Eat grass
88 replace_rate = 20,
89 replace_what = mobs_mc.replace.sheep,
90 -- Properly regrow wool after eating grass
91 on_replace = function(self, pos, oldnode, newnode)
92 if not self.color or not colors[self.color] then
93 self.color = "unicolor_white"
94 end
95 self.gotten = false
96 self.base_texture = sheep_texture(self.color)
97 self.object:set_properties({ textures = self.base_texture })
98 self.drops = {
99 {name = mobs_mc.items.mutton_raw,
100 chance = 1,
101 min = 1,
102 max = 2,},
103 {name = colors[self.color][1],
104 chance = 1,
105 min = 1,
106 max = 1,},
108 end,
110 -- Set random color on spawn
111 do_custom = function(self)
112 if not self.initial_color_set then
113 local r = math.random(0,100000)
114 local textures
115 if r <= 81836 then
116 -- 81.836%
117 self.color = "unicolor_white"
118 elseif r <= 81836 + 5000 then
119 -- 5%
120 self.color = "unicolor_grey"
121 elseif r <= 81836 + 5000 + 5000 then
122 -- 5%
123 self.color = "unicolor_darkgrey"
124 elseif r <= 81836 + 5000 + 5000 + 5000 then
125 -- 5%
126 self.color = "unicolor_black"
127 elseif r <= 81836 + 5000 + 5000 + 5000 + 3000 then
128 -- 3%
129 self.color = "unicolor_dark_orange"
130 else
131 -- 0.164%
132 self.color = "unicolor_light_red"
134 self.base_texture = sheep_texture(self.color)
135 self.object:set_properties({ textures = self.base_texture })
136 self.drops = {
137 {name = mobs_mc.items.mutton_raw,
138 chance = 1,
139 min = 1,
140 max = 2,},
141 {name = colors[self.color][1],
142 chance = 1,
143 min = 1,
144 max = 1,},
146 self.initial_color_set = true
148 end,
150 on_rightclick = function(self, clicker)
151 local item = clicker:get_wielded_item()
153 if mobs:feed_tame(self, clicker, 1, true, true) then return end
154 if mobs:protect(self, clicker) then return end
156 if item:get_name() == mobs_mc.items.shears and not self.gotten and not self.child then
157 self.gotten = true
158 local pos = self.object:get_pos()
159 minetest.sound_play("shears", {pos = pos}, true)
160 pos.y = pos.y + 0.5
161 if not self.color then
162 self.color = "unicolor_white"
164 minetest.add_item(pos, ItemStack(colors[self.color][1].." "..math.random(1,3)))
165 self.base_texture = gotten_texture
166 self.object:set_properties({
167 textures = self.base_texture,
169 if not minetest.is_creative_enabled(clicker:get_player_name()) then
170 item:add_wear(mobs_mc.misc.shears_wear)
171 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
173 self.drops = {
174 {name = mobs_mc.items.mutton_raw,
175 chance = 1,
176 min = 1,
177 max = 2,},
179 return
181 -- Dye sheep
182 if minetest.get_item_group(item:get_name(), "dye") == 1 and not self.gotten then
183 minetest.log("verbose", "[mobs_mc] " ..item:get_name() .. " " .. minetest.get_item_group(item:get_name(), "dye"))
184 for group, colordata in pairs(colors) do
185 if minetest.get_item_group(item:get_name(), group) == 1 then
186 if not minetest.is_creative_enabled(clicker:get_player_name()) then
187 item:take_item()
188 clicker:set_wielded_item(item)
190 self.base_texture = sheep_texture(group)
191 self.object:set_properties({
192 textures = self.base_texture,
194 self.color = group
195 self.drops = {
196 {name = mobs_mc.items.mutton_raw,
197 chance = 1,
198 min = 1,
199 max = 2,},
200 {name = colordata[1],
201 chance = 1,
202 min = 1,
203 max = 1,},
205 break
208 return
210 if mobs:capture_mob(self, clicker, 0, 5, 70, false, nil) then return end
211 end,
212 on_breed = function(parent1, parent2)
213 -- Breed sheep and choose a fur color for the child.
214 local pos = parent1.object:get_pos()
215 local child = mobs:spawn_child(pos, parent1.name)
216 if child then
217 local ent_c = child:get_luaentity()
218 local color1 = parent1.color
219 local color2 = parent2.color
221 local dye1 = mcl_dye.unicolor_to_dye(color1)
222 local dye2 = mcl_dye.unicolor_to_dye(color2)
223 local output
224 -- Check if parent colors could be mixed as dyes
225 if dye1 and dye2 then
226 output = minetest.get_craft_result({items = {dye1, dye2}, method="normal"})
228 local mixed = false
229 if output and not output.item:is_empty() then
230 -- Try to mix dyes and use that as new fur color
231 local new_dye = output.item:get_name()
232 local groups = minetest.registered_items[new_dye].groups
233 for k, v in pairs(groups) do
234 if string.sub(k, 1, 9) == "unicolor_" then
235 ent_c.color = k
236 ent_c.base_texture = sheep_texture(k)
237 mixed = true
238 break
243 -- Colors not mixable
244 if not mixed then
245 -- Choose color randomly from one of the parents
246 local p = math.random(1, 2)
247 if p == 1 and color1 then
248 ent_c.color = color1
249 else
250 ent_c.color = color2
252 ent_c.base_texture = sheep_texture(ent_c.color)
254 child:set_properties({textures = ent_c.base_texture})
255 ent_c.initial_color_set = true
256 ent_c.tamed = true
257 ent_c.owner = parent1.owner
258 return false
260 end,
262 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)
264 -- spawn eggs
265 mobs:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0)