conversion.lua 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. --[[
  2. More Blocks: conversion
  3. Copyright (c) 2011-2017 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. if false then -- ABM disabled
  63. minetest.register_abm({
  64. nodenames = {object},
  65. interval = 1,
  66. chance = 1,
  67. action = function(pos, node, active_object_count, active_object_count_wider)
  68. local fdir = node.param2 or 0
  69. local nfdir
  70. if flip_upside_down and not flip_to_wall then
  71. nfdir = dirs1[fdir + 2]
  72. elseif flip_to_wall and not flip_upside_down then
  73. nfdir = dirs2[fdir + 1]
  74. elseif flip_to_wall and flip_upside_down then
  75. nfdir = dirs3[fdir + 2]
  76. end
  77. minetest.set_node(pos, {name = dest_object, param2 = nfdir})
  78. end
  79. })
  80. end
  81. end
  82. for _, object in pairs(objects_list2) do
  83. local flip_upside_down = false
  84. local flip_to_wall = false
  85. local dest_object = object
  86. if string.find(dest_object, "_inverted") then
  87. flip_upside_down = true
  88. dest_object = string.gsub(dest_object, "_inverted", "")
  89. end
  90. if string.find(dest_object, "_top") then
  91. flip_upside_down = true
  92. dest_object = string.gsub(dest_object, "_top", "")
  93. end
  94. if string.find(dest_object, "_wall") then
  95. flip_to_wall = true
  96. dest_object = string.gsub(dest_object, "_wall", "")
  97. end
  98. --print(" +---> convert " ..object)
  99. --print(" | to " ..dest_object)
  100. if false then -- ABM disabled
  101. minetest.register_abm({
  102. nodenames = {object},
  103. interval = 1,
  104. chance = 1,
  105. action = function(pos, node, active_object_count, active_object_count_wider)
  106. local fdir = node.param2
  107. local nfdir = 20
  108. if flip_upside_down and not flip_to_wall then
  109. nfdir = dirs1[fdir + 1]
  110. elseif flip_to_wall and not flip_upside_down then
  111. nfdir = dirs2[fdir + 2]
  112. end
  113. minetest.set_node(pos, {name = dest_object, param2 = nfdir})
  114. end
  115. })
  116. end
  117. end
  118. end