init.lua 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. local modname = "planter_box"
  2. local modpath = minetest.get_modpath(modname)
  3. planter_box = {}
  4. minetest.register_node(modname..":planter_box", {
  5. description = "Planter Box",
  6. drawtype = "nodebox",
  7. node_box = {
  8. type = "connected",
  9. fixed = {{-3/8, -1/2, -3/8, 3/8, 1/2, 3/8}},
  10. -- connect_bottom =
  11. connect_front = {{-3/8, -1/2, -1/2, 3/8, 1/2, -1/4}},
  12. connect_left = {{-1/2, -1/2, -3/8, -1/4, 1/2, 3/8}},
  13. connect_back = {{-3/8, -1/2, 1/4, 3/8, 1/2, 1/2}},
  14. connect_right = {{ 3/8, -1/2, -3/8, 1/2, 1/2, 3/8}},
  15. },
  16. connects_to = { modname..":planter_box" },
  17. paramtype = "light",
  18. is_ground_content = true,
  19. tiles = {
  20. "default_dirt.png", "default_wood.png","default_wood.png",
  21. "default_wood.png", "default_wood.png","default_wood.png",
  22. },
  23. walkable = true,
  24. groups = { choppy = 3 },
  25. })
  26. -- crafting recipe
  27. minetest.register_craft({
  28. output = modname .. ":planter_box 2",
  29. recipe = {
  30. { '', '', '' },
  31. { "default:wood", "default:dirt", "default:wood"},
  32. { "default:wood", "default:wood", "default:wood"},
  33. }
  34. })
  35. local duplicates = {
  36. ["default:tree"]="default:sapling",
  37. }
  38. local hybrids = {
  39. ["default:tree"] = {
  40. ["default:jungletree"] = {"default:leaves"},
  41. ["default:stone"] ={"default:cobble"}
  42. },
  43. }
  44. planter_box.register_hybrid = function(p1, p2, baby)
  45. local a = hybrids[p1]
  46. local b = hybrids[p2]
  47. local top
  48. if hybrids[p1] == nil then
  49. if hybrids[p2] == nil then
  50. hybrids[p1] = {}
  51. else
  52. local t = p1
  53. p1 = p2
  54. p2 = t
  55. end
  56. end
  57. if hybrids[p1][p2] == nil then
  58. hybrids[p1][p2] = {}
  59. end
  60. table.insert(hybrids[p1][p2], baby)
  61. end
  62. minetest.register_abm({
  63. nodenames = {modname..":planter_box"},
  64. interval = 5,
  65. chance = 1,
  66. catch_up = true,
  67. action = function(pos, node)
  68. pos.y = pos.y + 1
  69. local over = minetest.get_node(pos)
  70. if over.name ~= "air" then
  71. return
  72. end
  73. function try_hybrids(n1, n2)
  74. if n1 == nil or n2 == nil then
  75. return false
  76. end
  77. local h = hybrids[n1.name]
  78. local h2n = n2.name
  79. if h == nil then
  80. h = hybrids[h2n]
  81. h2n = n1.name
  82. end
  83. if h == nil then
  84. return false
  85. end
  86. local baby = h[h2n]
  87. if baby ~= nil then
  88. minetest.set_node(pos, {name=baby})
  89. return true
  90. end
  91. return false
  92. end
  93. local x1 = minetest.get_node_or_nil({x=pos.x - 1, y=pos.y, z=pos.z})
  94. local x2 = minetest.get_node_or_nil({x=pos.x + 1, y=pos.y, z=pos.z})
  95. local z1 = minetest.get_node_or_nil({x=pos.x, y=pos.y, z=pos.z - 1})
  96. local z2 = minetest.get_node_or_nil({x=pos.x, y=pos.y, z=pos.z + 1})
  97. if try_hybrids(x1, x2) or try_hybrids(z1, z2) then
  98. return
  99. end
  100. --[[
  101. local r = math.random(1, 100)
  102. if r <= 15 then
  103. minetest.set_node(pos, {name=modname..":full_nest"})
  104. else
  105. minetest.set_node(pos, {name=modname..":empty_nest"})
  106. end, ]]
  107. end,
  108. })