init.lua 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. local pp_box_off = {
  2. type = "fixed",
  3. fixed = { -7/16, -8/16, -7/16, 7/16, -7/16, 7/16 },
  4. }
  5. local pp_box_on = {
  6. type = "fixed",
  7. fixed = { -7/16, -8/16, -7/16, 7/16, -7.5/16, 7/16 },
  8. }
  9. pp_on_timer = function (pos, elapsed)
  10. local node = minetest.env:get_node(pos)
  11. local ppspec = minetest.registered_nodes[node.name].pressureplate
  12. -- This is a workaround for a strange bug that occurs when the server is started
  13. -- For some reason the first time on_timer is called, the pos is wrong
  14. if not ppspec then return end
  15. local objs = minetest.env:get_objects_inside_radius(pos, 1)
  16. local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
  17. if objs[1] == nil and node.name == ppspec.onstate then
  18. minetest.env:add_node(pos, {name = ppspec.offstate})
  19. mesecon:receptor_off(pos)
  20. -- force deactivation of mesecon two blocks below (hacky)
  21. if not mesecon:connected_to_receptor(two_below) then
  22. mesecon:turnoff(two_below)
  23. end
  24. else
  25. for k, obj in pairs(objs) do
  26. local objpos = obj:getpos()
  27. if objpos.y > pos.y-1 and objpos.y < pos.y then
  28. minetest.env:add_node(pos, {name=ppspec.onstate})
  29. mesecon:receptor_on(pos)
  30. -- force activation of mesecon two blocks below (hacky)
  31. mesecon:turnon(two_below)
  32. end
  33. end
  34. end
  35. return true
  36. end
  37. -- Register a Pressure Plate
  38. -- offstate: name of the pressure plate when inactive
  39. -- onstate: name of the pressure plate when active
  40. -- description: description displayed in the player's inventory
  41. -- tiles_off: textures of the pressure plate when inactive
  42. -- tiles_on: textures of the pressure plate when active
  43. -- image: inventory and wield image of the pressure plate
  44. -- recipe: crafting recipe of the pressure plate
  45. function mesecon:register_pressure_plate(offstate, onstate, description, textures_off, textures_on, image_w, image_i, recipe)
  46. local ppspec = {
  47. offstate = offstate,
  48. onstate = onstate
  49. }
  50. minetest.register_node(offstate, {
  51. drawtype = "nodebox",
  52. tiles = textures_off,
  53. inventory_image = image_i,
  54. wield_image = image_w,
  55. paramtype = "light",
  56. selection_box = pp_box_off,
  57. node_box = pp_box_off,
  58. groups = {snappy = 2, oddly_breakable_by_hand = 3},
  59. description = description,
  60. pressureplate = ppspec,
  61. on_timer = pp_on_timer,
  62. mesecons = {receptor = {
  63. state = mesecon.state.off
  64. }},
  65. on_construct = function(pos)
  66. minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
  67. end,
  68. })
  69. minetest.register_node(onstate, {
  70. drawtype = "nodebox",
  71. tiles = textures_on,
  72. paramtype = "light",
  73. selection_box = pp_box_on,
  74. node_box = pp_box_on,
  75. groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
  76. drop = offstate,
  77. pressureplate = ppspec,
  78. on_timer = pp_on_timer,
  79. sounds = default.node_sound_wood_defaults(),
  80. mesecons = {receptor = {
  81. state = mesecon.state.on
  82. }},
  83. on_construct = function(pos)
  84. minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
  85. end,
  86. after_dig_node = function(pos)
  87. local two_below = mesecon:addPosRule(pos, {x = 0, y = -2, z = 0})
  88. if not mesecon:connected_to_receptor(two_below) then
  89. mesecon:turnoff(two_below)
  90. end
  91. end
  92. })
  93. minetest.register_craft({
  94. output = offstate,
  95. recipe = recipe,
  96. })
  97. end
  98. mesecon:register_pressure_plate(
  99. "mesecons_pressureplates:pressure_plate_wood_off",
  100. "mesecons_pressureplates:pressure_plate_wood_on",
  101. "Wooden Pressure Plate",
  102. {"jeija_pressure_plate_wood_off.png","jeija_pressure_plate_wood_off.png","jeija_pressure_plate_wood_off_edges.png"},
  103. {"jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on.png","jeija_pressure_plate_wood_on_edges.png"},
  104. "jeija_pressure_plate_wood_wield.png",
  105. "jeija_pressure_plate_wood_inv.png",
  106. {{"default:wood", "default:wood"}})
  107. mesecon:register_pressure_plate(
  108. "mesecons_pressureplates:pressure_plate_stone_off",
  109. "mesecons_pressureplates:pressure_plate_stone_on",
  110. "Stone Pressure Plate",
  111. {"jeija_pressure_plate_stone_off.png","jeija_pressure_plate_stone_off.png","jeija_pressure_plate_stone_off_edges.png"},
  112. {"jeija_pressure_plate_stone_on.png","jeija_pressure_plate_stone_on.png","jeija_pressure_plate_stone_on_edges.png"},
  113. "jeija_pressure_plate_stone_wield.png",
  114. "jeija_pressure_plate_stone_inv.png",
  115. {{"default:cobble", "default:cobble"}})