sheep.lua 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  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. type = "monster",
  23. passive = false,
  24. attack_type = "dogfight",
  25. pathfinding = true,
  26. reach = 2,
  27. hp_min = 8,
  28. hp_max = 10,
  29. armor = 200,
  30. collisionbox = {-0.5, -1, -0.5, 0.5, 0.3, 0.5},
  31. visual = "mesh",
  32. mesh = "mobs_sheep.b3d",
  33. textures = {
  34. {"mobs_sheep_base.png^(mobs_sheep_wool.png^[colorize:" .. col[3] .. ")"},
  35. },
  36. gotten_texture = {"mobs_sheep_shaved.png"},
  37. gotten_mesh = "mobs_sheep_shaved.b3d",
  38. makes_footstep_sound = true,
  39. sounds = {
  40. random = "mobs_sheep",
  41. },
  42. walk_velocity = 1,
  43. run_velocity = 2,
  44. runaway = true,
  45. jump = true,
  46. drops = {
  47. {name = "mobs:meat_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_harvested", "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. --are we giving a haircut>
  88. if itemname == "mobs:shears" then
  89. if self.gotten ~= false
  90. or self.child ~= false
  91. or not minetest.get_modpath("wool") then
  92. return
  93. end
  94. self.gotten = true -- shaved
  95. local obj = minetest.add_item(
  96. self.object:getpos(),
  97. ItemStack( "wool:" .. col[1] .. " " .. math.random(1, 3) )
  98. )
  99. if obj then
  100. obj:setvelocity({
  101. x = math.random(-1, 1),
  102. y = 5,
  103. z = math.random(-1, 1)
  104. })
  105. end
  106. item:add_wear(650) -- 100 uses
  107. clicker:set_wielded_item(item)
  108. self.object:set_properties({
  109. textures = {"mobs_sheep_shaved.png"},
  110. mesh = "mobs_sheep_shaved.b3d",
  111. })
  112. return
  113. end
  114. local name = clicker:get_player_name()
  115. --are we coloring?
  116. if itemname:find("dye:") then
  117. if self.gotten == false
  118. and self.child == false
  119. and self.tamed == true
  120. and name == self.owner then
  121. local colr = string.split(itemname, ":")[2]
  122. for _,c in pairs(all_colours) do
  123. if c[1] == colr then
  124. local pos = self.object:getpos()
  125. self.object:remove()
  126. local mob = minetest.add_entity(pos, "mobs_animal:sheep_" .. colr)
  127. local ent = mob:get_luaentity()
  128. ent.owner = name
  129. ent.tamed = true
  130. -- take item
  131. if not minetest.setting_getbool("creative_mode") then
  132. item:take_item()
  133. clicker:set_wielded_item(item)
  134. end
  135. break
  136. end
  137. end
  138. end
  139. return
  140. end
  141. -- protect mod with mobs:protector item
  142. if mobs:protect(self, clicker) then return end
  143. --are we capturing?
  144. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  145. end
  146. })
  147. mobs:register_egg("mobs_animal:sheep_"..col[1], col[2] .. " " .. S("Sheep"), "wool_"..col[1]..".png", 1)
  148. -- compatibility
  149. mobs:alias_mob("mobs:sheep_" .. col[1], "mobs_animal:sheep_" .. col[1])
  150. end
  151. local spawn_on = "default:dirt_with_grass"
  152. if minetest.get_modpath("ethereal") then
  153. spawn_on = "ethereal:green_dirt"
  154. end
  155. mobs:spawn({
  156. name = "mobs_animal:sheep_white",
  157. nodes = {spawn_on},
  158. min_light = 10,
  159. chance = 15000,
  160. min_height = 0,
  161. max_height = 31000,
  162. day_toggle = true,
  163. })
  164. mobs:alias_mob("mobs:sheep", "mobs_animal:sheep_white") -- compatibility