init.lua 3.6 KB

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