cow.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 = {
  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. -- milk cow with empty bucket
  83. if tool:get_name() == "bucket:bucket_empty" then
  84. --if self.gotten == true
  85. if self.child == true then
  86. return
  87. end
  88. if self.gotten == true then
  89. minetest.chat_send_player(name,
  90. S("Cow already milked!"))
  91. return
  92. end
  93. local inv = clicker:get_inventory()
  94. tool:take_item()
  95. clicker:set_wielded_item(tool)
  96. if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
  97. clicker:get_inventory():add_item("main", "mobs:bucket_milk")
  98. else
  99. local pos = self.object:get_pos()
  100. pos.y = pos.y + 0.5
  101. minetest.add_item(pos, {name = "mobs:bucket_milk"})
  102. end
  103. self.gotten = true -- milked
  104. return
  105. end
  106. end,
  107. on_replace = function(self, pos, oldnode, newnode)
  108. self.food = (self.food or 0) + 1
  109. -- if cow replaces 8x grass then it can be milked again
  110. if self.food >= 8 then
  111. self.food = 0
  112. self.gotten = false
  113. end
  114. end,
  115. })
  116. if not mobs.custom_spawn_animal then
  117. mobs:spawn({
  118. name = "mobs_animal:cow",
  119. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  120. neighbors = {"group:grass"},
  121. min_light = 14,
  122. interval = 60,
  123. chance = 8000, -- 15000
  124. min_height = 5,
  125. max_height = 200,
  126. day_toggle = true,
  127. })
  128. end
  129. mobs:register_egg("mobs_animal:cow", S("Cow"), "mobs_cow_inv.png")
  130. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  131. -- bucket of milk
  132. minetest.register_craftitem(":mobs:bucket_milk", {
  133. description = S("Bucket of Milk"),
  134. inventory_image = "mobs_bucket_milk.png",
  135. stack_max = 1,
  136. on_use = minetest.item_eat(8, "bucket:bucket_empty"),
  137. groups = {food_milk = 1, flammable = 3, drink = 1},
  138. })
  139. -- glass of milk
  140. minetest.register_craftitem(":mobs:glass_milk", {
  141. description = S("Glass of Milk"),
  142. inventory_image = "mobs_glass_milk.png",
  143. on_use = minetest.item_eat(2, "vessels:drinking_glass"),
  144. groups = {food_milk_glass = 1, flammable = 3, vessel = 1, drink = 1},
  145. })
  146. minetest.register_craft({
  147. -- type = "shapeless",
  148. output = "mobs:glass_milk 4",
  149. recipe = {
  150. {"vessels:drinking_glass", "vessels:drinking_glass"},
  151. {"vessels:drinking_glass", "vessels:drinking_glass"},
  152. {"mobs:bucket_milk", ""}
  153. },
  154. replacements = { {"mobs:bucket_milk", "bucket:bucket_empty"} }
  155. })
  156. minetest.register_craft({
  157. -- type = "shapeless",
  158. output = "mobs:bucket_milk",
  159. recipe = {
  160. {"group:food_milk_glass", "group:food_milk_glass"},
  161. {"group:food_milk_glass", "group:food_milk_glass"},
  162. {"bucket:bucket_empty", ""}
  163. },
  164. replacements = {
  165. {"group:food_milk_glass", "vessels:drinking_glass 4"}
  166. }
  167. })
  168. -- butter
  169. minetest.register_craftitem(":mobs:butter", {
  170. description = S("Butter"),
  171. inventory_image = "mobs_butter.png",
  172. on_use = minetest.item_eat(1),
  173. groups = {food_butter = 1, flammable = 2}
  174. })
  175. if minetest.get_modpath("farming") and farming and farming.mod then
  176. minetest.register_craft({
  177. type = "shapeless",
  178. output = "mobs:butter",
  179. recipe = {"mobs:bucket_milk", "farming:salt"},
  180. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  181. })
  182. else -- some saplings are high in sodium so makes a good replacement item
  183. minetest.register_craft({
  184. type = "shapeless",
  185. output = "mobs:butter",
  186. recipe = {"mobs:bucket_milk", "default:sapling"},
  187. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  188. })
  189. end
  190. -- cheese wedge
  191. minetest.register_craftitem(":mobs:cheese", {
  192. description = S("Cheese"),
  193. inventory_image = "mobs_cheese.png",
  194. on_use = minetest.item_eat(4),
  195. groups = {food_cheese = 1, flammable = 2},
  196. })
  197. minetest.register_craft({
  198. type = "cooking",
  199. output = "mobs:cheese",
  200. recipe = "mobs:bucket_milk",
  201. cooktime = 5,
  202. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  203. })
  204. -- cheese block
  205. minetest.register_node(":mobs:cheeseblock", {
  206. description = S("Cheese Block"),
  207. tiles = {"mobs_cheeseblock.png"},
  208. is_ground_content = false,
  209. groups = {oddly_breakable_by_hand = 3},
  210. sounds = default.node_sound_dirt_defaults()
  211. })
  212. minetest.register_craft({
  213. output = "mobs:cheeseblock",
  214. recipe = {
  215. {"group:food_cheese", "group:food_cheese", "group:food_cheese"},
  216. {"group:food_cheese", "group:food_cheese", "group:food_cheese"},
  217. {"group:food_cheese", "group:food_cheese", "group:food_cheese"},
  218. }
  219. })
  220. minetest.register_craft({
  221. output = "mobs:cheese 9",
  222. recipe = {
  223. {"mobs:cheeseblock"},
  224. }
  225. })