bee.lua 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 = default and default.gui_bg .. default.gui_bg_img .. default.gui_slots or ""
  82. meta:set_string("formspec", "size[8,6]"
  83. .. gui_bg
  84. .. "image[3,0.8;0.8,0.8;mobs_bee_inv.png]"
  85. .. "list[current_name;beehive;4,0.5;1,1;]"
  86. .. "list[current_player;main;0,2.35;8,4;]"
  87. .. "listring[]")
  88. meta:get_inventory():set_size("beehive", 1)
  89. end,
  90. after_place_node = function(pos, placer, itemstack)
  91. if placer and placer:is_player() then
  92. minetest.set_node(pos, {name = "mobs:beehive", param2 = 1})
  93. if math.random(4) == 1 then
  94. minetest.add_entity(pos, "mobs_animal:bee")
  95. end
  96. end
  97. end,
  98. on_punch = function(pos, node, puncher)
  99. -- yep, bee's don't like having their home punched by players
  100. puncher:set_hp(puncher:get_hp() - 4)
  101. end,
  102. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  103. if listname == "beehive" then
  104. return 0
  105. end
  106. return stack:get_count()
  107. end,
  108. can_dig = function(pos,player)
  109. local meta = minetest.get_meta(pos)
  110. -- only dig beehive if no honey inside
  111. return meta:get_inventory():is_empty("beehive")
  112. end
  113. })
  114. -- beehive recipe
  115. minetest.register_craft({
  116. output = "mobs:beehive",
  117. recipe = {
  118. {"mobs:bee","mobs:bee","mobs:bee"}
  119. }
  120. })
  121. -- honey block
  122. minetest.register_node(":mobs:honey_block", {
  123. description = S("Honey Block"),
  124. tiles = {"mobs_honey_block.png"},
  125. groups = {snappy = 3, flammable = 2},
  126. sounds = default and default.node_sound_dirt_defaults()
  127. })
  128. -- recipe
  129. minetest.register_craft({
  130. output = "mobs:honey_block",
  131. recipe = {
  132. {"mobs:honey", "mobs:honey", "mobs:honey"},
  133. {"mobs:honey", "mobs:honey", "mobs:honey"},
  134. {"mobs:honey", "mobs:honey", "mobs:honey"}
  135. }
  136. })
  137. minetest.register_craft({
  138. output = "mobs:honey 9",
  139. recipe = {
  140. {"mobs:honey_block"}
  141. }
  142. })
  143. -- beehive workings
  144. minetest.register_abm({
  145. nodenames = {"mobs:beehive"},
  146. interval = 12,
  147. chance = 6,
  148. catch_up = false,
  149. action = function(pos, node)
  150. -- bee's only make honey during the day
  151. local tod = (minetest.get_timeofday() or 0) * 24000
  152. if tod < 5500 or tod > 18500 then
  153. return
  154. end
  155. -- is hive full?
  156. local meta = minetest.get_meta(pos)
  157. if not meta then return end -- for older beehives
  158. local inv = meta:get_inventory()
  159. local honey = inv:get_stack("beehive", 1):get_count()
  160. -- is hive full?
  161. if honey > 11 then
  162. return
  163. end
  164. -- no flowers no honey, nuff said!
  165. if #minetest.find_nodes_in_area_under_air(
  166. {x = pos.x - 4, y = pos.y - 3, z = pos.z - 4},
  167. {x = pos.x + 4, y = pos.y + 3, z = pos.z + 4},
  168. "group:flower") > 3 then
  169. inv:add_item("beehive", "mobs:honey")
  170. end
  171. end
  172. })