init.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. --minetest.chat_send_player("MustTest", "Test1")
  60. return true
  61. end
  62. -- Front node.
  63. node2 = minetest.get_node(vector.subtract(pos, dir))
  64. if node2.name == nodename and node2.param2 == node.param2 then
  65. --minetest.chat_send_player("MustTest", "Test2")
  66. return true
  67. end
  68. end
  69. end
  70. if not sfn.run_once then
  71. local c = "sfn:core"
  72. local f = sfn.modpath .. "/init.lua"
  73. reload.register_file(c, f, false)
  74. sfn.run_once = true
  75. end
  76. -- Used in W-E luatransform updates.
  77. function sfn.update_node(pos)
  78. pos = vector_round(pos)
  79. local node = minetest.get_node(pos)
  80. if node.name == "glowstone:glowstone" then
  81. local positions = {
  82. {x=pos.x, y=pos.y+1, z=pos.z},
  83. {x=pos.x+1, y=pos.y+1, z=pos.z},
  84. {x=pos.x-1, y=pos.y+1, z=pos.z},
  85. {x=pos.x, y=pos.y+1, z=pos.z+1},
  86. {x=pos.x, y=pos.y+1, z=pos.z-1},
  87. }
  88. for k, v in ipairs(positions) do
  89. local n = minetest.get_node(v)
  90. if n.name == "air" then
  91. minetest.set_node(v, {name="stairs:slab_default_glass_1", param2=math_random(0, 3)})
  92. end
  93. end
  94. end
  95. --[[
  96. pos = vector_round(pos)
  97. local node = minetest.get_node(pos)
  98. if node.name == "rackstone:brick" then
  99. if math_random(1, 6) == 1 then
  100. node.name = "rackstone:redrack_block"
  101. minetest.swap_node(pos, node)
  102. end
  103. end
  104. --]]
  105. --[[
  106. pos = vector_round(pos)
  107. local node = minetest.get_node(pos)
  108. if node.name == "glowstone:glowstone" then
  109. local dirs = {
  110. {x=pos.x+1, y=pos.y, z=pos.z, p=1},
  111. {x=pos.x-1, y=pos.y, z=pos.z, p=3},
  112. {x=pos.x, y=pos.y, z=pos.z+1, p=0},
  113. {x=pos.x, y=pos.y, z=pos.z-1, p=2},
  114. }
  115. for k, v in ipairs(dirs) do
  116. local brick = minetest.get_node(v)
  117. local air = minetest.get_node({x=v.x, y=v.y+1, z=v.z})
  118. if brick.name == "rackstone:brick" and air.name == "air" then
  119. minetest.set_node(v, {name="stairs:stair_rackstone_brick2", param2=v.p})
  120. end
  121. end
  122. end
  123. --]]
  124. end