init.lua 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. -- Modified, from minetest_game/mods/doors/init.lua
  2. local function on_rightclick(pos, dir, check_name, replace, replace_dir, params)
  3. pos.y = pos.y + dir
  4. if not minetest.get_node(pos).name == check_name then
  5. return
  6. end
  7. local p2 = minetest.get_node(pos).param2
  8. p2 = params[p2 + 1]
  9. minetest.swap_node(pos, {name = replace_dir, param2 = p2})
  10. pos.y = pos.y - dir
  11. minetest.swap_node(pos, {name = replace, param2 = p2})
  12. if (minetest.get_meta(pos):get_int("right") ~= 0) == (params[1] ~= 3) then
  13. minetest.sound_play("door_close", {pos = pos, gain = 0.3, max_hear_distance = 10})
  14. else
  15. minetest.sound_play("door_open", {pos = pos, gain = 0.3, max_hear_distance = 10})
  16. end
  17. end
  18. local function meseconify_door(name)
  19. if not minetest.registered_items[name] then return end
  20. local function toggle_state1 (pos, node)
  21. on_rightclick(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2", {1,2,3,0})
  22. end
  23. local function toggle_state2 (pos, node)
  24. on_rightclick(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1", {3,0,1,2})
  25. end
  26. minetest.override_item(name.."_b_1", {
  27. mesecons = {effector = {
  28. action_on = toggle_state1,
  29. action_off = toggle_state1,
  30. rules = mesecon.rules.pplate
  31. }},
  32. })
  33. minetest.override_item(name.."_b_2", {
  34. mesecons = {effector = {
  35. action_on = toggle_state2,
  36. action_off = toggle_state2,
  37. rules = mesecon.rules.pplate
  38. }},
  39. })
  40. end
  41. meseconify_door("doors:door_wood")
  42. meseconify_door("doors:door_steel")
  43. meseconify_door("doors:door_glass")
  44. meseconify_door("doors:door_obsidian_glass")
  45. -- Trapdoor
  46. local function trapdoor_switch(pos, node)
  47. local state = minetest.get_meta(pos):get_int("state")
  48. if state == 1 then
  49. minetest.sound_play("doors_door_close", {pos = pos, gain = 0.3, max_hear_distance = 10})
  50. minetest.set_node(pos, {name="doors:trapdoor", param2 = node.param2})
  51. else
  52. minetest.sound_play("doors_door_open", {pos = pos, gain = 0.3, max_hear_distance = 10})
  53. minetest.set_node(pos, {name="doors:trapdoor_open", param2 = node.param2})
  54. end
  55. minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1)
  56. end
  57. if minetest.registered_nodes["doors:trapdoor"] then
  58. minetest.override_item("doors:trapdoor", {
  59. mesecons = {effector = {
  60. action_on = trapdoor_switch,
  61. action_off = trapdoor_switch
  62. }},
  63. })
  64. minetest.override_item("doors:trapdoor_open", {
  65. mesecons = {effector = {
  66. action_on = trapdoor_switch,
  67. action_off = trapdoor_switch
  68. }},
  69. })
  70. end