bee.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. local S = mobs.intllib_animal
  2. -- Bee by KrupnoPavel (.b3d model by sirrobzeroone)
  3. mobs:register_mob("mobs_animal:bee", {
  4. type = "animal",
  5. passive = true,
  6. hp_min = 1,
  7. hp_max = 2,
  8. armor = 200,
  9. collisionbox = {-0.2, -0.01, -0.2, 0.2, 0.5, 0.2},
  10. visual = "mesh",
  11. mesh = "mobs_bee.b3d",
  12. textures = {
  13. {"mobs_bee.png"}
  14. },
  15. blood_texture = "mobs_bee_inv.png",
  16. blood_amount = 1,
  17. makes_footstep_sound = false,
  18. sounds = {
  19. random = "mobs_bee"
  20. },
  21. walk_velocity = 1,
  22. jump = true,
  23. drops = {
  24. {name = "mobs:honey", chance = 2, min = 1, max = 2}
  25. },
  26. water_damage = 1,
  27. lava_damage = 2,
  28. light_damage = 0,
  29. fall_damage = 0,
  30. fall_speed = -3,
  31. animation = {
  32. speed_normal = 15,
  33. stand_start = 0,
  34. stand_end = 30,
  35. walk_start = 35,
  36. walk_end = 65
  37. },
  38. on_rightclick = function(self, clicker)
  39. mobs:capture_mob(self, clicker, 50, 90, 0, true, "mobs_animal:bee")
  40. end,
  41. -- after_activate = function(self, staticdata, def, dtime)
  42. -- print ("------", self.name, dtime, self.health)
  43. -- end,
  44. })
  45. if not mobs.custom_spawn_animal then
  46. mobs:spawn({
  47. name = "mobs_animal:bee",
  48. nodes = {"group:flower"},
  49. min_light = 14,
  50. interval = 60,
  51. chance = 7000,
  52. min_height = 3,
  53. max_height = 200,
  54. day_toggle = true
  55. })
  56. end
  57. -- spawn egg
  58. mobs:register_egg("mobs_animal:bee", S("Bee"), "mobs_bee_inv.png")
  59. -- compatibility (only required if moving from old mobs to mobs_redo)
  60. mobs:alias_mob("mobs:bee", "mobs_animal:bee")
  61. -- honey
  62. minetest.register_craftitem(":mobs:honey", {
  63. description = S("Honey"),
  64. inventory_image = "mobs_honey_inv.png",
  65. on_use = minetest.item_eat(4),
  66. groups = {food_honey = 1, food_sugar = 1, flammable = 1}
  67. })
  68. -- beehive (when placed spawns bee)
  69. minetest.register_node(":mobs:beehive", {
  70. description = S("Beehive"),
  71. drawtype = "plantlike",
  72. tiles = {"mobs_beehive.png"},
  73. inventory_image = "mobs_beehive.png",
  74. paramtype = "light",
  75. sunlight_propagates = true,
  76. walkable = true,
  77. groups = {oddly_breakable_by_hand = 3, flammable = 1, disable_suffocation = 1},
  78. sounds = default and default.node_sound_defaults(),
  79. on_construct = function(pos)
  80. local meta = minetest.get_meta(pos)
  81. local gui_bg = ""
  82. if default then
  83. gui_bg = default.gui_bg .. default.gui_bg_img .. default.gui_slots
  84. end
  85. meta:set_string("formspec", "size[8,6]"
  86. .. gui_bg
  87. .. "image[3,0.8;0.8,0.8;mobs_bee_inv.png]"
  88. .. "list[current_name;beehive;4,0.5;1,1;]"
  89. .. "list[current_player;main;0,2.35;8,4;]"
  90. .. "listring[]")
  91. meta:get_inventory():set_size("beehive", 1)
  92. end,
  93. after_place_node = function(pos, placer, itemstack)
  94. if placer and placer:is_player() then
  95. minetest.set_node(pos, {name = "mobs:beehive", param2 = 1})
  96. if math.random(4) == 1 then
  97. minetest.add_entity(pos, "mobs_animal:bee")
  98. end
  99. end
  100. end,
  101. on_punch = function(pos, node, puncher)
  102. -- yep, bee's don't like having their home punched by players
  103. puncher:set_hp(puncher:get_hp() - 4)
  104. end,
  105. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  106. if listname == "beehive" then
  107. return 0
  108. end
  109. return stack:get_count()
  110. end,
  111. can_dig = function(pos,player)
  112. local meta = minetest.get_meta(pos)
  113. -- only dig beehive if no honey inside
  114. return meta:get_inventory():is_empty("beehive")
  115. end
  116. })
  117. -- beehive recipe
  118. minetest.register_craft({
  119. output = "mobs:beehive",
  120. recipe = {
  121. {"mobs:bee","mobs:bee","mobs:bee"}
  122. }
  123. })
  124. -- honey block
  125. minetest.register_node(":mobs:honey_block", {
  126. description = S("Honey Block"),
  127. tiles = {"mobs_honey_block.png"},
  128. groups = {snappy = 3, flammable = 2},
  129. sounds = default and default.node_sound_dirt_defaults()
  130. })
  131. -- recipe
  132. minetest.register_craft({
  133. output = "mobs:honey_block",
  134. recipe = {
  135. {"mobs:honey", "mobs:honey", "mobs:honey"},
  136. {"mobs:honey", "mobs:honey", "mobs:honey"},
  137. {"mobs:honey", "mobs:honey", "mobs:honey"}
  138. }
  139. })
  140. minetest.register_craft({
  141. output = "mobs:honey 9",
  142. recipe = {
  143. {"mobs:honey_block"}
  144. }
  145. })
  146. -- beehive workings
  147. minetest.register_abm({
  148. nodenames = {"mobs:beehive"},
  149. interval = 12,
  150. chance = 6,
  151. catch_up = false,
  152. action = function(pos, node)
  153. -- bee's only make honey during the day
  154. local tod = (minetest.get_timeofday() or 0) * 24000
  155. if tod < 5500 or tod > 18500 then
  156. return
  157. end
  158. -- is hive full?
  159. local meta = minetest.get_meta(pos)
  160. if not meta then return end -- for older beehives
  161. local inv = meta:get_inventory()
  162. local honey = inv:get_stack("beehive", 1):get_count()
  163. -- is hive full?
  164. if honey > 11 then
  165. return
  166. end
  167. -- no flowers no honey, nuff said!
  168. if #minetest.find_nodes_in_area_under_air(
  169. {x = pos.x - 4, y = pos.y - 3, z = pos.z - 4},
  170. {x = pos.x + 4, y = pos.y + 3, z = pos.z + 4},
  171. "group:flower") > 3 then
  172. inv:add_item("beehive", "mobs:honey")
  173. end
  174. end
  175. })