cow.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. local S = mobs.intllib
  2. -- Cow by sirrobzeroone
  3. mobs:register_mob("mobs_animal:cow", {
  4. type = "animal",
  5. passive = false,
  6. attack_type = "dogfight",
  7. attack_npcs = false,
  8. reach = 2,
  9. damage = 4,
  10. hp_min = 5,
  11. hp_max = 20,
  12. armor = 200,
  13. collisionbox = {-0.4, -0.01, -0.4, 0.4, 1.2, 0.4},
  14. visual = "mesh",
  15. mesh = "mobs_cow.b3d",
  16. textures = {
  17. {"mobs_cow.png"},
  18. {"mobs_cow2.png"},
  19. },
  20. makes_footstep_sound = true,
  21. sounds = {
  22. random = "mobs_cow",
  23. },
  24. walk_velocity = 1,
  25. run_velocity = 2,
  26. jump = true,
  27. jump_height = 6,
  28. pushable = true,
  29. drops = {
  30. {name = "mobs:meat_raw", chance = 1, min = 1, max = 3},
  31. {name = "mobs:leather", chance = 1, min = 0, max = 2},
  32. },
  33. water_damage = 0,
  34. lava_damage = 5,
  35. light_damage = 0,
  36. animation = {
  37. stand_start = 0,
  38. stand_end = 30,
  39. stand_speed = 20,
  40. stand1_start = 35,
  41. stand1_end = 75,
  42. stand1_speed = 20,
  43. walk_start = 85,
  44. walk_end = 114,
  45. walk_speed = 20,
  46. run_start = 120,
  47. run_end = 140,
  48. run_speed = 30,
  49. punch_start = 145,
  50. punch_end = 160,
  51. punch_speed = 20,
  52. die_start = 165,
  53. die_end = 185,
  54. die_speed = 10,
  55. die_loop = false,
  56. },
  57. follow = {"farming:wheat", "default:grass_1"},
  58. view_range = 8,
  59. replace_rate = 10,
  60. replace_what = {
  61. {"group:grass", "air", 0},
  62. {"default:dirt_with_grass", "default:dirt", -1}
  63. },
  64. fear_height = 2,
  65. on_rightclick = function(self, clicker)
  66. -- feed or tame
  67. if mobs:feed_tame(self, clicker, 8, true, true) then
  68. -- if fed 7x wheat or grass then cow can be milked again
  69. if self.food and self.food > 6 then
  70. self.gotten = false
  71. end
  72. return
  73. end
  74. if mobs:protect(self, clicker) then return end
  75. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  76. local tool = clicker:get_wielded_item()
  77. local name = clicker:get_player_name()
  78. -- milk cow with empty bucket
  79. if tool:get_name() == "bucket:bucket_empty" then
  80. --if self.gotten == true
  81. if self.child == true then
  82. return
  83. end
  84. if self.gotten == true then
  85. minetest.chat_send_player(name,
  86. S("Cow already milked!"))
  87. return
  88. end
  89. local inv = clicker:get_inventory()
  90. tool:take_item()
  91. clicker:set_wielded_item(tool)
  92. if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
  93. clicker:get_inventory():add_item("main", "mobs:bucket_milk")
  94. else
  95. local pos = self.object:get_pos()
  96. pos.y = pos.y + 0.5
  97. minetest.add_item(pos, {name = "mobs:bucket_milk"})
  98. end
  99. self.gotten = true -- milked
  100. return
  101. end
  102. end,
  103. on_replace = function(self, pos, oldnode, newnode)
  104. self.food = (self.food or 0) + 1
  105. -- if cow replaces 8x grass then it can be milked again
  106. if self.food >= 8 then
  107. self.food = 0
  108. self.gotten = false
  109. end
  110. end,
  111. })
  112. mobs:spawn({
  113. name = "mobs_animal:cow",
  114. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  115. neighbors = {"group:grass"},
  116. min_light = 14,
  117. interval = 60,
  118. chance = 8000, -- 15000
  119. min_height = 5,
  120. max_height = 200,
  121. day_toggle = true,
  122. })
  123. mobs:register_egg("mobs_animal:cow", S("Cow"), "mobs_cow_inv.png")
  124. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  125. -- bucket of milk
  126. minetest.register_craftitem(":mobs:bucket_milk", {
  127. description = S("Bucket of Milk"),
  128. inventory_image = "mobs_bucket_milk.png",
  129. stack_max = 1,
  130. on_use = minetest.item_eat(8, "bucket:bucket_empty"),
  131. groups = {food_milk = 1, flammable = 3},
  132. })
  133. -- glass of milk
  134. minetest.register_craftitem(":mobs:glass_milk", {
  135. description = S("Glass of Milk"),
  136. inventory_image = "mobs_glass_milk.png",
  137. on_use = minetest.item_eat(2, "vessels:drinking_glass"),
  138. groups = {food_milk_glass = 1, flammable = 3, vessel = 1},
  139. })
  140. minetest.register_craft({
  141. type = "shapeless",
  142. output = "mobs:glass_milk 4",
  143. recipe = {
  144. "vessels:drinking_glass", "vessels:drinking_glass",
  145. "vessels:drinking_glass", "vessels:drinking_glass",
  146. "mobs:bucket_milk"
  147. },
  148. replacements = { {"mobs:bucket_milk", "bucket:bucket_empty"} }
  149. })
  150. minetest.register_craft({
  151. type = "shapeless",
  152. output = "mobs:bucket_milk",
  153. recipe = {
  154. "mobs:glass_milk", "mobs:glass_milk",
  155. "mobs:glass_milk", "mobs:glass_milk",
  156. "bucket:bucket_empty"
  157. },
  158. replacements = { {"mobs:glass_milk", "vessels:drinking_glass 4"} }
  159. })
  160. -- butter
  161. minetest.register_craftitem(":mobs:butter", {
  162. description = S("Butter"),
  163. inventory_image = "mobs_butter.png",
  164. on_use = minetest.item_eat(1),
  165. groups = {food_butter = 1, flammable = 2},
  166. })
  167. if minetest.get_modpath("farming") and farming and farming.mod then
  168. minetest.register_craft({
  169. type = "shapeless",
  170. output = "mobs:butter",
  171. recipe = {"mobs:bucket_milk", "farming:salt"},
  172. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  173. })
  174. else -- some saplings are high in sodium so makes a good replacement item
  175. minetest.register_craft({
  176. type = "shapeless",
  177. output = "mobs:butter",
  178. recipe = {"mobs:bucket_milk", "default:sapling"},
  179. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  180. })
  181. end
  182. -- cheese wedge
  183. minetest.register_craftitem(":mobs:cheese", {
  184. description = S("Cheese"),
  185. inventory_image = "mobs_cheese.png",
  186. on_use = minetest.item_eat(4),
  187. groups = {food_cheese = 1, flammable = 2},
  188. })
  189. minetest.register_craft({
  190. type = "cooking",
  191. output = "mobs:cheese",
  192. recipe = "mobs:bucket_milk",
  193. cooktime = 5,
  194. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  195. })
  196. -- cheese block
  197. minetest.register_node(":mobs:cheeseblock", {
  198. description = S("Cheese Block"),
  199. tiles = {"mobs_cheeseblock.png"},
  200. is_ground_content = false,
  201. groups = {crumbly = 3},
  202. sounds = default.node_sound_dirt_defaults()
  203. })
  204. minetest.register_craft({
  205. output = "mobs:cheeseblock",
  206. recipe = {
  207. {"mobs:cheese", "mobs:cheese", "mobs:cheese"},
  208. {"mobs:cheese", "mobs:cheese", "mobs:cheese"},
  209. {"mobs:cheese", "mobs:cheese", "mobs:cheese"},
  210. }
  211. })
  212. minetest.register_craft({
  213. output = "mobs:cheese 9",
  214. recipe = {
  215. {"mobs:cheeseblock"},
  216. }
  217. })