init.lua 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. if not minetest.global_exists("sfn") then sfn = {} end
  2. sfn.modpath = minetest.get_modpath("sfn")
  3. -- Localize for performance.
  4. local vector_round = vector.round
  5. local math_random = math.random
  6. sfn.drop_node = function(pos)
  7. return core.spawn_falling_node(pos)
  8. end
  9. -- Return TRUE if the node is supported in some special, custom fashion.
  10. function sfn.check_clump_fall_special(pos, node)
  11. local nodename = node.name
  12. local ndef = minetest.registered_nodes[nodename]
  13. if not ndef then return end
  14. local groups = ndef.groups or {}
  15. -- Stairs, slabs, microblocks, etc. supported if at least one full block is next to them.
  16. local stair = groups.stair_node or 0
  17. if stair ~= 0 then
  18. local p = {
  19. {x=pos.x+1, y=pos.y, z=pos.z},
  20. {x=pos.x-1, y=pos.y, z=pos.z},
  21. {x=pos.x, y=pos.y, z=pos.z+1},
  22. {x=pos.x, y=pos.y, z=pos.z-1},
  23. }
  24. for k, v in ipairs(p) do
  25. local def2 = minetest.registered_nodes[minetest.get_node(v).name]
  26. if def2 then
  27. if def2.drawtype == "normal" then
  28. return true
  29. end
  30. end
  31. end
  32. end
  33. -- Tree trunks are supported if there is an adjacent connecting trunk.
  34. local tree = groups.tree or 0
  35. if tree ~= 0 and ndef.paramtype2 == "facedir" then
  36. local dir = minetest.facedir_to_dir(node.param2)
  37. -- Back node.
  38. local node2 = minetest.get_node(vector.add(pos, dir))
  39. if node2.name == nodename and node2.param2 == node.param2 then
  40. return true
  41. end
  42. -- Front node.
  43. node2 = minetest.get_node(vector.subtract(pos, dir))
  44. if node2.name == nodename and node2.param2 == node.param2 then
  45. return true
  46. end
  47. end
  48. end
  49. if not sfn.run_once then
  50. local c = "sfn:core"
  51. local f = sfn.modpath .. "/init.lua"
  52. reload.register_file(c, f, false)
  53. sfn.run_once = true
  54. end
  55. -- Used in W-E luatransform updates.
  56. function sfn.update_node(pos)
  57. pos = vector_round(pos)
  58. local node = minetest.get_node(pos)
  59. if node.name == "glowstone:glowstone" then
  60. local positions = {
  61. {x=pos.x, y=pos.y+1, z=pos.z},
  62. {x=pos.x+1, y=pos.y+1, z=pos.z},
  63. {x=pos.x-1, y=pos.y+1, z=pos.z},
  64. {x=pos.x, y=pos.y+1, z=pos.z+1},
  65. {x=pos.x, y=pos.y+1, z=pos.z-1},
  66. }
  67. for k, v in ipairs(positions) do
  68. local n = minetest.get_node(v)
  69. if n.name == "air" then
  70. minetest.set_node(v, {name="stairs:slab_default_glass_1", param2=math_random(0, 3)})
  71. end
  72. end
  73. end
  74. --[[
  75. pos = vector_round(pos)
  76. local node = minetest.get_node(pos)
  77. if node.name == "rackstone:brick" then
  78. if math_random(1, 6) == 1 then
  79. node.name = "rackstone:redrack_block"
  80. minetest.swap_node(pos, node)
  81. end
  82. end
  83. --]]
  84. --[[
  85. pos = vector_round(pos)
  86. local node = minetest.get_node(pos)
  87. if node.name == "glowstone:glowstone" then
  88. local dirs = {
  89. {x=pos.x+1, y=pos.y, z=pos.z, p=1},
  90. {x=pos.x-1, y=pos.y, z=pos.z, p=3},
  91. {x=pos.x, y=pos.y, z=pos.z+1, p=0},
  92. {x=pos.x, y=pos.y, z=pos.z-1, p=2},
  93. }
  94. for k, v in ipairs(dirs) do
  95. local brick = minetest.get_node(v)
  96. local air = minetest.get_node({x=v.x, y=v.y+1, z=v.z})
  97. if brick.name == "rackstone:brick" and air.name == "air" then
  98. minetest.set_node(v, {name="stairs:stair_rackstone_brick2", param2=v.p})
  99. end
  100. end
  101. end
  102. --]]
  103. end