bee.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. })
  40. mobs:spawn({
  41. name = "mobs_animal:bee",
  42. nodes = {"group:flower"},
  43. min_light = 10,
  44. chance = 9000,
  45. min_height = 0,
  46. day_toggle = true,
  47. })
  48. mobs:register_egg("mobs_animal:bee", S("Bee"), "mobs_bee_inv.png", 0)
  49. -- compatibility
  50. mobs:alias_mob("mobs:bee", "mobs_animal:bee")
  51. -- honey
  52. minetest.register_craftitem(":mobs:honey", {
  53. description = S("Honey"),
  54. inventory_image = "mobs_honey_inv.png",
  55. on_use = minetest.item_eat(6),
  56. })
  57. -- beehive (when placed spawns bee)
  58. minetest.register_node(":mobs:beehive", {
  59. description = S("Beehive"),
  60. drawtype = "plantlike",
  61. tiles = {"mobs_beehive.png"},
  62. inventory_image = "mobs_beehive.png",
  63. paramtype = "light",
  64. sunlight_propagates = true,
  65. walkable = true,
  66. groups = {oddly_breakable_by_hand = 3, flammable = 1},
  67. sounds = default.node_sound_defaults(),
  68. on_construct = function(pos)
  69. local meta = minetest.get_meta(pos)
  70. meta:set_string("formspec", "size[8,6]"
  71. ..default.gui_bg..default.gui_bg_img..default.gui_slots
  72. .. "image[3,0.8;0.8,0.8;mobs_bee_inv.png]"
  73. .. "list[current_name;beehive;4,0.5;1,1;]"
  74. .. "list[current_player;main;0,2.35;8,4;]"
  75. .. "listring[]")
  76. meta:get_inventory():set_size("beehive", 1)
  77. end,
  78. after_place_node = function(pos, placer, itemstack)
  79. if placer:is_player() then
  80. minetest.set_node(pos, {name = "mobs:beehive", param2 = 1})
  81. if math.random(1, 4) == 1 then
  82. minetest.add_entity(pos, "mobs_animal:bee")
  83. end
  84. end
  85. end,
  86. on_punch = function(pos, node, puncher)
  87. -- yep, bee's don't like having their home punched by players
  88. puncher:set_hp(puncher:get_hp() - 4)
  89. end,
  90. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  91. if listname == "beehive" then
  92. return 0
  93. end
  94. return stack:get_count()
  95. end,
  96. can_dig = function(pos,player)
  97. local meta = minetest.get_meta(pos)
  98. -- only dig beehive if no honey inside
  99. return meta:get_inventory():is_empty("beehive")
  100. end,
  101. })
  102. minetest.register_craft({
  103. output = "mobs:beehive",
  104. recipe = {
  105. {"mobs:bee","mobs:bee","mobs:bee"},
  106. }
  107. })
  108. -- honey block
  109. minetest.register_node(":mobs:honey_block", {
  110. description = S("Honey Block"),
  111. tiles = {"mobs_honey_block.png"},
  112. groups = {snappy = 3, flammable = 2},
  113. sounds = default.node_sound_dirt_defaults(),
  114. })
  115. minetest.register_craft({
  116. output = "mobs:honey_block",
  117. recipe = {
  118. {"mobs:honey", "mobs:honey", "mobs:honey"},
  119. {"mobs:honey", "mobs:honey", "mobs:honey"},
  120. {"mobs:honey", "mobs:honey", "mobs:honey"},
  121. }
  122. })
  123. minetest.register_craft({
  124. output = "mobs:honey 9",
  125. recipe = {
  126. {"mobs:honey_block"},
  127. }
  128. })
  129. -- beehive workings
  130. minetest.register_abm({
  131. nodenames = {"mobs:beehive"},
  132. interval = 6,
  133. chance = 6,
  134. catch_up = false,
  135. action = function(pos, node)
  136. -- bee's only make honey during the day
  137. local tod = (minetest.get_timeofday() or 0) * 24000
  138. if tod < 5500 or tod > 18500 then
  139. return
  140. end
  141. -- is hive full?
  142. local meta = minetest.get_meta(pos)
  143. if not meta then return end -- for older beehives
  144. local inv = meta:get_inventory()
  145. local honey = inv:get_stack("beehive", 1):get_count()
  146. -- is hive full?
  147. if honey > 19 then
  148. return
  149. end
  150. -- no flowers no honey, nuff said!
  151. if #minetest.find_nodes_in_area_under_air(
  152. {x = pos.x - 4, y = pos.y - 3, z = pos.z - 4},
  153. {x = pos.x + 4, y = pos.y + 3, z = pos.z + 4},
  154. "group:flower") > 3 then
  155. inv:add_item("beehive", "mobs:honey")
  156. end
  157. end
  158. })