sheep.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. },
  50. water_damage = 1,
  51. lava_damage = 5,
  52. light_damage = 0,
  53. animation = {
  54. speed_normal = 15,
  55. speed_run = 15,
  56. stand_start = 0,
  57. stand_end = 80,
  58. walk_start = 81,
  59. walk_end = 100,
  60. },
  61. follow = {"farming:wheat", "default:grass_5"},
  62. view_range = 8,
  63. replace_rate = 10,
  64. replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "farming:wheat_8"},
  65. replace_with = "air",
  66. replace_offset = -1,
  67. fear_height = 3,
  68. --[[
  69. on_replace = function(self, pos, oldnode, newnode)
  70. print ("---- replaced") ; return false -- false to keep node, true to replace
  71. end,
  72. ]]
  73. on_rightclick = function(self, clicker)
  74. --are we feeding?
  75. if mobs:feed_tame(self, clicker, 8, true, true) then
  76. --if full grow fuzz
  77. if self.gotten == false then
  78. self.object:set_properties({
  79. textures = {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},
  80. mesh = "mobs_sheep.b3d",
  81. })
  82. end
  83. return
  84. end
  85. local item = clicker:get_wielded_item()
  86. local itemname = item:get_name()
  87. local name = clicker:get_player_name()
  88. --are we giving a haircut>
  89. if itemname == "mobs:shears" then
  90. if self.gotten ~= false
  91. or self.child ~= false
  92. or name ~= self.owner
  93. or not minetest.get_modpath("wool") then
  94. return
  95. end
  96. self.gotten = true -- shaved
  97. local obj = minetest.add_item(
  98. self.object:get_pos(),
  99. ItemStack( "wool:" .. col[1] .. " " .. math.random(1, 3) )
  100. )
  101. if obj then
  102. obj:setvelocity({
  103. x = math.random(-1, 1),
  104. y = 5,
  105. z = math.random(-1, 1)
  106. })
  107. end
  108. item:add_wear(650) -- 100 uses
  109. clicker:set_wielded_item(item)
  110. self.object:set_properties({
  111. textures = {"mobs_sheep_shaved.png"},
  112. mesh = "mobs_sheep_shaved.b3d",
  113. })
  114. return
  115. end
  116. --are we coloring?
  117. if itemname:find("dye:") then
  118. if self.gotten == false
  119. and self.child == false
  120. and self.tamed == true
  121. and name == self.owner then
  122. local colr = string.split(itemname, ":")[2]
  123. for _,c in pairs(all_colours) do
  124. if c[1] == colr then
  125. local pos = self.object:get_pos()
  126. self.object:remove()
  127. local mob = minetest.add_entity(pos, "mobs_animal:sheep_" .. colr)
  128. local ent = mob:get_luaentity()
  129. ent.owner = name
  130. ent.tamed = true
  131. -- take item
  132. if not mobs.is_creative(clicker:get_player_name()) then
  133. item:take_item()
  134. clicker:set_wielded_item(item)
  135. end
  136. break
  137. end
  138. end
  139. end
  140. return
  141. end
  142. -- protect mod with mobs:protector item
  143. if mobs:protect(self, clicker) then return end
  144. --are we capturing?
  145. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  146. end
  147. })
  148. mobs:register_egg("mobs_animal:sheep_"..col[1], S("@1 Sheep", col[2]), "wool_"..col[1]..".png", 1)
  149. -- compatibility
  150. mobs:alias_mob("mobs:sheep_" .. col[1], "mobs_animal:sheep_" .. col[1])
  151. end
  152. mobs:spawn({
  153. name = "mobs_animal:sheep_white",
  154. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  155. neighbors = {"group:grass"},
  156. min_light = 14,
  157. interval = 60,
  158. chance = 8000, -- 15000
  159. min_height = 0,
  160. max_height = 200,
  161. day_toggle = true,
  162. })
  163. mobs:alias_mob("mobs:sheep", "mobs_animal:sheep_white") -- compatibility
  164. -- raw mutton
  165. minetest.register_craftitem(":mobs:mutton_raw", {
  166. description = S("Raw Mutton"),
  167. inventory_image = "mobs_mutton_raw.png",
  168. on_use = minetest.item_eat(2),
  169. groups = {food_meat_raw = 1, food_mutton_raw = 1, flammable = 2},
  170. })
  171. -- cooked mutton
  172. minetest.register_craftitem(":mobs:mutton_cooked", {
  173. description = S("Cooked Mutton"),
  174. inventory_image = "mobs_mutton_cooked.png",
  175. on_use = minetest.item_eat(6),
  176. groups = {food_meat = 1, food_mutton = 1, flammable = 2},
  177. })
  178. minetest.register_craft({
  179. type = "cooking",
  180. output = "mobs:mutton_cooked",
  181. recipe = "mobs:mutton_raw",
  182. cooktime = 5,
  183. })