sheep.lua 5.7 KB

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