sheep.lua 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. -- Localize for performance.
  2. local math_random = math.random
  3. mobs.register_mob("sheep:sheep", {
  4. type = "animal",
  5. passive = true,
  6. hp_min = 8,
  7. hp_max = 10,
  8. armor = 200,
  9. collisionbox = {-0.45, -1, -0.45, 0.45, 0.3, 0.45},
  10. visual = "mesh",
  11. mesh = "sheep_sheep.b3d",
  12. textures = {
  13. {"sheep_sheep_base.png^(sheep_sheep_wool.png^[colorize:#abababc0)"},
  14. },
  15. gotten_texture = {"sheep_sheep_shaved.png"},
  16. gotten_mesh = "sheep_sheep_shaved.b3d",
  17. makes_footstep_sound = true,
  18. sounds = {
  19. random = "sheep_sheep",
  20. death = "sheep_sheep",
  21. },
  22. walk_velocity = 1,
  23. run_velocity = 2,
  24. runaway = true,
  25. jump = true,
  26. drops = {
  27. {name = "mobs:meat_raw_mutton", chance = 1, min = 1, max = 1}, -- Killing sheep doesn't yield much meat.
  28. },
  29. water_damage = 1,
  30. lava_damage = 100,
  31. light_damage = 0,
  32. animation = {
  33. speed_normal = 15,
  34. speed_run = 15,
  35. stand_start = 0,
  36. stand_end = 80,
  37. walk_start = 81,
  38. walk_end = 100,
  39. },
  40. follow = {"farming:wheat", "default:grass_dummy", "default:coarsegrass"},
  41. view_range = 8,
  42. replace_rate = 10,
  43. replace_what = {
  44. "default:grass_3",
  45. "default:grass_4",
  46. "default:grass_5",
  47. "farming:wheat_8",
  48. },
  49. replace_with = "air",
  50. replace_offset = -1,
  51. fear_height = 2,
  52. on_rightclick = function(self, clicker)
  53. -- Are we feeding?
  54. if mobs.feed_tame(self, clicker, 8, true, true) then
  55. --if full grow fuzz
  56. if self.gotten == false then
  57. self.object:set_properties({
  58. textures = {"sheep_sheep_base.png^(sheep_sheep_wool.png^[colorize:#abababc0)"},
  59. mesh = "sheep_sheep.b3d",
  60. })
  61. end
  62. return
  63. end
  64. local item = clicker:get_wielded_item()
  65. local itemname = item:get_name()
  66. -- Are we giving a haircut?.
  67. if itemname == "shears:shears" then
  68. if self.gotten ~= false or self.child ~= false or not minetest.get_modpath("wool") then
  69. return
  70. end
  71. self.gotten = true -- shaved
  72. local obj = minetest.add_item(
  73. self.object:getpos(),
  74. ItemStack( "wool:white " .. math_random(1, 3) )
  75. )
  76. if obj then
  77. obj:setvelocity({
  78. x = math_random(-1, 1),
  79. y = 5,
  80. z = math_random(-1, 1)
  81. })
  82. end
  83. item:add_wear(650) -- 100 uses
  84. clicker:set_wielded_item(item)
  85. self.object:set_properties({
  86. textures = {"sheep_sheep_shaved.png"},
  87. mesh = "sheep_sheep_shaved.b3d",
  88. })
  89. return
  90. end
  91. -- Are we capturing?
  92. mobs.capture_mob(self, clicker, 0, 80, 60, false, nil)
  93. end
  94. })
  95. -- Obtainable by players.
  96. mobs.register_egg("sheep:sheep", "Sheep", "wool_white.png", 1)
  97. -- Compatibility.
  98. mobs.alias_mob("mobs:sheep", "sheep:sheep")
  99. mobs.alias_mob("mobs_animal:sheep_white", "sheep:sheep")