cow.lua 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257
  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. -- stay_near = {{"farming:straw", "group:grass"}, 10},
  65. fear_height = 2,
  66. on_rightclick = function(self, clicker)
  67. -- feed or tame
  68. if mobs:feed_tame(self, clicker, 8, true, true) then
  69. -- if fed 7x wheat or grass then cow can be milked again
  70. if self.food and self.food > 6 then
  71. self.gotten = false
  72. end
  73. return
  74. end
  75. if mobs:protect(self, clicker) then return end
  76. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  77. local tool = clicker:get_wielded_item()
  78. local name = clicker:get_player_name()
  79. -- milk cow with empty bucket
  80. if tool:get_name() == "bucket:bucket_empty" then
  81. --if self.gotten == true
  82. if self.child == true then
  83. return
  84. end
  85. if self.gotten == true then
  86. minetest.chat_send_player(name,
  87. S("Cow already milked!"))
  88. return
  89. end
  90. local inv = clicker:get_inventory()
  91. tool:take_item()
  92. clicker:set_wielded_item(tool)
  93. if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
  94. clicker:get_inventory():add_item("main", "mobs:bucket_milk")
  95. else
  96. local pos = self.object:get_pos()
  97. pos.y = pos.y + 0.5
  98. minetest.add_item(pos, {name = "mobs:bucket_milk"})
  99. end
  100. self.gotten = true -- milked
  101. return
  102. end
  103. end,
  104. on_replace = function(self, pos, oldnode, newnode)
  105. self.food = (self.food or 0) + 1
  106. -- if cow replaces 8x grass then it can be milked again
  107. if self.food >= 8 then
  108. self.food = 0
  109. self.gotten = false
  110. end
  111. end,
  112. })
  113. mobs:spawn({
  114. name = "mobs_animal:cow",
  115. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  116. neighbors = {"group:grass"},
  117. min_light = 14,
  118. interval = 60,
  119. chance = 8000, -- 15000
  120. min_height = 5,
  121. max_height = 200,
  122. day_toggle = true,
  123. })
  124. mobs:register_egg("mobs_animal:cow", S("Cow"), "mobs_cow_inv.png")
  125. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  126. -- bucket of milk
  127. minetest.register_craftitem(":mobs:bucket_milk", {
  128. description = S("Bucket of Milk"),
  129. inventory_image = "mobs_bucket_milk.png",
  130. stack_max = 1,
  131. groups = {food_milk = 1, flammable = 3, drink = 1},
  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, drink = 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. })