cow.lua 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. local S = mobs.intllib
  2. -- Cow by Krupnovpavel (additional texture by JurajVajda)
  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.x",
  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. speed_normal = 15,
  38. speed_run = 15,
  39. stand_start = 0,
  40. stand_end = 30,
  41. walk_start = 35,
  42. walk_end = 65,
  43. run_start = 105,
  44. run_end = 135,
  45. punch_start = 70,
  46. punch_end = 100,
  47. },
  48. follow = {"farming:wheat", "default:grass_1"},
  49. view_range = 8,
  50. replace_rate = 10,
  51. replace_what = {
  52. {"group:grass", "air", 0},
  53. {"default:dirt_with_grass", "default:dirt", -1}
  54. },
  55. fear_height = 2,
  56. on_rightclick = function(self, clicker)
  57. -- feed or tame
  58. if mobs:feed_tame(self, clicker, 8, true, true) then
  59. -- if fed 7x wheat or grass then cow can be milked again
  60. if self.food and self.food > 6 then
  61. self.gotten = false
  62. end
  63. return
  64. end
  65. if mobs:protect(self, clicker) then return end
  66. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  67. local tool = clicker:get_wielded_item()
  68. local name = clicker:get_player_name()
  69. -- milk cow with empty bucket
  70. if tool:get_name() == "bucket:bucket_empty" then
  71. --if self.gotten == true
  72. if self.child == true then
  73. return
  74. end
  75. if self.gotten == true then
  76. minetest.chat_send_player(name,
  77. S("Cow already milked!"))
  78. return
  79. end
  80. local inv = clicker:get_inventory()
  81. tool:take_item()
  82. clicker:set_wielded_item(tool)
  83. if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
  84. clicker:get_inventory():add_item("main", "mobs:bucket_milk")
  85. else
  86. local pos = self.object:get_pos()
  87. pos.y = pos.y + 0.5
  88. minetest.add_item(pos, {name = "mobs:bucket_milk"})
  89. end
  90. self.gotten = true -- milked
  91. return
  92. end
  93. end,
  94. on_replace = function(self, pos, oldnode, newnode)
  95. self.food = (self.food or 0) + 1
  96. -- if cow replaces 8x grass then it can be milked again
  97. if self.food >= 8 then
  98. self.food = 0
  99. self.gotten = false
  100. end
  101. end,
  102. })
  103. mobs:spawn({
  104. name = "mobs_animal:cow",
  105. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  106. neighbors = {"group:grass"},
  107. min_light = 14,
  108. interval = 60,
  109. chance = 8000, -- 15000
  110. min_height = 5,
  111. max_height = 200,
  112. day_toggle = true,
  113. })
  114. mobs:register_egg("mobs_animal:cow", S("Cow"), "default_grass.png", 1)
  115. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  116. -- bucket of milk
  117. minetest.register_craftitem(":mobs:bucket_milk", {
  118. description = S("Bucket of Milk"),
  119. inventory_image = "mobs_bucket_milk.png",
  120. stack_max = 1,
  121. on_use = minetest.item_eat(8, 'bucket:bucket_empty'),
  122. groups = {food_milk = 1, flammable = 3},
  123. })
  124. -- glass of milk
  125. minetest.register_craftitem(":mobs:glass_milk", {
  126. description = S("Glass of Milk"),
  127. inventory_image = "mobs_glass_milk.png",
  128. on_use = minetest.item_eat(2, 'vessels:drinking_glass'),
  129. groups = {food_milk_glass = 1, flammable = 3, vessel = 1},
  130. })
  131. minetest.register_craft({
  132. type = "shapeless",
  133. output = "mobs:glass_milk 4",
  134. recipe = {
  135. 'vessels:drinking_glass', 'vessels:drinking_glass',
  136. 'vessels:drinking_glass', 'vessels:drinking_glass',
  137. 'mobs:bucket_milk'
  138. },
  139. replacements = { {"mobs:bucket_milk", "bucket:bucket_empty"} }
  140. })
  141. minetest.register_craft({
  142. type = "shapeless",
  143. output = "mobs:bucket_milk",
  144. recipe = {
  145. 'mobs:glass_milk', 'mobs:glass_milk',
  146. 'mobs:glass_milk', 'mobs:glass_milk',
  147. 'bucket:bucket_empty'
  148. },
  149. replacements = { {"mobs:glass_milk", "vessels:drinking_glass 4"} }
  150. })
  151. -- butter
  152. minetest.register_craftitem(":mobs:butter", {
  153. description = S("Butter"),
  154. inventory_image = "mobs_butter.png",
  155. on_use = minetest.item_eat(1),
  156. groups = {food_butter = 1, flammable = 2},
  157. })
  158. if minetest.get_modpath("farming") and farming and farming.mod then
  159. minetest.register_craft({
  160. type = "shapeless",
  161. output = "mobs:butter",
  162. recipe = {"mobs:bucket_milk", "farming:salt"},
  163. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  164. })
  165. else -- some saplings are high in sodium so makes a good replacement item
  166. minetest.register_craft({
  167. type = "shapeless",
  168. output = "mobs:butter",
  169. recipe = {"mobs:bucket_milk", "default:sapling"},
  170. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  171. })
  172. end
  173. -- cheese wedge
  174. minetest.register_craftitem(":mobs:cheese", {
  175. description = S("Cheese"),
  176. inventory_image = "mobs_cheese.png",
  177. on_use = minetest.item_eat(4),
  178. groups = {food_cheese = 1, flammable = 2},
  179. })
  180. minetest.register_craft({
  181. type = "cooking",
  182. output = "mobs:cheese",
  183. recipe = "mobs:bucket_milk",
  184. cooktime = 5,
  185. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  186. })
  187. -- cheese block
  188. minetest.register_node(":mobs:cheeseblock", {
  189. description = S("Cheese Block"),
  190. tiles = {"mobs_cheeseblock.png"},
  191. is_ground_content = false,
  192. groups = {crumbly = 3},
  193. sounds = default.node_sound_dirt_defaults()
  194. })
  195. minetest.register_craft({
  196. output = "mobs:cheeseblock",
  197. recipe = {
  198. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  199. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  200. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  201. }
  202. })
  203. minetest.register_craft({
  204. output = "mobs:cheese 9",
  205. recipe = {
  206. {'mobs:cheeseblock'},
  207. }
  208. })