sheep.lua 6.2 KB

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