bunny.lua 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. local S = mobs.intllib_animal
  2. -- Bunny by ExeterDad
  3. mobs:register_mob("mobs_animal:bunny", {
  4. type = "animal",
  5. passive = true,
  6. reach = 1,
  7. stepheight = 0.6,
  8. hp_min = 1,
  9. hp_max = 4,
  10. armor = 200,
  11. collisionbox = {-0.268, -0.5, -0.268, 0.268, 0.167, 0.268},
  12. visual = "mesh",
  13. mesh = "mobs_bunny.b3d",
  14. drawtype = "front",
  15. textures = {
  16. {"mobs_bunny_grey.png"},
  17. {"mobs_bunny_brown.png"},
  18. {"mobs_bunny_white.png"}
  19. },
  20. sounds = {},
  21. makes_footstep_sound = false,
  22. walk_velocity = 1,
  23. run_velocity = 2,
  24. runaway = true,
  25. runaway_from = {"mobs_animal:pumba", "player"},
  26. jump = true,
  27. jump_height = 6,
  28. drops = {
  29. {name = "mobs:rabbit_raw", chance = 1, min = 1, max = 1},
  30. {name = "mobs:rabbit_hide", chance = 1, min = 0, max = 1}
  31. },
  32. water_damage = 0.01,
  33. lava_damage = 4,
  34. light_damage = 0,
  35. fear_height = 2,
  36. animation = {
  37. speed_normal = 15,
  38. stand_start = 1,
  39. stand_end = 15,
  40. walk_start = 16,
  41. walk_end = 24,
  42. punch_start = 16,
  43. punch_end = 24
  44. },
  45. follow = {"farming:carrot", "farming_plus:carrot_item", "default:grass_1"},
  46. view_range = 8,
  47. replace_rate = 10,
  48. replace_what = {"farming:carrot_7", "farming:carrot_8", "farming_plus:carrot"},
  49. replace_with = "air",
  50. on_rightclick = function(self, clicker)
  51. -- feed or tame
  52. if mobs:feed_tame(self, clicker, 4, true, true) then return end
  53. if mobs:protect(self, clicker) then return end
  54. if mobs:capture_mob(self, clicker, 30, 50, 80, false, nil) then return end
  55. -- Monty Python tribute
  56. local item = clicker:get_wielded_item()
  57. local player_name = clicker:get_player_name()
  58. if self.owner == player_name
  59. and item:get_name() == "mobs:lava_orb" then
  60. -- take orb
  61. if not mobs.is_creative(clicker:get_player_name()) then
  62. item:take_item()
  63. clicker:set_wielded_item(item)
  64. end
  65. -- set special bunny attributes
  66. local staticdata = minetest.serialize({
  67. type = "monster",
  68. attack_type = "dogfight",
  69. hp_max = 20,
  70. health = 20,
  71. damage = 5,
  72. run_velocity = 3,
  73. passive = false,
  74. runaway = false,
  75. runaway_from = {},
  76. runaway_timer = 0,
  77. tamed = false,
  78. base_texture = {"mobs_bunny_evil.png"}
  79. })
  80. -- add evil bunny
  81. local obj = minetest.add_entity(
  82. self.object:get_pos(), "mobs_animal:bunny", staticdata)
  83. -- remove old bunny
  84. if obj:get_luaentity() then
  85. mobs:remove(self, true)
  86. end
  87. end
  88. end,
  89. on_spawn = function(self)
  90. local pos = self.object:get_pos() ; pos.y = pos.y - 1
  91. -- white snowy bunny
  92. if minetest.find_node_near(pos, 1,
  93. {"default:snow", "default:snowblock", "default:dirt_with_snow"}) then
  94. self.base_texture = {"mobs_bunny_white.png"}
  95. self.object:set_properties({textures = self.base_texture})
  96. -- brown desert bunny
  97. elseif minetest.find_node_near(pos, 1,
  98. {"default:desert_sand", "default:desert_stone"}) then
  99. self.base_texture = {"mobs_bunny_brown.png"}
  100. self.object:set_properties({textures = self.base_texture})
  101. -- grey stone bunny
  102. elseif minetest.find_node_near(pos, 1,
  103. {"default:stone", "default:gravel"}) then
  104. self.base_texture = {"mobs_bunny_grey.png"}
  105. self.object:set_properties({textures = self.base_texture})
  106. end
  107. return true -- run only once, false/nil runs every activation
  108. end
  109. })
  110. local spawn_on = "default:dirt_with_grass"
  111. if minetest.get_modpath("ethereal") then
  112. spawn_on = "ethereal:prairie_dirt"
  113. end
  114. if not mobs.custom_spawn_animal then
  115. mobs:spawn({
  116. name = "mobs_animal:bunny",
  117. nodes = {spawn_on},
  118. neighbors = {"group:grass"},
  119. min_light = 14,
  120. interval = 60,
  121. chance = 8000,
  122. min_height = 5,
  123. max_height = 200,
  124. day_toggle = true
  125. })
  126. end
  127. mobs:register_egg("mobs_animal:bunny", S("Bunny"), "mobs_bunny_inv.png", 0)
  128. mobs:alias_mob("mobs:bunny", "mobs_animal:bunny") -- compatibility
  129. -- raw rabbit
  130. minetest.register_craftitem(":mobs:rabbit_raw", {
  131. description = S("Raw Rabbit"),
  132. inventory_image = "mobs_rabbit_raw.png",
  133. on_use = minetest.item_eat(3),
  134. groups = {food_meat_raw = 1, food_rabbit_raw = 1, flammable = 2}
  135. })
  136. -- cooked rabbit
  137. minetest.register_craftitem(":mobs:rabbit_cooked", {
  138. description = S("Cooked Rabbit"),
  139. inventory_image = "mobs_rabbit_cooked.png",
  140. on_use = minetest.item_eat(5),
  141. groups = {food_meat = 1, food_rabbit = 1, flammable = 2}
  142. })
  143. minetest.register_craft({
  144. type = "cooking",
  145. output = "mobs:rabbit_cooked",
  146. recipe = "mobs:rabbit_raw",
  147. cooktime = 5
  148. })
  149. -- rabbit hide
  150. minetest.register_craftitem(":mobs:rabbit_hide", {
  151. description = S("Rabbit Hide"),
  152. inventory_image = "mobs_rabbit_hide.png",
  153. groups = {flammable = 2, pelt = 1}
  154. })
  155. minetest.register_craft({
  156. type = "fuel",
  157. recipe = "mobs:rabbit_hide",
  158. burntime = 2
  159. })
  160. minetest.register_craft({
  161. output = "mobs:leather",
  162. recipe = {
  163. {"mobs:rabbit_hide", "mobs:rabbit_hide"},
  164. {"mobs:rabbit_hide", "mobs:rabbit_hide"}
  165. }
  166. })