presets.lua 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. mesecon.rules = {}
  2. mesecon.state = {}
  3. mesecon.rules.default = {
  4. {x = 0, y = 0, z = -1},
  5. {x = 1, y = 0, z = 0},
  6. {x = -1, y = 0, z = 0},
  7. {x = 0, y = 0, z = 1},
  8. {x = 1, y = 1, z = 0},
  9. {x = 1, y = -1, z = 0},
  10. {x = -1, y = 1, z = 0},
  11. {x = -1, y = -1, z = 0},
  12. {x = 0, y = 1, z = 1},
  13. {x = 0, y = -1, z = 1},
  14. {x = 0, y = 1, z = -1},
  15. {x = 0, y = -1, z = -1},
  16. }
  17. mesecon.rules.floor = mesecon.mergetable(mesecon.rules.default, {{x = 0, y = -1, z = 0}})
  18. mesecon.rules.pplate = mesecon.mergetable(mesecon.rules.floor, {{x = 0, y = -2, z = 0}})
  19. mesecon.rules.buttonlike = {
  20. {x = 1, y = 0, z = 0},
  21. {x = 1, y = 1, z = 0},
  22. {x = 1, y = -1, z = 0},
  23. {x = 1, y = -1, z = 1},
  24. {x = 1, y = -1, z = -1},
  25. {x = 2, y = 0, z = 0},
  26. }
  27. mesecon.rules.flat = {
  28. {x = 1, y = 0, z = 0},
  29. {x = -1, y = 0, z = 0},
  30. {x = 0, y = 0, z = 1},
  31. {x = 0, y = 0, z = -1},
  32. }
  33. mesecon.rules.alldirs = {
  34. {x = 1, y = 0, z = 0},
  35. {x = -1, y = 0, z = 0},
  36. {x = 0, y = 1, z = 0},
  37. {x = 0, y = -1, z = 0},
  38. {x = 0, y = 0, z = 1},
  39. {x = 0, y = 0, z = -1},
  40. }
  41. local rules_wallmounted = {
  42. xp = mesecon.rotate_rules_down(mesecon.rules.floor),
  43. xn = mesecon.rotate_rules_up(mesecon.rules.floor),
  44. yp = mesecon.rotate_rules_up(mesecon.rotate_rules_up(mesecon.rules.floor)),
  45. yn = mesecon.rules.floor,
  46. zp = mesecon.rotate_rules_left(mesecon.rotate_rules_up(mesecon.rules.floor)),
  47. zn = mesecon.rotate_rules_right(mesecon.rotate_rules_up(mesecon.rules.floor)),
  48. }
  49. local rules_buttonlike = {
  50. xp = mesecon.rules.buttonlike,
  51. xn = mesecon.rotate_rules_right(mesecon.rotate_rules_right(mesecon.rules.buttonlike)),
  52. yp = mesecon.rotate_rules_down(mesecon.rules.buttonlike),
  53. yn = mesecon.rotate_rules_up(mesecon.rules.buttonlike),
  54. zp = mesecon.rotate_rules_right(mesecon.rules.buttonlike),
  55. zn = mesecon.rotate_rules_left(mesecon.rules.buttonlike),
  56. }
  57. local function rules_from_dir(ruleset, dir)
  58. if dir.x == 1 then return ruleset.xp end
  59. if dir.y == 1 then return ruleset.yp end
  60. if dir.z == 1 then return ruleset.zp end
  61. if dir.x == -1 then return ruleset.xn end
  62. if dir.y == -1 then return ruleset.yn end
  63. if dir.z == -1 then return ruleset.zn end
  64. end
  65. mesecon.rules.wallmounted_get = function(node)
  66. local dir = minetest.wallmounted_to_dir(node.param2)
  67. return rules_from_dir(rules_wallmounted, dir)
  68. end
  69. mesecon.rules.buttonlike_get = function(node)
  70. local dir = minetest.facedir_to_dir(node.param2)
  71. return rules_from_dir(rules_buttonlike, dir)
  72. end
  73. mesecon.state.on = "on"
  74. mesecon.state.off = "off"