bee.lua 4.3 KB

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