1 --License for code WTFPL and otherwise stated in readmes
4 local MP
= minetest
.get_modpath(minetest
.get_current_modname())
5 local S
, NS
= dofile(MP
.."/intllib.lua")
8 --################### SHEEP
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" }
34 local sheep_texture
= function(color_group
)
36 "mobs_mc_sheep_fur.png^[colorize:"..colors
[color_group
][2],
41 local gotten_texture
= { "blank.png", "mobs_mc_sheep.png" }
44 mobs
:register_mob("mobs_mc:sheep", {
49 collisionbox
= {-0.45, -0.01, -0.45, 0.45, 1.29, 0.45},
52 visual_size
= {x
=3, y
=3},
53 mesh
= "mobs_mc_sheepfur.b3d",
54 textures
= { sheep_texture("unicolor_white") },
55 gotten_texture
= gotten_texture
,
56 color
= "unicolor_white",
57 makes_footstep_sound
= true,
60 {name
= mobs_mc
.items
.mutton_raw
,
64 {name
= colors
["unicolor_white"][1],
74 random = "mobs_sheep",
76 damage
= "mobs_sheep",
80 speed_normal
= 25, speed_run
= 50,
81 stand_start
= 40, stand_end
= 80,
82 walk_start
= 0, walk_end
= 40,
83 run_start
= 0, run_end
= 40,
85 follow
= mobs_mc
.follow
.sheep
,
90 replace_what
= mobs_mc
.replace
.sheep
,
91 -- Properly regrow wool after eating grass
92 on_replace
= function(self
, pos
, oldnode
, newnode
)
93 if not self
.color
or not colors
[self
.color
] then
94 self
.color
= "unicolor_white"
97 self
.base_texture
= sheep_texture(self
.color
)
98 self
.object
:set_properties({ textures
= self
.base_texture
})
100 {name
= mobs_mc
.items
.mutton_raw
,
104 {name
= colors
[self
.color
][1],
111 -- Set random color on spawn
112 do_custom
= function(self
)
113 if not self
.initial_color_set
then
114 local r
= math
.random(0,100000)
118 self
.color
= "unicolor_white"
119 elseif r
<= 81836 + 5000 then
121 self
.color
= "unicolor_grey"
122 elseif r
<= 81836 + 5000 + 5000 then
124 self
.color
= "unicolor_darkgrey"
125 elseif r
<= 81836 + 5000 + 5000 + 5000 then
127 self
.color
= "unicolor_black"
128 elseif r
<= 81836 + 5000 + 5000 + 5000 + 3000 then
130 self
.color
= "unicolor_dark_orange"
133 self
.color
= "unicolor_light_red"
135 self
.base_texture
= sheep_texture(self
.color
)
136 self
.object
:set_properties({ textures
= self
.base_texture
})
138 {name
= mobs_mc
.items
.mutton_raw
,
142 {name
= colors
[self
.color
][1],
147 self
.initial_color_set
= true
151 on_rightclick
= function(self
, clicker
)
152 local item
= clicker
:get_wielded_item()
154 if mobs
:feed_tame(self
, clicker
, 1, true, true) then return end
155 if mobs
:protect(self
, clicker
) then return end
157 if item
:get_name() == mobs_mc
.items
.shears
and not self
.gotten
and not self
.child
then
159 local pos
= self
.object
:get_pos()
160 minetest
.sound_play("shears", {pos
= pos
})
162 if not self
.color
then
163 self
.color
= "unicolor_white"
165 minetest
.add_item(pos
, ItemStack(colors
[self
.color
][1].." "..math
.random(1,3)))
166 self
.base_texture
= gotten_texture
167 self
.object
:set_properties({
168 textures
= self
.base_texture
,
170 if not minetest
.settings
:get_bool("creative_mode") then
171 item
:add_wear(mobs_mc
.misc
.shears_wear
)
172 clicker
:get_inventory():set_stack("main", clicker
:get_wield_index(), item
)
175 {name
= mobs_mc
.items
.mutton_raw
,
183 if minetest
.get_item_group(item
:get_name(), "dye") == 1 and not self
.gotten
then
184 minetest
.log("verbose", "[mobs_mc] " ..item
:get_name() .. " " .. minetest
.get_item_group(item
:get_name(), "dye"))
185 for group
, colordata
in pairs(colors
) do
186 if minetest
.get_item_group(item
:get_name(), group
) == 1 then
187 self
.base_texture
= sheep_texture(group
)
188 self
.object
:set_properties({
189 textures
= self
.base_texture
,
193 {name
= mobs_mc
.items
.mutton_raw
,
197 {name
= colordata
[1],
207 if mobs
:capture_mob(self
, clicker
, 0, 5, 70, false, nil) then return end
209 on_breed
= function(parent1
, parent2
)
210 -- Breed sheep and choose a fur color for the child.
211 local pos
= parent1
.object
:get_pos()
212 local child
= mobs
:spawn_child(pos
, parent1
.name
)
214 local ent_c
= child
:get_luaentity()
215 local color1
= parent1
.color
216 local color2
= parent2
.color
218 local dye1
= mcl_dye
.unicolor_to_dye(color1
)
219 local dye2
= mcl_dye
.unicolor_to_dye(color2
)
221 -- Check if parent colors could be mixed as dyes
222 if dye1
and dye2
then
223 output
= minetest
.get_craft_result({items
= {dye1
, dye2
}, method
="normal"})
226 if output
and not output
.item
:is_empty() then
227 -- Try to mix dyes and use that as new fur color
228 local new_dye
= output
.item
:get_name()
229 local groups
= minetest
.registered_items
[new_dye
].groups
230 for k
, v
in pairs(groups
) do
231 if string.sub(k
, 1, 9) == "unicolor_" then
232 ent_c
.base_texture
= sheep_texture(k
)
239 -- Colors not mixable
241 -- Choose color randomly from one of the parents
242 local p
= math
.random(1, 2)
244 ent_c
.base_texture
= sheep_texture(color1
)
246 ent_c
.base_texture
= sheep_texture(color2
)
249 child
:set_properties({textures
= ent_c
.base_texture
})
250 ent_c
.initial_color_set
= true
252 ent_c
.owner
= parent1
.owner
257 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
)
260 mobs
:alias_mob("mobs_animal:sheep", "mobs_mc:sheep")
262 mobs
:register_egg("mobs_mc:sheep", S("Sheep"), "mobs_mc_spawn_icon_sheep.png", 0)
264 if minetest
.settings
:get_bool("log_mods") then
265 minetest
.log("action", "MC Sheep loaded")