tjunction.lua 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. local screwdriver_exists = minetest.global_exists("screwdriver")
  2. local tjunction_nodebox = {
  3. type = "fixed",
  4. -- ±0.001 is to prevent z-fighting
  5. fixed = {{ -16/32-0.001, -17/32, -3/32, 16/32+0.001, -13/32, 3/32 },
  6. { -3/32, -17/32, -16/32+0.001, 3/32, -13/32, -3/32},}
  7. }
  8. local tjunction_selectionbox = {
  9. type = "fixed",
  10. fixed = { -16/32, -16/32, -16/32, 16/32, -12/32, 7/32 },
  11. }
  12. local tjunction_get_rules = function (node)
  13. local rules =
  14. {{x = 0, y = 0, z = 1},
  15. {x = 1, y = 0, z = 0},
  16. {x = 0, y = 0, z = -1}}
  17. for i = 0, node.param2 do
  18. rules = mesecon.rotate_rules_left(rules)
  19. end
  20. return rules
  21. end
  22. minetest.register_node("mesecons_extrawires:tjunction_on", {
  23. drawtype = "nodebox",
  24. tiles = {
  25. "jeija_insulated_wire_tjunction_tb_on.png",
  26. "jeija_insulated_wire_tjunction_tb_on.png^[transformR180",
  27. "jeija_insulated_wire_ends_on.png",
  28. "jeija_insulated_wire_ends_on.png",
  29. "jeija_insulated_wire_sides_on.png",
  30. "jeija_insulated_wire_ends_on.png"
  31. },
  32. paramtype = "light",
  33. paramtype2 = "facedir",
  34. is_ground_content = false,
  35. walkable = false,
  36. sunlight_propagates = true,
  37. selection_box = tjunction_selectionbox,
  38. node_box = tjunction_nodebox,
  39. groups = {dig_immediate = 3, not_in_creative_inventory = 1},
  40. drop = "mesecons_extrawires:tjunction_off",
  41. sounds = default.node_sound_defaults(),
  42. mesecons = {conductor =
  43. {
  44. state = mesecon.state.on,
  45. rules = tjunction_get_rules,
  46. offstate = "mesecons_extrawires:tjunction_off"
  47. }},
  48. on_blast = mesecon.on_blastnode,
  49. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  50. })
  51. minetest.register_node("mesecons_extrawires:tjunction_off", {
  52. drawtype = "nodebox",
  53. description = "Insulated Mesecon T-junction",
  54. tiles = {
  55. "jeija_insulated_wire_tjunction_tb_off.png",
  56. "jeija_insulated_wire_tjunction_tb_off.png^[transformR180",
  57. "jeija_insulated_wire_ends_off.png",
  58. "jeija_insulated_wire_ends_off.png",
  59. "jeija_insulated_wire_sides_off.png",
  60. "jeija_insulated_wire_ends_off.png"
  61. },
  62. paramtype = "light",
  63. paramtype2 = "facedir",
  64. is_ground_content = false,
  65. walkable = false,
  66. sunlight_propagates = true,
  67. selection_box = tjunction_selectionbox,
  68. node_box = tjunction_nodebox,
  69. groups = {dig_immediate = 3},
  70. sounds = default.node_sound_defaults(),
  71. mesecons = {conductor =
  72. {
  73. state = mesecon.state.off,
  74. rules = tjunction_get_rules,
  75. onstate = "mesecons_extrawires:tjunction_on"
  76. }},
  77. on_blast = mesecon.on_blastnode,
  78. on_rotate = screwdriver_exists and screwdriver.rotate_simple,
  79. })
  80. minetest.register_craft({
  81. output = "mesecons_extrawires:tjunction_off 3",
  82. recipe = {
  83. {"mesecons_insulated:insulated_off", "mesecons_insulated:insulated_off", "mesecons_insulated:insulated_off"},
  84. {"", "mesecons_insulated:insulated_off", ""},
  85. }
  86. })