sheep.lua 6.0 KB

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