conversion.lua 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. --[[
  2. More Blocks: conversion
  3. Copyright © 2011-2020 Hugo Locurcio and contributors.
  4. Licensed under the zlib license. See LICENSE.md for more information.
  5. --]]
  6. -- Function to convert all stairs/slabs/etc nodes from
  7. -- inverted, wall, etc to regular + 6d facedir
  8. local dirs1 = {21, 20, 23, 22, 21}
  9. local dirs2 = {15, 8, 17, 6, 15}
  10. local dirs3 = {14, 11, 16, 5, 14}
  11. function stairsplus:register_6dfacedir_conversion(modname, material)
  12. --print("Register stairsplus 6d facedir conversion")
  13. --print('ABM for '..modname..' "'..material..'"')
  14. local objects_list1 = {
  15. modname.. ":slab_" ..material.. "_inverted",
  16. modname.. ":slab_" ..material.. "_quarter_inverted",
  17. modname.. ":slab_" ..material.. "_three_quarter_inverted",
  18. modname.. ":stair_" ..material.. "_inverted",
  19. modname.. ":stair_" ..material.. "_wall",
  20. modname.. ":stair_" ..material.. "_wall_half",
  21. modname.. ":stair_" ..material.. "_wall_half_inverted",
  22. modname.. ":stair_" ..material.. "_half_inverted",
  23. modname.. ":stair_" ..material.. "_right_half_inverted",
  24. modname.. ":panel_" ..material.. "_vertical",
  25. modname.. ":panel_" ..material.. "_top",
  26. }
  27. local objects_list2 = {
  28. modname.. ":slab_" ..material.. "_wall",
  29. modname.. ":slab_" ..material.. "_quarter_wall",
  30. modname.. ":slab_" ..material.. "_three_quarter_wall",
  31. modname.. ":stair_" ..material.. "_inner_inverted",
  32. modname.. ":stair_" ..material.. "_outer_inverted",
  33. modname.. ":micro_" ..material.. "_top"
  34. }
  35. for _, object in pairs(objects_list1) do
  36. local flip_upside_down = false
  37. local flip_to_wall = false
  38. local dest_object = object
  39. if string.find(dest_object, "_inverted") then
  40. flip_upside_down = true
  41. dest_object = string.gsub(dest_object, "_inverted", "")
  42. end
  43. if string.find(object, "_top") then
  44. flip_upside_down = true
  45. dest_object = string.gsub(dest_object, "_top", "")
  46. end
  47. if string.find(dest_object, "_wall") then
  48. flip_to_wall = true
  49. dest_object = string.gsub(dest_object, "_wall", "")
  50. end
  51. if string.find(dest_object, "_vertical") then
  52. flip_to_wall = true
  53. dest_object = string.gsub(dest_object, "_vertical", "")
  54. end
  55. if string.find(dest_object, "_half") and not string.find(dest_object, "_right_half") then
  56. dest_object = string.gsub(dest_object, "_half", "_right_half")
  57. elseif string.find(dest_object, "_right_half") then
  58. dest_object = string.gsub(dest_object, "_right_half", "_half")
  59. end
  60. --print(" +---> convert " ..object)
  61. --print(" | to " ..dest_object)
  62. minetest.register_abm({
  63. nodenames = {object},
  64. interval = 1,
  65. chance = 1,
  66. action = function(pos, node, active_object_count, active_object_count_wider)
  67. local fdir = node.param2 or 0
  68. local nfdir
  69. if flip_upside_down and not flip_to_wall then
  70. nfdir = dirs1[fdir + 2]
  71. elseif flip_to_wall and not flip_upside_down then
  72. nfdir = dirs2[fdir + 1]
  73. elseif flip_to_wall and flip_upside_down then
  74. nfdir = dirs3[fdir + 2]
  75. end
  76. minetest.set_node(pos, {name = dest_object, param2 = nfdir})
  77. end
  78. })
  79. end
  80. for _, object in pairs(objects_list2) do
  81. local flip_upside_down = false
  82. local flip_to_wall = false
  83. local dest_object = object
  84. if string.find(dest_object, "_inverted") then
  85. flip_upside_down = true
  86. dest_object = string.gsub(dest_object, "_inverted", "")
  87. end
  88. if string.find(dest_object, "_top") then
  89. flip_upside_down = true
  90. dest_object = string.gsub(dest_object, "_top", "")
  91. end
  92. if string.find(dest_object, "_wall") then
  93. flip_to_wall = true
  94. dest_object = string.gsub(dest_object, "_wall", "")
  95. end
  96. --print(" +---> convert " ..object)
  97. --print(" | to " ..dest_object)
  98. minetest.register_abm({
  99. nodenames = {object},
  100. interval = 1,
  101. chance = 1,
  102. action = function(pos, node, active_object_count, active_object_count_wider)
  103. local fdir = node.param2
  104. local nfdir = 20
  105. if flip_upside_down and not flip_to_wall then
  106. nfdir = dirs1[fdir + 1]
  107. elseif flip_to_wall and not flip_upside_down then
  108. nfdir = dirs2[fdir + 2]
  109. end
  110. minetest.set_node(pos, {name = dest_object, param2 = nfdir})
  111. end
  112. })
  113. end
  114. end