sheep.lua 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. local S = mobs.intllib_animal
  2. local random = math.random
  3. local all_colours = {
  4. {"black", S("Black"), "#000000b0"},
  5. {"blue", S("Blue"), "#015dbb70"},
  6. {"brown", S("Brown"), "#663300a0"},
  7. {"cyan", S("Cyan"), "#01ffd870"},
  8. {"dark_green", S("Dark Green"), "#005b0770"},
  9. {"dark_grey", S("Dark Grey"), "#303030b0"},
  10. {"green", S("Green"), "#61ff0170"},
  11. {"grey", S("Grey"), "#5b5b5bb0"},
  12. {"magenta", S("Magenta"), "#ff05bb70"},
  13. {"orange", S("Orange"), "#ff840170"},
  14. {"pink", S("Pink"), "#ff65b570"},
  15. {"red", S("Red"), "#ff0000a0"},
  16. {"violet", S("Violet"), "#2000c970"},
  17. {"white", S("White"), "#abababc0"},
  18. {"yellow", S("Yellow"), "#e3ff0070"}
  19. }
  20. -- Sheep by PilzAdam/K Pavel, texture converted to minetest by AMMOnym from Summerfield pack
  21. for _, col in ipairs(all_colours) do
  22. local drops_normal = {
  23. {name = "mobs:mutton_raw", chance = 1, min = 1, max = 2},
  24. {name = "wool:" .. col[1], chance = 1, min = 1, max = 1}
  25. }
  26. local drops_gotten = {
  27. {name = "mobs:mutton_raw", chance = 1, min = 1, max = 2}
  28. }
  29. mobs:register_mob("mobs_animal:sheep_" .. col[1], {
  30. stay_near = {"farming:straw", 10},
  31. stepheight = 0.6,
  32. type = "animal",
  33. passive = true,
  34. hp_min = 8,
  35. hp_max = 10,
  36. armor = 200,
  37. collisionbox = {-0.5, -1, -0.5, 0.5, 0.3, 0.5},
  38. visual = "mesh",
  39. mesh = "mobs_sheep.b3d",
  40. textures = {
  41. {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"}
  42. },
  43. gotten_texture = {"mobs_sheep_shaved.png"},
  44. gotten_mesh = "mobs_sheep_shaved.b3d",
  45. makes_footstep_sound = true,
  46. sounds = {
  47. random = "mobs_sheep"
  48. },
  49. walk_velocity = 1,
  50. run_velocity = 2,
  51. runaway = true,
  52. jump = true,
  53. jump_height = 6,
  54. pushable = true,
  55. drops = drops_normal,
  56. water_damage = 0,
  57. lava_damage = 5,
  58. light_damage = 0,
  59. animation = {
  60. speed_normal = 15,
  61. speed_run = 15,
  62. stand_start = 0,
  63. stand_end = 80,
  64. walk_start = 81,
  65. walk_end = 100,
  66. die_start = 1, -- we dont have a specific death animation so we will
  67. die_end = 2, -- re-use 2 standing frames at a speed of 1 fps and
  68. die_speed = 1, -- have mob rotate when dying.
  69. die_loop = false,
  70. die_rotate = true
  71. },
  72. follow = {
  73. "farming:wheat", "default:grass_1", "farming:barley",
  74. "farming:oat", "farming:rye"
  75. },
  76. view_range = 8,
  77. replace_rate = 10,
  78. replace_what = {
  79. {"group:grass", "air", -1},
  80. {"default:dirt_with_grass", "default:dirt", -2}
  81. },
  82. fear_height = 3,
  83. on_replace = function(self, pos, oldnode, newnode)
  84. self.food = (self.food or 0) + 1
  85. -- if sheep replaces 8x grass then it regrows wool
  86. if self.food >= 8 then
  87. self.food = 0
  88. self.gotten = false
  89. self.drops = drops_normal
  90. self.object:set_properties({
  91. textures = {
  92. "mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:"
  93. .. col[3] .. ")"
  94. },
  95. mesh = "mobs_sheep.b3d",
  96. })
  97. end
  98. end,
  99. on_rightclick = function(self, clicker)
  100. --are we feeding?
  101. if mobs:feed_tame(self, clicker, 8, true, true) then
  102. --if fed 7 times then sheep regrows wool
  103. if self.food and self.food > 6 then
  104. self.gotten = false
  105. self.drops = drops_normal
  106. self.object:set_properties({
  107. textures = {
  108. "mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:"
  109. .. col[3] .. ")"
  110. },
  111. mesh = "mobs_sheep.b3d"
  112. })
  113. end
  114. return
  115. end
  116. local item = clicker:get_wielded_item()
  117. local itemname = item:get_name()
  118. local name = clicker:get_player_name()
  119. --are we giving a haircut>
  120. if itemname == "mobs:shears" then
  121. if self.gotten ~= false
  122. or self.child ~= false
  123. or name ~= self.owner
  124. or not minetest.get_modpath("wool") then
  125. return
  126. end
  127. self.gotten = true -- shaved
  128. self.drops = drops_gotten
  129. local obj = minetest.add_item(
  130. self.object:get_pos(),
  131. ItemStack("wool:" .. col[1] .. " " .. random(3))
  132. )
  133. if obj then
  134. obj:set_velocity({
  135. x = random(-1, 1),
  136. y = 5,
  137. z = random(-1, 1)
  138. })
  139. end
  140. item:add_wear(650) -- 100 uses
  141. clicker:set_wielded_item(item)
  142. self.object:set_properties({
  143. textures = {"mobs_sheep_shaved.png"},
  144. mesh = "mobs_sheep_shaved.b3d"
  145. })
  146. return
  147. end
  148. --are we coloring?
  149. if itemname:find("dye:") then
  150. if self.gotten == false
  151. and self.child == false
  152. and self.tamed == true
  153. and name == self.owner then
  154. local colr = string.split(itemname, ":")[2]
  155. for _,c in pairs(all_colours) do
  156. if c[1] == colr then
  157. local pos = self.object:get_pos()
  158. self.object:remove()
  159. local mob = minetest.add_entity(pos, "mobs_animal:sheep_" .. colr)
  160. local ent = mob:get_luaentity()
  161. ent.owner = name
  162. ent.tamed = true
  163. ent.protected = self.protected
  164. ent.fire_damage = self.fire_damage
  165. -- take item
  166. if not mobs.is_creative(clicker:get_player_name()) then
  167. item:take_item()
  168. clicker:set_wielded_item(item)
  169. end
  170. break
  171. end
  172. end
  173. end
  174. return
  175. end
  176. -- protect mod with mobs:protector item
  177. if mobs:protect(self, clicker) then return end
  178. --are we capturing?
  179. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  180. end
  181. })
  182. -- spawn egg
  183. mobs:register_egg("mobs_animal:sheep_"..col[1], S("@1 Sheep", col[2]),
  184. "wool_" .. col[1] .. ".png^mobs_sheep_inv.png")
  185. -- compatibility
  186. mobs:alias_mob("mobs:sheep_" .. col[1], "mobs_animal:sheep_" .. col[1])
  187. end
  188. if not mobs.custom_spawn_animal then
  189. mobs:spawn({
  190. name = "mobs_animal:sheep_white",
  191. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  192. neighbors = {"group:grass"},
  193. min_light = 14,
  194. interval = 60,
  195. chance = 8000,
  196. min_height = 0,
  197. max_height = 200,
  198. day_toggle = true,
  199. active_object_count = 3,
  200. -- custom function to spawn sheep herds around main mob
  201. on_spawn = function(self, pos)
  202. local nods = minetest.find_nodes_in_area_under_air(
  203. {x = pos.x - 4, y = pos.y - 3, z = pos.z - 4},
  204. {x = pos.x + 4, y = pos.y + 3, z = pos.z + 4},
  205. {"default:dirt_with_grass", "ethereal:green_dirt"})
  206. if nods and #nods > 0 then
  207. -- min herd of 3
  208. local iter = math.min(#nods, 3)
  209. -- print("--- sheep at", minetest.pos_to_string(pos), iter)
  210. for n = 1, iter do
  211. -- 1/8 chance of black sheep, 1/4 chance of baby sheep
  212. local pos2 = nods[random(#nods)]
  213. local type = random(8) == 1 and "_black" or "_white"
  214. local kid = random(4) == 1 and true or nil
  215. pos2.y = pos2.y + 2
  216. if minetest.get_node(pos2).name == "air" then
  217. mobs:add_mob(pos2, {
  218. name = "mobs_animal:sheep" .. type, child = kid})
  219. end
  220. end
  221. end
  222. end
  223. })
  224. end
  225. mobs:alias_mob("mobs:sheep", "mobs_animal:sheep_white") -- compatibility
  226. -- raw mutton
  227. minetest.register_craftitem(":mobs:mutton_raw", {
  228. description = S("Raw Mutton"),
  229. inventory_image = "mobs_mutton_raw.png",
  230. on_use = minetest.item_eat(2),
  231. groups = {food_meat_raw = 1, food_mutton_raw = 1, flammable = 2}
  232. })
  233. -- cooked mutton
  234. minetest.register_craftitem(":mobs:mutton_cooked", {
  235. description = S("Cooked Mutton"),
  236. inventory_image = "mobs_mutton_cooked.png",
  237. on_use = minetest.item_eat(6),
  238. groups = {food_meat = 1, food_mutton = 1, flammable = 2}
  239. })
  240. minetest.register_craft({
  241. type = "cooking",
  242. output = "mobs:mutton_cooked",
  243. recipe = "mobs:mutton_raw",
  244. cooktime = 5
  245. })