cow.lua 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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 = 1, max = 2},
  32. {name = 'bonemeal:bone', chance = 2, min = 1, max = 10},
  33. },
  34. water_damage = 1,
  35. lava_damage = 5,
  36. light_damage = 0,
  37. animation = {
  38. speed_normal = 15,
  39. speed_run = 15,
  40. stand_start = 0,
  41. stand_end = 30,
  42. walk_start = 35,
  43. walk_end = 65,
  44. run_start = 105,
  45. run_end = 135,
  46. punch_start = 70,
  47. punch_end = 100,
  48. },
  49. follow = "farming:wheat",
  50. view_range = 8,
  51. replace_rate = 10,
  52. replace_what = {"default:grass_3", "default:grass_4", "default:grass_5", "group:grain"},
  53. replace_with = "air",
  54. fear_height = 2,
  55. on_rightclick = function(self, clicker)
  56. if mobs:feed_tame(self, clicker, 8, true, true) then return end
  57. if mobs:protect(self, clicker) then return end
  58. if mobs:capture_mob(self, clicker, 0, 5, 60, false, nil) then return end
  59. local tool = clicker:get_wielded_item()
  60. local name = clicker:get_player_name()
  61. if tool:get_name() == "bucket:bucket_empty" then
  62. if self.child == true then
  63. return
  64. end
  65. if self.gotten == true then
  66. minetest.chat_send_player(name,
  67. S("Cow already milked!"))
  68. return
  69. end
  70. local inv = clicker:get_inventory()
  71. tool:take_item()
  72. clicker:set_wielded_item(tool)
  73. if inv:room_for_item("main", {name = "mobs:bucket_milk"}) then
  74. clicker:get_inventory():add_item("main", "mobs:bucket_milk")
  75. else
  76. local pos = self.object:get_pos()
  77. pos.y = pos.y + 0.5
  78. minetest.add_item(pos, {name = "mobs:bucket_milk"})
  79. end
  80. self.gotten = true -- milked
  81. return
  82. end
  83. end,
  84. on_replace = function(self, pos, oldnode, newnode)
  85. self.food = (self.food or 0) + 1
  86. if self.food >= 8 then
  87. self.food = 0
  88. self.gotten = false
  89. end
  90. end,
  91. })
  92. mobs:spawn({
  93. name = "mobs_animal:cow",
  94. nodes = {"default:dirt_with_grass", "ethereal:green_dirt"},
  95. neighbors = {"group:grass"},
  96. min_light = 14,
  97. interval = 60,
  98. chance = 8000, -- 15000
  99. min_height = 5,
  100. max_height = 200,
  101. day_toggle = true,
  102. })
  103. mobs:register_egg("mobs_animal:cow", S("Cow"), "default_grass.png", 1)
  104. mobs:alias_mob("mobs:cow", "mobs_animal:cow") -- compatibility
  105. -- bucket of milk
  106. minetest.register_craftitem(":mobs:bucket_milk", {
  107. description = S("Bucket of Milk"),
  108. inventory_image = "mobs_bucket_milk.png",
  109. stack_max = 1,
  110. on_use = minetest.item_eat(8, 'bucket:bucket_empty'),
  111. groups = {food_milk = 1, flammable = 3},
  112. })
  113. -- butter
  114. minetest.register_craftitem(":mobs:butter", {
  115. description = S("Butter"),
  116. inventory_image = "mobs_butter.png",
  117. on_use = minetest.item_eat(1),
  118. groups = {food_butter = 1, flammable = 2},
  119. })
  120. if minetest.get_modpath("farming") and farming and farming.mod then
  121. minetest.register_craft({
  122. type = "shapeless",
  123. output = "mobs:butter",
  124. recipe = {"mobs:bucket_milk", "farming:salt"},
  125. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  126. })
  127. else -- some saplings are high in sodium so makes a good replacement item
  128. minetest.register_craft({
  129. type = "shapeless",
  130. output = "mobs:butter",
  131. recipe = {"mobs:bucket_milk", "default:sapling"},
  132. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  133. })
  134. end
  135. -- cheese wedge
  136. minetest.register_craftitem(":mobs:cheese", {
  137. description = S("Cheese"),
  138. inventory_image = "mobs_cheese.png",
  139. on_use = minetest.item_eat(4),
  140. groups = {food_cheese = 1, flammable = 2},
  141. })
  142. minetest.register_craft({
  143. type = "cooking",
  144. output = "mobs:cheese",
  145. recipe = "mobs:bucket_milk",
  146. cooktime = 5,
  147. replacements = {{ "mobs:bucket_milk", "bucket:bucket_empty"}}
  148. })
  149. -- cheese block
  150. minetest.register_node(":mobs:cheeseblock", {
  151. description = S("Cheese Block"),
  152. tiles = {"mobs_cheeseblock.png"},
  153. is_ground_content = false,
  154. groups = {crumbly = 3},
  155. sounds = default.node_sound_dirt_defaults()
  156. })
  157. minetest.register_craft({
  158. output = "mobs:cheeseblock",
  159. recipe = {
  160. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  161. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  162. {'mobs:cheese', 'mobs:cheese', 'mobs:cheese'},
  163. }
  164. })
  165. minetest.register_craft({
  166. output = "mobs:cheese 9",
  167. recipe = {
  168. {'mobs:cheeseblock'},
  169. }
  170. })