bee.lua 4.8 KB

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