doors.lua 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. -- Doors that are especially useful for travelnet elevators but can also be used in other situations.
  2. -- All doors (not only these here) in front of a travelnet or elevator are opened automaticly when a player arrives
  3. -- and are closed when a player departs from the travelnet or elevator.
  4. -- Autor: Sokomine
  5. local S = minetest.get_translator("travelnet")
  6. function travelnet.register_door(node_base_name, def_tiles, material)
  7. local closed_door = node_base_name .. "_closed"
  8. local open_door = node_base_name .. "_open"
  9. minetest.register_node(open_door, {
  10. description = S("Elevator door (open)"),
  11. drawtype = "nodebox",
  12. tiles = def_tiles,
  13. use_texture_alpha = "clip",
  14. paramtype = "light",
  15. paramtype2 = "facedir",
  16. is_ground_content = true,
  17. -- only the closed variant is in creative inventory
  18. groups = {
  19. snappy = 2,
  20. choppy = 2,
  21. oddly_breakable_by_hand = 2,
  22. not_in_creative_inventory = 1,
  23. door = 1
  24. },
  25. -- larger than one node but slightly smaller than a half node so
  26. -- that wallmounted torches pose no problem
  27. node_box = {
  28. type = "fixed",
  29. fixed = {
  30. { -0.90, -0.5, 0.4, -0.49, 1.5, 0.5 },
  31. { 0.49, -0.5, 0.4, 0.9, 1.5, 0.5 },
  32. },
  33. },
  34. selection_box = {
  35. type = "fixed",
  36. fixed = {
  37. { -0.9, -0.5, 0.4, 0.9, 1.5, 0.5 },
  38. },
  39. },
  40. drop = closed_door,
  41. on_rightclick = function(pos, node)
  42. minetest.add_node(pos, {
  43. name = closed_door,
  44. param2 = node.param2
  45. })
  46. end,
  47. })
  48. minetest.register_node(closed_door, {
  49. description = S("Elevator door (closed)"),
  50. drawtype = "nodebox",
  51. tiles = def_tiles,
  52. use_texture_alpha = "clip",
  53. paramtype = "light",
  54. paramtype2 = "facedir",
  55. is_ground_content = true,
  56. groups = {
  57. snappy = 2,
  58. choppy = 2,
  59. oddly_breakable_by_hand = 2,
  60. door = 1
  61. },
  62. node_box = {
  63. type = "fixed",
  64. fixed = {
  65. { -0.5, -0.5, 0.4, -0.01, 1.5, 0.5 },
  66. { 0.01, -0.5, 0.4, 0.5, 1.5, 0.5 },
  67. },
  68. },
  69. selection_box = {
  70. type = "fixed",
  71. fixed = {
  72. { -0.5, -0.5, 0.4, 0.5, 1.5, 0.5 },
  73. },
  74. },
  75. on_rightclick = function(pos, node)
  76. minetest.add_node(pos, {
  77. name = open_door,
  78. param2 = node.param2
  79. })
  80. end,
  81. })
  82. -- add a craft receipe for the door
  83. minetest.register_craft({
  84. output = closed_door,
  85. recipe = {
  86. { material, "", material },
  87. { material, "", material },
  88. { material, "", material }
  89. }
  90. })
  91. -- Make doors reacts to mesecons
  92. if minetest.get_modpath("mesecons") then
  93. local mesecons = {
  94. effector = {
  95. action_on = function(pos, node)
  96. minetest.add_node(pos, {
  97. name = open_door,
  98. param2 = node.param2
  99. })
  100. end,
  101. action_off = function(pos, node)
  102. minetest.add_node(pos, {
  103. name = closed_door,
  104. param2 = node.param2
  105. })
  106. end,
  107. rules = mesecon.rules.pplate
  108. }
  109. }
  110. minetest.override_item(closed_door, { mesecons=mesecons })
  111. minetest.override_item(open_door, { mesecons=mesecons })
  112. end
  113. end
  114. -- actually register the doors
  115. -- (but only if the materials for them exist)
  116. if minetest.get_modpath("default") then
  117. travelnet.register_door(":travelnet:elevator_door_steel", { "default_stone.png" }, "default:steel_ingot")
  118. travelnet.register_door(":travelnet:elevator_door_glass", { "travelnet_elevator_door_glass.png" }, "default:glass")
  119. travelnet.register_door(":travelnet:elevator_door_tin", { "default_clay.png" }, "default:tin_ingot")
  120. elseif minetest.registered_nodes[":mcl_core:wood"] then
  121. travelnet.register_door(":travelnet:elevator_door_steel", { "default_stone.png" }, "mcl_core:iron_ingot")
  122. travelnet.register_door(":travelnet:elevator_door_glass", { "travelnet_elevator_door_glass.png" }, "mcl_core:glass")
  123. -- travelnet.register_door("travelnet:elevator_door_tin", { "default_clay.png" }, "default:tin_ingot")
  124. end