init.lua 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. sfn = sfn or {}
  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.spawn_falling_node = function(pos, node, meta)
  7. ambiance.particles_on_dig(pos, node)
  8. local obj = minetest.add_entity(pos, "__builtin:falling_node")
  9. if obj then
  10. obj:get_luaentity():set_node(node, meta)
  11. end
  12. end
  13. sfn.drop_node = function(pos)
  14. local node = minetest.get_node(pos)
  15. if string.find(node.name, "flowing") then
  16. -- Do not treat flowing liquid as a falling node. Looks ugly.
  17. return
  18. end
  19. if node.name ~= "air" and node.name ~= "ignore" then
  20. if minetest.get_item_group(node.name, "immovable") == 0 then
  21. local meta = minetest.get_meta(pos):to_table()
  22. minetest.remove_node(pos)
  23. sfn.spawn_falling_node(pos, node, meta)
  24. return true -- Success.
  25. end
  26. end
  27. end
  28. -- Return TRUE if the node is supported in some special, custom fashion.
  29. function sfn.check_clump_fall_special(pos, node)
  30. local nodename = node.name
  31. local ndef = minetest.registered_nodes[nodename]
  32. if not ndef then return end
  33. local groups = ndef.groups or {}
  34. -- Stairs, slabs, microblocks, etc. supported if at least one full block is next to them.
  35. local stair = groups.stair_node or 0
  36. if stair ~= 0 then
  37. local p = {
  38. {x=pos.x+1, y=pos.y, z=pos.z},
  39. {x=pos.x-1, y=pos.y, z=pos.z},
  40. {x=pos.x, y=pos.y, z=pos.z+1},
  41. {x=pos.x, y=pos.y, z=pos.z-1},
  42. }
  43. for k, v in ipairs(p) do
  44. local def2 = minetest.registered_nodes[minetest.get_node(v).name]
  45. if def2 then
  46. if def2.drawtype == "normal" then
  47. return true
  48. end
  49. end
  50. end
  51. end
  52. -- Tree trunks are supported if there is an adjacent connecting trunk.
  53. local tree = groups.tree or 0
  54. if tree ~= 0 and ndef.paramtype2 == "facedir" then
  55. local dir = minetest.facedir_to_dir(node.param2)
  56. -- Back node.
  57. local node2 = minetest.get_node(vector.add(pos, dir))
  58. if node2.name == nodename and node2.param2 == node.param2 then
  59. return true
  60. end
  61. -- Front node.
  62. node2 = minetest.get_node(vector.subtract(pos, dir))
  63. if node2.name == nodename and node2.param2 == node.param2 then
  64. return true
  65. end
  66. end
  67. end
  68. if not sfn.run_once then
  69. local c = "sfn:core"
  70. local f = sfn.modpath .. "/init.lua"
  71. reload.register_file(c, f, false)
  72. sfn.run_once = true
  73. end
  74. -- Used in W-E luatransform updates.
  75. function sfn.update_node(pos)
  76. pos = vector_round(pos)
  77. local node = minetest.get_node(pos)
  78. if node.name == "glowstone:glowstone" then
  79. local positions = {
  80. {x=pos.x, y=pos.y+1, z=pos.z},
  81. {x=pos.x+1, y=pos.y+1, z=pos.z},
  82. {x=pos.x-1, y=pos.y+1, z=pos.z},
  83. {x=pos.x, y=pos.y+1, z=pos.z+1},
  84. {x=pos.x, y=pos.y+1, z=pos.z-1},
  85. }
  86. for k, v in ipairs(positions) do
  87. local n = minetest.get_node(v)
  88. if n.name == "air" then
  89. minetest.set_node(v, {name="stairs:slab_default_glass_1", param2=math_random(0, 3)})
  90. end
  91. end
  92. end
  93. --[[
  94. pos = vector_round(pos)
  95. local node = minetest.get_node(pos)
  96. if node.name == "rackstone:brick" then
  97. if math_random(1, 6) == 1 then
  98. node.name = "rackstone:redrack_block"
  99. minetest.swap_node(pos, node)
  100. end
  101. end
  102. --]]
  103. --[[
  104. pos = vector_round(pos)
  105. local node = minetest.get_node(pos)
  106. if node.name == "glowstone:glowstone" then
  107. local dirs = {
  108. {x=pos.x+1, y=pos.y, z=pos.z, p=1},
  109. {x=pos.x-1, y=pos.y, z=pos.z, p=3},
  110. {x=pos.x, y=pos.y, z=pos.z+1, p=0},
  111. {x=pos.x, y=pos.y, z=pos.z-1, p=2},
  112. }
  113. for k, v in ipairs(dirs) do
  114. local brick = minetest.get_node(v)
  115. local air = minetest.get_node({x=v.x, y=v.y+1, z=v.z})
  116. if brick.name == "rackstone:brick" and air.name == "air" then
  117. minetest.set_node(v, {name="stairs:stair_rackstone_brick2", param2=v.p})
  118. end
  119. end
  120. end
  121. --]]
  122. end