Clean up grass block group stuff
[MineClone/MineClone2.git] / mods / ENTITIES / mobs_mc / sheep.lua
blobbfc8ac0f474c2e5c1d79094154d2c69bee3044e7
1 --License for code WTFPL and otherwise stated in readmes
3 -- intllib
4 local MP = minetest.get_modpath(minetest.get_current_modname())
5 local S, NS = dofile(MP.."/intllib.lua")
7 --###################
8 --################### SHEEP
9 --###################
11 local colors = {
12 -- group = { wool, textures }
13 unicolor_white = { mobs_mc.items.wool_white, "#FFFFFF00" },
14 unicolor_dark_orange = { mobs_mc.items.wool_brown, "#502A00D0" },
15 unicolor_grey = { mobs_mc.items.wool_light_grey, "#5B5B5BD0" },
16 unicolor_darkgrey = { mobs_mc.items.wool_grey, "#303030D0" },
17 unicolor_blue = { mobs_mc.items.wool_blue, "#0000CCD0" },
18 unicolor_dark_green = { mobs_mc.items.wool_green, "#005000D0" },
19 unicolor_green = { mobs_mc.items.wool_lime, "#50CC00D0" },
20 unicolor_violet = { mobs_mc.items.wool_purple , "#5000CCD0" },
21 unicolor_light_red = { mobs_mc.items.wool_pink, "#FF5050D0" },
22 unicolor_yellow = { mobs_mc.items.wool_yellow, "#CCCC00D0" },
23 unicolor_orange = { mobs_mc.items.wool_orange, "#CC5000D0" },
24 unicolor_red = { mobs_mc.items.wool_red, "#CC0000D0" },
25 unicolor_cyan = { mobs_mc.items.wool_cyan, "#00CCCCD0" },
26 unicolor_red_violet = { mobs_mc.items.wool_magenta, "#CC0050D0" },
27 unicolor_black = { mobs_mc.items.wool_black, "#000000D0" },
30 if minetest.get_modpath("mcl_wool") ~= nil then
31 colors["unicolor_light_blue"] = { mobs_mc.items.wool_light_blue, "#5050FFD0" }
32 end
34 local sheep_texture = function(color_group)
35 return {"mobs_mc_sheep.png^(mobs_mc_sheep_fur.png^[colorize:"..colors[color_group][2]..")"}
36 end
38 --mcsheep
39 mobs:register_mob("mobs_mc:sheep", {
40 type = "animal",
41 hp_min = 8,
42 hp_max = 8,
44 collisionbox = {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
46 visual = "mesh",
47 visual_size = {x=3, y=3},
48 mesh = "mobs_mc_sheepfur.b3d",
49 gotten_mesh = "mobs_mc_sheepnaked.b3d",
50 textures = { sheep_texture("unicolor_white") },
51 color = "unicolor_white",
52 makes_footstep_sound = true,
53 walk_velocity = 1,
54 drops = {
55 {name = mobs_mc.items.mutton_raw,
56 chance = 1,
57 min = 1,
58 max = 2,},
59 {name = colors["unicolor_white"][1],
60 chance = 1,
61 min = 1,
62 max = 1,},
64 water_damage = 1,
65 lava_damage = 4,
66 light_damage = 0,
67 fear_height = 4,
68 sounds = {
69 random = "mobs_sheep",
70 death = "mobs_sheep",
71 damage = "mobs_sheep",
72 distance = 16,
74 animation = {
75 speed_normal = 25, speed_run = 50,
76 stand_start = 40, stand_end = 80,
77 walk_start = 0, walk_end = 40,
78 run_start = 0, run_end = 40,
80 follow = mobs_mc.follow.sheep,
81 view_range = 12,
83 -- Eat grass
84 replace_rate = 20,
85 replace_what = mobs_mc.replace.sheep,
86 -- Properly regrow wool after eating grass
87 on_replace = function(self, pos, oldnode, newnode)
88 if not self.color or not colors[self.color] then
89 self.color = "unicolor_white"
90 end
91 self.gotten = false
92 self.drops = {
93 {name = mobs_mc.items.mutton_raw,
94 chance = 1,
95 min = 1,
96 max = 2,},
97 {name = colors[self.color][1],
98 chance = 1,
99 min = 1,
100 max = 1,},
102 self.object:set_properties({
103 mesh = "mobs_mc_sheepfur.b3d",
105 end,
107 -- Set random color on spawn
108 do_custom = function(self)
109 if not self.initial_color_set then
110 local r = math.random(0,100000)
111 local textures
112 if r <= 81836 then
113 -- 81.836%
114 self.color = "unicolor_white"
115 elseif r <= 81836 + 5000 then
116 -- 5%
117 self.color = "unicolor_grey"
118 elseif r <= 81836 + 5000 + 5000 then
119 -- 5%
120 self.color = "unicolor_darkgrey"
121 elseif r <= 81836 + 5000 + 5000 + 5000 then
122 -- 5%
123 self.color = "unicolor_black"
124 elseif r <= 81836 + 5000 + 5000 + 5000 + 3000 then
125 -- 3%
126 self.color = "unicolor_dark_orange"
127 else
128 -- 0.164%
129 self.color = "unicolor_light_red"
131 self.base_texture = sheep_texture(self.color)
132 self.object:set_properties({ textures = self.base_texture })
133 self.drops = {
134 {name = mobs_mc.items.mutton_raw,
135 chance = 1,
136 min = 1,
137 max = 2,},
138 {name = colors[self.color][1],
139 chance = 1,
140 min = 1,
141 max = 1,},
143 self.initial_color_set = true
145 end,
147 on_rightclick = function(self, clicker)
148 local item = clicker:get_wielded_item()
150 if mobs:feed_tame(self, clicker, 1, true, true) then return end
151 if mobs:protect(self, clicker) then return end
153 if item:get_name() == mobs_mc.items.shears and not self.gotten then
154 self.gotten = true
155 local pos = self.object:getpos()
156 minetest.sound_play("shears", {pos = pos})
157 pos.y = pos.y + 0.5
158 if not self.color then
159 self.color = "unicolor_white"
161 minetest.add_item(pos, ItemStack(colors[self.color][1].." "..math.random(1,3)))
162 self.object:set_properties({
163 mesh = "mobs_mc_sheepnaked.b3d",
165 if not minetest.settings:get_bool("creative_mode") then
166 item:add_wear(mobs_mc.misc.shears_wear)
167 clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
169 self.drops = {
170 {name = mobs_mc.items.mutton_raw,
171 chance = 1,
172 min = 1,
173 max = 2,},
175 return
177 -- Dye sheep
178 if minetest.get_item_group(item:get_name(), "dye") == 1 and not self.gotten then
179 minetest.log("verbose", "[mobs_mc] " ..item:get_name() .. " " .. minetest.get_item_group(item:get_name(), "dye"))
180 for group, colordata in pairs(colors) do
181 if minetest.get_item_group(item:get_name(), group) == 1 then
182 self.base_texture = sheep_texture(group)
183 self.object:set_properties({
184 textures = self.base_texture,
186 self.color = group
187 self.drops = {
188 {name = mobs_mc.items.mutton_raw,
189 chance = 1,
190 min = 1,
191 max = 2,},
192 {name = colordata[1],
193 chance = 1,
194 min = 1,
195 max = 1,},
197 break
200 return
202 if mobs:capture_mob(self, clicker, 0, 5, 70, false, nil) then return end
203 end,
205 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)
207 -- compatibility
208 mobs:alias_mob("mobs_animal:sheep", "mobs_mc:sheep")
209 -- spawn eggs
210 mobs:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0)
212 if minetest.settings:get_bool("log_mods") then
213 minetest.log("action", "MC Sheep loaded")