init.lua 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814
  1. --Bees
  2. ------
  3. --Author Bas080
  4. --Version 2.2
  5. --License WTFPL
  6. --VARIABLES
  7. local bees = {}
  8. local formspecs = {}
  9. --FUNCTIONS
  10. function formspecs.hive_wild(pos, grafting)
  11. local spos = pos.x .. ',' .. pos.y .. ',' ..pos.z
  12. local formspec =
  13. 'size[8,9]'..
  14. 'list[nodemeta:'.. spos .. ';combs;1.5,3;5,1;]'..
  15. 'list[current_player;main;0,5;8,4;]'
  16. if grafting then
  17. formspec = formspec..'list[nodemeta:'.. spos .. ';queen;3.5,1;1,1;]'
  18. end
  19. return formspec
  20. end
  21. function formspecs.hive_artificial(pos)
  22. local spos = pos.x..','..pos.y..','..pos.z
  23. local formspec =
  24. 'size[8,9]'..
  25. 'list[nodemeta:'..spos..';queen;3.5,1;1,1;]'..
  26. 'list[nodemeta:'..spos..';frames;0,3;8,1;]'..
  27. 'list[current_player;main;0,5;8,4;]'
  28. return formspec
  29. end
  30. function bees.polinate_flower(pos, flower)
  31. local spawn_pos = { x=pos.x+math.random(-3,3) , y=pos.y+math.random(-3,3) , z=pos.z+math.random(-3,3) }
  32. local floor_pos = { x=spawn_pos.x , y=spawn_pos.y-1 , z=spawn_pos.z }
  33. local spawn = minetest.get_node(spawn_pos).name
  34. local floor = minetest.get_node(floor_pos).name
  35. if floor == 'default:dirt_with_grass' and spawn == 'air' then
  36. minetest.set_node(spawn_pos, {name=flower})
  37. end
  38. end
  39. --NODES
  40. minetest.register_node('bees:extractor', {
  41. description = 'honey extractor',
  42. tiles = {"bees_extractor.png", "bees_extractor.png", "bees_extractor.png", "bees_extractor.png", "bees_extractor.png", "bees_extractor_front.png"},
  43. paramtype2 = "facedir",
  44. groups = {choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1},
  45. on_construct = function(pos, node)
  46. local meta = minetest.get_meta(pos)
  47. local inv = meta:get_inventory()
  48. local pos = pos.x..','..pos.y..','..pos.z
  49. inv:set_size('frames_filled' ,1)
  50. inv:set_size('frames_emptied' ,1)
  51. inv:set_size('bottles_empty' ,1)
  52. inv:set_size('bottles_full' ,1)
  53. inv:set_size('wax',1)
  54. meta:set_string('formspec',
  55. 'size[8,9]'..
  56. --input
  57. 'list[nodemeta:'..pos..';frames_filled;2,1;1,1;]'..
  58. 'list[nodemeta:'..pos..';bottles_empty;2,3;1,1;]'..
  59. --output
  60. 'list[nodemeta:'..pos..';frames_emptied;5,0.5;1,1;]'..
  61. 'list[nodemeta:'..pos..';wax;5,2;1,1;]'..
  62. 'list[nodemeta:'..pos..';bottles_full;5,3.5;1,1;]'..
  63. --player inventory
  64. 'list[current_player;main;0,5;8,4;]'
  65. )
  66. end,
  67. on_timer = function(pos, node)
  68. local meta = minetest.get_meta(pos)
  69. local inv = meta:get_inventory()
  70. if not inv:contains_item('frames_filled','bees:frame_full') or not inv:contains_item('bottles_empty','vessels:glass_bottle') then
  71. return
  72. end
  73. if inv:room_for_item('frames_emptied', 'bees:frame_empty')
  74. and inv:room_for_item('wax','bees:wax')
  75. and inv:room_for_item('bottles_full', 'bees:bottle_honey') then
  76. --add to output
  77. inv:add_item('frames_emptied', 'bees:frame_empty')
  78. inv:add_item('wax', 'bees:wax')
  79. inv:add_item('bottles_full', 'bees:bottle_honey')
  80. --remove from input
  81. inv:remove_item('bottles_empty','vessels:glass_bottle')
  82. inv:remove_item('frames_filled','bees:frame_full')
  83. local p = {x=pos.x+math.random()-0.5, y=pos.y+math.random()-0.5, z=pos.z+math.random()-0.5}
  84. --wax flying all over the place
  85. minetest.add_particle({
  86. pos = {x=pos.x, y=pos.y, z=pos.z},
  87. vel = {x=math.random(-4,4),y=math.random(8),z=math.random(-4,4)},
  88. acc = {x=0,y=-6,z=0},
  89. expirationtime = 2,
  90. size = math.random(1,3),
  91. collisiondetection = false,
  92. texture = 'bees_wax_particle.png',
  93. })
  94. local timer = minetest.get_node_timer(pos)
  95. timer:start(5)
  96. else
  97. local timer = minetest.get_node_timer(pos)
  98. timer:start(1) -- Try again in 1 second
  99. end
  100. end,
  101. tube = {
  102. insert_object = function(pos, node, stack, direction)
  103. local meta = minetest.get_meta(pos)
  104. local inv = meta:get_inventory()
  105. local timer = minetest.get_node_timer(pos)
  106. if stack:get_name() == "bees:frame_full" then
  107. if inv:is_empty("frames_filled") then
  108. timer:start(5)
  109. end
  110. return inv:add_item("frames_filled",stack)
  111. elseif stack:get_name() == "vessels:glass_bottle" then
  112. if inv:is_empty("bottles_empty") then
  113. timer:start(5)
  114. end
  115. return inv:add_item("bottles_empty",stack)
  116. end
  117. return stack
  118. end,
  119. can_insert = function(pos,node,stack,direction)
  120. local meta = minetest.get_meta(pos)
  121. local inv = meta:get_inventory()
  122. if stack:get_name() == "bees:frame_full" then
  123. return inv:room_for_item("frames_filled",stack)
  124. elseif stack:get_name() == "vessels:glass_bottle" then
  125. return inv:room_for_item("bottles_empty",stack)
  126. end
  127. return false
  128. end,
  129. input_inventory = {"frames_emptied", "bottles_full", "wax"},
  130. connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
  131. },
  132. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  133. local timer = minetest.get_node_timer(pos)
  134. local meta = minetest.get_meta(pos)
  135. local inv = meta:get_inventory()
  136. if inv:get_stack(listname, 1):get_count() == stack:get_count() then -- inv was empty -> start the timer
  137. timer:start(5) --create a honey bottle and empty frame and wax every 5 seconds
  138. end
  139. end,
  140. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  141. if (listname == 'bottles_empty' and stack:get_name() == 'vessels:glass_bottle') or (listname == 'frames_filled' and stack:get_name() == 'bees:frame_full') then
  142. return stack:get_count()
  143. else
  144. return 0
  145. end
  146. end,
  147. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  148. return 0
  149. end,
  150. })
  151. minetest.register_node('bees:bees', {
  152. description = 'flying bees',
  153. drawtype = 'plantlike',
  154. paramtype = 'light',
  155. groups = { not_in_creative_inventory=1 },
  156. tiles = {
  157. {
  158. name='bees_strip.png',
  159. animation={type='vertical_frames', aspect_w=16,aspect_h=16, length=2.0}
  160. }
  161. },
  162. damage_per_second = 1,
  163. walkable = false,
  164. buildable_to = true,
  165. pointable = false,
  166. on_punch = function(pos, node, puncher)
  167. local health = puncher:get_hp()
  168. puncher:set_hp(health-2)
  169. end,
  170. })
  171. minetest.register_node('bees:hive_wild', {
  172. description = 'wild bee hive',
  173. tiles = {'bees_hive_wild.png','bees_hive_wild.png','bees_hive_wild.png', 'bees_hive_wild.png', 'bees_hive_wild_bottom.png'}, --Neuromancer's base texture
  174. drawtype = 'nodebox',
  175. paramtype = 'light',
  176. paramtype2 = 'wallmounted',
  177. drop = {
  178. max_items = 6,
  179. items = {
  180. { items = {'bees:honey_comb'}, rarity = 5}
  181. }
  182. },
  183. groups = {choppy=2,oddly_breakable_by_hand=2,flammable=3,attached_node=1},
  184. node_box = { --VanessaE's wild hive nodebox contribution
  185. type = 'fixed',
  186. fixed = {
  187. {-0.250000,-0.500000,-0.250000,0.250000,0.375000,0.250000}, --NodeBox 2
  188. {-0.312500,-0.375000,-0.312500,0.312500,0.250000,0.312500}, --NodeBox 4
  189. {-0.375000,-0.250000,-0.375000,0.375000,0.125000,0.375000}, --NodeBox 5
  190. {-0.062500,-0.500000,-0.062500,0.062500,0.500000,0.062500}, --NodeBox 6
  191. }
  192. },
  193. on_timer = function(pos)
  194. local meta = minetest.get_meta(pos)
  195. local inv = meta:get_inventory()
  196. local timer= minetest.get_node_timer(pos)
  197. local rad = 10
  198. local minp = {x=pos.x-rad, y=pos.y-rad, z=pos.z-rad}
  199. local maxp = {x=pos.x+rad, y=pos.y+rad, z=pos.z+rad}
  200. local flowers = minetest.find_nodes_in_area(minp, maxp, 'group:flower')
  201. if #flowers == 0 then
  202. inv:set_stack('queen', 1, '')
  203. meta:set_string('infotext', 'this colony died, not enough flowers in area')
  204. return
  205. end --not any flowers nearby The queen dies!
  206. if #flowers < 3 then return end --requires 2 or more flowers before can make honey
  207. local flower = flowers[math.random(#flowers)]
  208. bees.polinate_flower(flower, minetest.get_node(flower).name)
  209. local stacks = inv:get_list('combs')
  210. for k, v in pairs(stacks) do
  211. if inv:get_stack('combs', k):is_empty() then --then replace that with a full one and reset pro..
  212. inv:set_stack('combs',k,'bees:honey_comb')
  213. timer:start(1000/#flowers)
  214. return
  215. end
  216. end
  217. --what to do if all combs are filled
  218. end,
  219. on_construct = function(pos)
  220. minetest.get_node(pos).param2 = 0
  221. local meta = minetest.get_meta(pos)
  222. local inv = meta:get_inventory()
  223. local timer = minetest.get_node_timer(pos)
  224. meta:set_int('agressive', 1)
  225. timer:start(100+math.random(100))
  226. inv:set_size('queen', 1)
  227. inv:set_size('combs', 5)
  228. inv:set_stack('queen', 1, 'bees:queen')
  229. for i=1,math.random(3) do
  230. inv:set_stack('combs', i, 'bees:honey_comb')
  231. end
  232. end,
  233. on_punch = function(pos, node, puncher)
  234. local meta = minetest.get_meta(pos)
  235. local inv = meta:get_inventory()
  236. if inv:contains_item('queen','bees:queen') then
  237. local health = puncher:get_hp()
  238. puncher:set_hp(health-4)
  239. end
  240. end,
  241. on_metadata_inventory_take = function(pos, listname, index, stack, taker)
  242. local meta = minetest.get_meta(pos)
  243. local inv = meta:get_inventory()
  244. local timer= minetest.get_node_timer(pos)
  245. if listname == 'combs' and inv:contains_item('queen', 'bees:queen') then
  246. local health = taker:get_hp()
  247. timer:start(10)
  248. taker:set_hp(health-2)
  249. end
  250. end,
  251. on_metadata_inventory_put = function(pos, listname, index, stack, taker) --restart the colony by adding a queen
  252. local timer = minetest.get_node_timer(pos)
  253. if not timer:is_started() then
  254. timer:start(10)
  255. end
  256. end,
  257. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  258. if listname == 'queen' and stack:get_name() == 'bees:queen' then
  259. return 1
  260. else
  261. return 0
  262. end
  263. end,
  264. on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
  265. minetest.show_formspec(
  266. clicker:get_player_name(),
  267. 'bees:hive_artificial',
  268. formspecs.hive_wild(pos, (itemstack:get_name() == 'bees:grafting_tool'))
  269. )
  270. local meta = minetest.get_meta(pos)
  271. local inv = meta:get_inventory()
  272. if meta:get_int('agressive') == 1 and inv:contains_item('queen', 'bees:queen') then
  273. local health = clicker:get_hp()
  274. clicker:set_hp(health-4)
  275. else
  276. meta:set_int('agressive', 1)
  277. end
  278. end,
  279. can_dig = function(pos,player)
  280. local meta = minetest.get_meta(pos)
  281. local inv = meta:get_inventory()
  282. if inv:is_empty('queen') and inv:is_empty('combs') then
  283. return true
  284. else
  285. return false
  286. end
  287. end,
  288. after_dig_node = function(pos, oldnode, oldmetadata, user)
  289. local wielded if user:get_wielded_item() ~= nil then wielded = user:get_wielded_item() else return end
  290. if 'bees:grafting_tool' == wielded:get_name() then
  291. local inv = user:get_inventory()
  292. if inv then
  293. inv:add_item('main', ItemStack('bees:queen'))
  294. end
  295. end
  296. end
  297. })
  298. minetest.register_node('bees:hive_artificial', {
  299. description = 'bee hive',
  300. tiles = {'default_wood.png','default_wood.png','default_wood.png', 'default_wood.png','default_wood.png','bees_hive_artificial.png'},
  301. drawtype = 'nodebox',
  302. paramtype = 'light',
  303. paramtype2 = 'facedir',
  304. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3,wood=1},
  305. sounds = default.node_sound_wood_defaults(),
  306. node_box = {
  307. type = 'fixed',
  308. fixed = {
  309. {-4/8, 2/8, -4/8, 4/8, 3/8, 4/8},
  310. {-3/8, -4/8, -2/8, 3/8, 2/8, 3/8},
  311. {-3/8, 0/8, -3/8, 3/8, 2/8, -2/8},
  312. {-3/8, -4/8, -3/8, 3/8, -1/8, -2/8},
  313. {-3/8, -1/8, -3/8, -1/8, 0/8, -2/8},
  314. {1/8, -1/8, -3/8, 3/8, 0/8, -2/8},
  315. }
  316. },
  317. on_construct = function(pos)
  318. local timer = minetest.get_node_timer(pos)
  319. local meta = minetest.get_meta(pos)
  320. local inv = meta:get_inventory()
  321. meta:set_int('agressive', 1)
  322. inv:set_size('queen', 1)
  323. inv:set_size('frames', 8)
  324. meta:set_string('infotext','requires queen bee to function')
  325. end,
  326. on_rightclick = function(pos, node, clicker, itemstack)
  327. minetest.show_formspec(
  328. clicker:get_player_name(),
  329. 'bees:hive_artificial',
  330. formspecs.hive_artificial(pos)
  331. )
  332. local meta = minetest.get_meta(pos)
  333. local inv = meta:get_inventory()
  334. if meta:get_int('agressive') == 1 and inv:contains_item('queen', 'bees:queen') then
  335. local health = clicker:get_hp()
  336. clicker:set_hp(health-4)
  337. else
  338. meta:set_int('agressive', 1)
  339. end
  340. end,
  341. on_timer = function(pos,elapsed)
  342. local meta = minetest.get_meta(pos)
  343. local inv = meta:get_inventory()
  344. local timer = minetest.get_node_timer(pos)
  345. if inv:contains_item('queen', 'bees:queen') then
  346. if inv:contains_item('frames', 'bees:frame_empty') then
  347. timer:start(30)
  348. local rad = 10
  349. local minp = {x=pos.x-rad, y=pos.y-rad, z=pos.z-rad}
  350. local maxp = {x=pos.x+rad, y=pos.y+rad, z=pos.z+rad}
  351. local flowers = minetest.find_nodes_in_area(minp, maxp, 'group:flower')
  352. local progress = meta:get_int('progress')
  353. progress = progress + #flowers
  354. meta:set_int('progress', progress)
  355. if progress > 1000 then
  356. local flower = flowers[math.random(#flowers)]
  357. bees.polinate_flower(flower, minetest.get_node(flower).name)
  358. local stacks = inv:get_list('frames')
  359. for k, v in pairs(stacks) do
  360. if inv:get_stack('frames', k):get_name() == 'bees:frame_empty' then
  361. meta:set_int('progress', 0)
  362. inv:set_stack('frames',k,'bees:frame_full')
  363. return
  364. end
  365. end
  366. else
  367. meta:set_string('infotext', 'progress: '..progress..'+'..#flowers..'/1000')
  368. end
  369. else
  370. meta:set_string('infotext', 'does not have empty frame(s)')
  371. timer:stop()
  372. end
  373. end
  374. end,
  375. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  376. if listname == 'queen' then
  377. local timer = minetest.get_node_timer(pos)
  378. local meta = minetest.get_meta(pos)
  379. meta:set_string('infotext','requires queen bee to function')
  380. timer:stop()
  381. end
  382. end,
  383. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  384. local inv = minetest.get_meta(pos):get_inventory()
  385. if from_list == to_list then
  386. if inv:get_stack(to_list, to_index):is_empty() then
  387. return 1
  388. else
  389. return 0
  390. end
  391. else
  392. return 0
  393. end
  394. end,
  395. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  396. local meta = minetest.get_meta(pos)
  397. local inv = meta:get_inventory()
  398. local timer = minetest.get_node_timer(pos)
  399. if listname == 'queen' or listname == 'frames' then
  400. meta:set_string('queen', stack:get_name())
  401. meta:set_string('infotext','queen is inserted, now for the empty frames');
  402. if inv:contains_item('frames', 'bees:frame_empty') then
  403. timer:start(30)
  404. meta:set_string('infotext','bees are aclimating');
  405. end
  406. end
  407. end,
  408. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  409. if not minetest.get_meta(pos):get_inventory():get_stack(listname, index):is_empty() then return 0 end
  410. if listname == 'queen' then
  411. if stack:get_name():match('bees:queen*') then
  412. return 1
  413. end
  414. elseif listname == 'frames' then
  415. if stack:get_name() == ('bees:frame_empty') then
  416. return 1
  417. end
  418. end
  419. return 0
  420. end,
  421. })
  422. --ABMS
  423. minetest.register_abm({ --particles
  424. nodenames = {'bees:hive_artificial', 'bees:hive_wild', 'bees:hive_industrial'},
  425. interval = 10,
  426. chance = 4,
  427. action = function(pos)
  428. minetest.add_particle({
  429. pos = {x=pos.x, y=pos.y, z=pos.z},
  430. vel = {x=(math.random()-0.5)*5,y=(math.random()-0.5)*5,z=(math.random()-0.5)*5},
  431. acc = {x=math.random()-0.5,y=math.random()-0.5,z=math.random()-0.5},
  432. expirationtime = math.random(2.5),
  433. size = math.random(3),
  434. collisiondetection = true,
  435. texture = 'bees_particle_bee.png',
  436. })
  437. end,
  438. })
  439. minetest.register_abm({ --spawn abm. This should be changed to a more realistic type of spawning
  440. nodenames = {'group:leaves'},
  441. neighbors = {''},
  442. interval = 1600,
  443. chance = 20,
  444. action = function(pos, node, _, _)
  445. local p = {x=pos.x, y=pos.y-1, z=pos.z}
  446. if minetest.get_node(p).walkable == false then return end
  447. if (minetest.find_node_near(p, 5, 'group:flora') ~= nil and minetest.find_node_near(p, 40, 'bees:hive_wild') == nil) then
  448. minetest.add_node(p, {name='bees:hive_wild'})
  449. end
  450. end,
  451. })
  452. minetest.register_abm({ --spawning bees around bee hive
  453. nodenames = {'bees:hive_wild', 'bees:hive_artificial', 'bees:hive_industrial'},
  454. neighbors = {'group:flowers', 'group:leaves'},
  455. interval = 30,
  456. chance = 4,
  457. action = function(pos, node, _, _)
  458. local p = {x=pos.x+math.random(-5,5), y=pos.y-math.random(0,3), z=pos.z+math.random(-5,5)}
  459. if minetest.get_node(p).name == 'air' then
  460. minetest.add_node(p, {name='bees:bees'})
  461. end
  462. end,
  463. })
  464. minetest.register_abm({ --remove bees
  465. nodenames = {'bees:bees'},
  466. interval = 30,
  467. chance = 5,
  468. action = function(pos, node, _, _)
  469. minetest.remove_node(pos)
  470. end,
  471. })
  472. --ITEMS
  473. minetest.register_craftitem('bees:frame_empty', {
  474. description = 'empty hive frame',
  475. inventory_image = 'bees_frame_empty.png',
  476. stack_max = 24,
  477. })
  478. minetest.register_craftitem('bees:frame_full', {
  479. description = 'filled hive frame',
  480. inventory_image = 'bees_frame_full.png',
  481. stack_max = 12,
  482. })
  483. minetest.register_craftitem('bees:bottle_honey', {
  484. description = 'honey bottle',
  485. inventory_image = 'bees_bottle_honey.png',
  486. stack_max = 12,
  487. on_use = minetest.item_eat(3, "vessels:glass_bottle"),
  488. })
  489. minetest.register_craftitem('bees:wax', {
  490. description = 'bees wax',
  491. inventory_image = 'bees_wax.png',
  492. stack_max = 48,
  493. })
  494. minetest.register_craftitem('bees:honey_comb', {
  495. description = 'honey comb',
  496. inventory_image = 'bees_comb.png',
  497. on_use = minetest.item_eat(2),
  498. stack_max = 8,
  499. })
  500. minetest.register_craftitem('bees:queen', {
  501. description = 'Queen Bee',
  502. inventory_image = 'bees_particle_bee.png',
  503. stack_max = 1,
  504. })
  505. --CRAFTS
  506. minetest.register_craft({
  507. output = 'bees:extractor',
  508. recipe = {
  509. {'','default:steel_ingot',''},
  510. {'default:steel_ingot','default:stick','default:steel_ingot'},
  511. {'default:mese_crystal','default:steel_ingot','default:mese_crystal'},
  512. }
  513. })
  514. minetest.register_craft({
  515. output = 'bees:smoker',
  516. recipe = {
  517. {'default:steel_ingot', 'wool:red', ''},
  518. {'', 'default:torch', ''},
  519. {'', 'default:steel_ingot',''},
  520. }
  521. })
  522. minetest.register_craft({
  523. output = 'bees:hive_artificial',
  524. recipe = {
  525. {'group:wood','group:wood','group:wood'},
  526. {'group:wood','default:stick','group:wood'},
  527. {'group:wood','default:stick','group:wood'},
  528. }
  529. })
  530. minetest.register_craft({
  531. output = 'bees:grafting_tool',
  532. recipe = {
  533. {'', '', 'default:steel_ingot'},
  534. {'', 'default:stick', ''},
  535. {'', '', ''},
  536. }
  537. })
  538. minetest.register_craft({
  539. output = 'bees:frame_empty',
  540. recipe = {
  541. {'group:wood', 'group:wood', 'group:wood'},
  542. {'default:stick', 'default:stick', 'default:stick'},
  543. {'default:stick', 'default:stick', 'default:stick'},
  544. }
  545. })
  546. if minetest.get_modpath('bushes_classic') then
  547. minetest.register_craft({
  548. type = 'cooking',
  549. cooktime = 5,
  550. recipe = 'bees:bottle_honey',
  551. output = 'bushes:sugar',
  552. })
  553. end
  554. --TOOLS
  555. minetest.register_tool('bees:smoker', {
  556. description = 'smoker',
  557. inventory_image = 'bees_smoker.png',
  558. tool_capabilities = {
  559. full_punch_interval = 3.0,
  560. max_drop_level=0,
  561. damage_groups = {fleshy=2},
  562. },
  563. on_use = function(tool, user, node)
  564. if node then
  565. local pos = node.under
  566. if pos then
  567. for i=1,6 do
  568. minetest.add_particle({
  569. pos = {x=pos.x+math.random()-0.5, y=pos.y, z=pos.z+math.random()-0.5},
  570. vel = {x=0,y=0.5+math.random(),z=0},
  571. acc = {x=0,y=0,z=0},
  572. expirationtime = 2+math.random(2.5),
  573. size = math.random(3),
  574. collisiondetection = false,
  575. texture = 'bees_smoke_particle.png',
  576. })
  577. end
  578. --tool:add_wear(2)
  579. local meta = minetest.get_meta(pos)
  580. meta:set_int('agressive', 0)
  581. return nil
  582. end
  583. end
  584. end,
  585. })
  586. minetest.register_tool('bees:grafting_tool', {
  587. description = 'grafting tool',
  588. inventory_image = 'bees_grafting_tool.png',
  589. tool_capabilities = {
  590. full_punch_interval = 3.0,
  591. max_drop_level=0,
  592. damage_groups = {fleshy=2},
  593. },
  594. })
  595. --COMPATIBILTY --remove after all has been updated
  596. --ALIASES
  597. minetest.register_alias('bees:honey_extractor', 'bees:extractor')
  598. --BACKWARDS COMPATIBILITY WITH OLDER VERSION
  599. minetest.register_alias('bees:honey_bottle', 'bees:bottle_honey')
  600. minetest.register_abm({
  601. nodenames = {'bees:hive', 'bees:hive_artificial_inhabited'},
  602. interval = 0,
  603. chance = 1,
  604. action = function(pos, node)
  605. if node.name == 'bees:hive' then
  606. minetest.set_node(pos, { name = 'bees:hive_wild' })
  607. local meta = minetest.get_meta(pos)
  608. local inv = meta:get_inventory()
  609. inv:set_stack('queen', 1, 'bees:queen')
  610. end
  611. if node.name == 'bees:hive_artificial_inhabited' then
  612. minetest.set_node(pos, { name = 'bees:hive_artificial' })
  613. local meta = minetest.get_meta(pos)
  614. local inv = meta:get_inventory()
  615. inv:set_stack('queen', 1, 'bees:queen')
  616. local timer = minetest.get_node_timer(pos)
  617. timer:start(60)
  618. end
  619. end,
  620. })
  621. --PIPEWORKS
  622. if minetest.get_modpath("pipeworks") then
  623. minetest.register_node('bees:hive_industrial', {
  624. description = 'industrial bee hive',
  625. tiles = { 'bees_hive_industrial.png'},
  626. paramtype2 = 'facedir',
  627. groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,tubedevice=1,tubedevice_receiver=1},
  628. sounds = default.node_sound_wood_defaults(),
  629. tube = {
  630. insert_object = function(pos, node, stack, direction)
  631. local meta = minetest.get_meta(pos)
  632. local inv = meta:get_inventory()
  633. if stack:get_name() ~= "bees:frame_empty" or stack:get_count() > 1 then
  634. return stack
  635. end
  636. for i = 1, 8 do
  637. if inv:get_stack("frames", i):is_empty() then
  638. inv:set_stack("frames", i, stack)
  639. local timer = minetest.get_node_timer(pos)
  640. timer:start(30)
  641. meta:set_string('infotext','bees are aclimating')
  642. return ItemStack("")
  643. end
  644. end
  645. return stack
  646. end,
  647. can_insert = function(pos,node,stack,direction)
  648. local meta = minetest.get_meta(pos)
  649. local inv = meta:get_inventory()
  650. if stack:get_name() ~= "bees:frame_empty" or stack:get_count() > 1 then
  651. return false
  652. end
  653. for i = 1, 8 do
  654. if inv:get_stack("frames", i):is_empty() then
  655. return true
  656. end
  657. end
  658. return false
  659. end,
  660. can_remove = function(pos,node,stack,direction)
  661. if stack:get_name() == "bees:frame_full" then
  662. return 1
  663. else
  664. return 0
  665. end
  666. end,
  667. input_inventory = "frames",
  668. connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
  669. },
  670. on_construct = function(pos)
  671. local timer = minetest.get_node_timer(pos)
  672. local meta = minetest.get_meta(pos)
  673. local inv = meta:get_inventory()
  674. meta:set_int('agressive', 1)
  675. inv:set_size('queen', 1)
  676. inv:set_size('frames', 8)
  677. meta:set_string('infotext','requires queen bee to function')
  678. end,
  679. on_rightclick = function(pos, node, clicker, itemstack)
  680. minetest.show_formspec(
  681. clicker:get_player_name(),
  682. 'bees:hive_artificial',
  683. formspecs.hive_artificial(pos)
  684. )
  685. local meta = minetest.get_meta(pos)
  686. local inv = meta:get_inventory()
  687. if meta:get_int('agressive') == 1 and inv:contains_item('queen', 'bees:queen') then
  688. local health = clicker:get_hp()
  689. clicker:set_hp(health-4)
  690. else
  691. meta:set_int('agressive', 1)
  692. end
  693. end,
  694. on_timer = function(pos,elapsed)
  695. local meta = minetest.get_meta(pos)
  696. local inv = meta:get_inventory()
  697. local timer = minetest.get_node_timer(pos)
  698. if inv:contains_item('queen', 'bees:queen') then
  699. if inv:contains_item('frames', 'bees:frame_empty') then
  700. timer:start(30)
  701. local rad = 10
  702. local minp = {x=pos.x-rad, y=pos.y-rad, z=pos.z-rad}
  703. local maxp = {x=pos.x+rad, y=pos.y+rad, z=pos.z+rad}
  704. local flowers = minetest.find_nodes_in_area(minp, maxp, 'group:flower')
  705. local progress = meta:get_int('progress')
  706. progress = progress + #flowers
  707. meta:set_int('progress', progress)
  708. if progress > 1000 then
  709. local flower = flowers[math.random(#flowers)]
  710. bees.polinate_flower(flower, minetest.get_node(flower).name)
  711. local stacks = inv:get_list('frames')
  712. for k, v in pairs(stacks) do
  713. if inv:get_stack('frames', k):get_name() == 'bees:frame_empty' then
  714. meta:set_int('progress', 0)
  715. inv:set_stack('frames',k,'bees:frame_full')
  716. return
  717. end
  718. end
  719. else
  720. meta:set_string('infotext', 'progress: '..progress..'+'..#flowers..'/1000')
  721. end
  722. else
  723. meta:set_string('infotext', 'does not have empty frame(s)')
  724. timer:stop()
  725. end
  726. end
  727. end,
  728. on_metadata_inventory_take = function(pos, listname, index, stack, player)
  729. if listname == 'queen' then
  730. local timer = minetest.get_node_timer(pos)
  731. local meta = minetest.get_meta(pos)
  732. meta:set_string('infotext','requires queen bee to function')
  733. timer:stop()
  734. end
  735. end,
  736. allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
  737. local inv = minetest.get_meta(pos):get_inventory()
  738. if from_list == to_list then
  739. if inv:get_stack(to_list, to_index):is_empty() then
  740. return 1
  741. else
  742. return 0
  743. end
  744. else
  745. return 0
  746. end
  747. end,
  748. on_metadata_inventory_put = function(pos, listname, index, stack, player)
  749. local meta = minetest.get_meta(pos)
  750. local inv = meta:get_inventory()
  751. local timer = minetest.get_node_timer(pos)
  752. if listname == 'queen' or listname == 'frames' then
  753. meta:set_string('queen', stack:get_name())
  754. meta:set_string('infotext','queen is inserted, now for the empty frames');
  755. if inv:contains_item('frames', 'bees:frame_empty') then
  756. timer:start(30)
  757. meta:set_string('infotext','bees are aclimating');
  758. end
  759. end
  760. end,
  761. allow_metadata_inventory_put = function(pos, listname, index, stack, player)
  762. if not minetest.get_meta(pos):get_inventory():get_stack(listname, index):is_empty() then return 0 end
  763. if listname == 'queen' then
  764. if stack:get_name():match('bees:queen*') then
  765. return 1
  766. end
  767. elseif listname == 'frames' then
  768. if stack:get_name() == ('bees:frame_empty') then
  769. return 1
  770. end
  771. end
  772. return 0
  773. end,
  774. })
  775. minetest.register_craft({
  776. output = 'bees:hive_industrial',
  777. recipe = {
  778. {'default:steel_ingot','homedecor:plastic_sheeting','default:steel_ingot'},
  779. {'pipeworks:tube_1','bees:hive_artificial','pipeworks:tube_1'},
  780. {'default:steel_ingot','homedecor:plastic_sheeting','default:steel_ingot'},
  781. }
  782. })
  783. end
  784. print('[Mod]Bees Loaded!')