cow.lua 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. local S = mobs.intllib_animal
  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 = {
  58. "farming:wheat", "default:grass_1", "farming:barley",
  59. "farming:oat", "farming:rye"
  60. },
  61. view_range = 8,
  62. replace_rate = 10,
  63. replace_what = {
  64. {"group:grass", "air", 0},
  65. {"default:dirt_with_grass", "default:dirt", -1}
  66. },
  67. -- stay_near = {{"farming:straw", "group:grass"}, 10},
  68. fear_height = 2,
  69. on_rightclick = function(self, clicker)
  70. -- feed or tame
  71. if mobs:feed_tame(self, clicker, 8, true, true) then
  72. -- if fed 7x wheat or grass then cow can be milked again
  73. if self.food and self.food > 6 then
  74. self.gotten = false
  75. end
  76. return
  77. end
  78. if mobs:protect(self, clicker) then return end
  79. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  80. local tool = clicker:get_wielded_item()
  81. local name = clicker:get_player_name()
  82. local item = tool:get_name()
  83. -- milk cow with empty bucket
  84. if item == "bucket:bucket_empty"
  85. or item == "wooden_bucket:bucket_wood_empty" then
  86. --if self.gotten == true
  87. if self.child == true then
  88. return
  89. end
  90. if self.gotten == true then
  91. minetest.chat_send_player(name,
  92. S("Cow already milked!"))
  93. return
  94. end
  95. local inv = clicker:get_inventory()
  96. tool:take_item()
  97. clicker:set_wielded_item(tool)
  98. -- which bucket are we using
  99. local ret_item = "mobs:bucket_milk"
  100. if item == "wooden_bucket:bucket_wood_empty" then
  101. ret_item = "mobs:wooden_bucket_milk"
  102. end
  103. if inv:room_for_item("main", {name = ret_item}) then
  104. clicker:get_inventory():add_item("main", ret_item)
  105. else
  106. local pos = self.object:get_pos()
  107. pos.y = pos.y + 0.5
  108. minetest.add_item(pos, {name = ret_item})
  109. end
  110. self.gotten = true -- milked
  111. return
  112. end
  113. end,
  114. on_replace = function(self, pos, oldnode, newnode)
  115. self.food = (self.food or 0) + 1
  116. -- if cow replaces 8x grass then it can be milked again
  117. if self.food >= 8 then
  118. self.food = 0
  119. self.gotten = false
  120. end
  121. end
  122. })
  123. if not mobs.custom_spawn_animal then
  124. mobs:spawn({
  125. name = "mobs_animal:cow",
  126. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  127. neighbors = {"group:grass"},
  128. min_light = 14,
  129. interval = 60,
  130. chance = 8000,
  131. min_height = 5,
  132. max_height = 200,
  133. day_toggle = true
  134. })
  135. end
  136. mobs:register_egg("mobs_animal:cow", S("Cow"), "mobs_cow_inv.png")
  137. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  138. -- bucket of milk
  139. minetest.register_craftitem(":mobs:bucket_milk", {
  140. description = S("Bucket of Milk"),
  141. inventory_image = "mobs_bucket_milk.png",
  142. stack_max = 1,
  143. on_use = minetest.item_eat(8, "bucket:bucket_empty"),
  144. groups = {food_milk = 1, flammable = 3, drink = 1},
  145. })
  146. -- glass of milk
  147. minetest.register_craftitem(":mobs:glass_milk", {
  148. description = S("Glass of Milk"),
  149. inventory_image = "mobs_glass_milk.png",
  150. on_use = minetest.item_eat(2, "vessels:drinking_glass"),
  151. groups = {food_milk_glass = 1, flammable = 3, vessel = 1, drink = 1},
  152. })
  153. minetest.register_craft({
  154. output = "mobs:glass_milk 4",
  155. recipe = {
  156. {"vessels:drinking_glass", "vessels:drinking_glass"},
  157. {"vessels:drinking_glass", "vessels:drinking_glass"},
  158. {"mobs:bucket_milk", ""}
  159. },
  160. replacements = {{"mobs:bucket_milk", "bucket:bucket_empty"}}
  161. })
  162. minetest.register_craft({
  163. output = "mobs:bucket_milk",
  164. recipe = {
  165. {"group:food_milk_glass", "group:food_milk_glass"},
  166. {"group:food_milk_glass", "group:food_milk_glass"},
  167. {"bucket:bucket_empty", ""}
  168. },
  169. replacements = {
  170. {"group:food_milk_glass", "vessels:drinking_glass 4"}
  171. }
  172. })
  173. -- butter
  174. minetest.register_craftitem(":mobs:butter", {
  175. description = S("Butter"),
  176. inventory_image = "mobs_butter.png",
  177. on_use = minetest.item_eat(1),
  178. groups = {food_butter = 1, flammable = 2}
  179. })
  180. local salt_item = "default:sapling" -- some saplings are high in sodium
  181. if minetest.get_modpath("farming") and farming and farming.mod then
  182. salt_item = "farming:salt"
  183. end
  184. minetest.register_craft({
  185. output = "mobs:butter",
  186. recipe = {{"mobs:bucket_milk", salt_item}},
  187. replacements = {{"mobs:bucket_milk", "bucket:bucket_empty"}}
  188. })
  189. -- cheese wedge
  190. minetest.register_craftitem(":mobs:cheese", {
  191. description = S("Cheese"),
  192. inventory_image = "mobs_cheese.png",
  193. on_use = minetest.item_eat(4),
  194. groups = {food_cheese = 1, flammable = 2}
  195. })
  196. minetest.register_craft({
  197. type = "cooking",
  198. output = "mobs:cheese",
  199. recipe = "mobs:bucket_milk",
  200. cooktime = 5,
  201. replacements = {{"mobs:bucket_milk", "bucket:bucket_empty"}}
  202. })
  203. -- cheese block
  204. minetest.register_node(":mobs:cheeseblock", {
  205. description = S("Cheese Block"),
  206. tiles = {"mobs_cheeseblock.png"},
  207. is_ground_content = false,
  208. groups = {oddly_breakable_by_hand = 3},
  209. sounds = default.node_sound_dirt_defaults()
  210. })
  211. minetest.register_craft({
  212. output = "mobs:cheeseblock",
  213. recipe = {
  214. {"group:food_cheese", "group:food_cheese", "group:food_cheese"},
  215. {"group:food_cheese", "group:food_cheese", "group:food_cheese"},
  216. {"group:food_cheese", "group:food_cheese", "group:food_cheese"}
  217. }
  218. })
  219. minetest.register_craft({
  220. output = "mobs:cheese 9",
  221. recipe = {{"mobs:cheeseblock"}}
  222. })
  223. -- check for wooden bucket mod and add compatibility
  224. if minetest.get_modpath("wooden_bucket") then
  225. minetest.register_craftitem(":mobs:wooden_bucket_milk", {
  226. description = S("Wooden Bucket of Milk"),
  227. inventory_image = "mobs_wooden_bucket_milk.png",
  228. stack_max = 1,
  229. on_use = minetest.item_eat(8, "wooden_bucket:bucket_wood_empty"),
  230. groups = {food_milk = 1, flammable = 3, drink = 1}
  231. })
  232. minetest.register_craft({
  233. output = "mobs:glass_milk 4",
  234. recipe = {
  235. {"vessels:drinking_glass", "vessels:drinking_glass"},
  236. {"vessels:drinking_glass", "vessels:drinking_glass"},
  237. {"mobs:wooden_bucket_milk", ""}
  238. },
  239. replacements = {{"mobs:wooden_bucket_milk", "wooden_bucket:bucket_wood_empty"}}
  240. })
  241. minetest.register_craft({
  242. output = "mobs:wooden_bucket_milk",
  243. recipe = {
  244. {"group:food_milk_glass", "group:food_milk_glass"},
  245. {"group:food_milk_glass", "group:food_milk_glass"},
  246. {"wooden_bucket:bucket_wood_empty", ""}
  247. },
  248. replacements = {
  249. {"group:food_milk_glass", "vessels:drinking_glass 4"}
  250. }
  251. })
  252. minetest.register_craft({
  253. output = "mobs:butter",
  254. recipe = {{"mobs:wooden_bucket_milk", salt_item}},
  255. replacements = {{"mobs:wooden_bucket_milk", "wooden_bucket:bucket_wood_empty"}}
  256. })
  257. end