init.lua 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/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. if objs[1] == nil and node.name == ppspec.onstate then
  17. minetest.env:add_node(pos, {name = ppspec.offstate})
  18. mesecon:receptor_off(pos)
  19. -- force deactivation of mesecon two blocks below (hacky)
  20. mesecon:turnoff(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
  21. else
  22. for k, obj in pairs(objs) do
  23. local objpos = obj:getpos()
  24. if objpos.y > pos.y-1 and objpos.y < pos.y then
  25. minetest.env:add_node(pos, {name=ppspec.onstate})
  26. mesecon:receptor_on(pos)
  27. -- force activation of mesecon two blocks below (hacky)
  28. mesecon:turnon(mesecon:addPosRule(pos, {x = 0, y = -2, z = 0}))
  29. end
  30. end
  31. end
  32. return true
  33. end
  34. -- Register a Pressure Plate
  35. -- offstate: name of the pressure plate when inactive
  36. -- onstate: name of the pressure plate when active
  37. -- description: description displayed in the player's inventory
  38. -- tiles_off: textures of the pressure plate when inactive
  39. -- tiles_on: textures of the pressure plate when active
  40. -- image: inventory and wield image of the pressure plate
  41. -- recipe: crafting recipe of the pressure plate
  42. function mesecon:register_pressure_plate(offstate, onstate, description, texture_off, texture_on, recipe)
  43. local ppspec = {
  44. offstate = offstate,
  45. onstate = onstate
  46. }
  47. minetest.register_node(offstate, {
  48. drawtype = "nodebox",
  49. tiles = {texture_off},
  50. inventory_image = texture_off,
  51. wield_image = image,
  52. paramtype = "light",
  53. selection_box = pp_box_off,
  54. node_box = pp_box_off,
  55. groups = {snappy = 2, oddly_breakable_by_hand = 3},
  56. description = description,
  57. pressureplate = ppspec,
  58. on_timer = pp_on_timer,
  59. mesecons = {receptor = {
  60. state = mesecon.state.off
  61. }},
  62. on_construct = function(pos)
  63. minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
  64. end,
  65. })
  66. minetest.register_node(onstate, {
  67. drawtype = "nodebox",
  68. tiles = {texture_on},
  69. paramtype = "light",
  70. selection_box = pp_box_on,
  71. node_box = pp_box_on,
  72. groups = {snappy = 2, oddly_breakable_by_hand = 3, not_in_creative_inventory = 1},
  73. drop = offstate,
  74. pressureplate = ppspec,
  75. on_timer = pp_on_timer,
  76. mesecons = {receptor = {
  77. state = mesecon.state.on
  78. }},
  79. on_construct = function(pos)
  80. minetest.env:get_node_timer(pos):start(PRESSURE_PLATE_INTERVAL)
  81. end,
  82. })
  83. minetest.register_craft({
  84. output = offstate,
  85. recipe = recipe,
  86. })
  87. end
  88. mesecon:register_pressure_plate(
  89. "mesecons_pressureplates:pressure_plate_wood_off",
  90. "mesecons_pressureplates:pressure_plate_wood_on",
  91. "Wooden Pressure Plate",
  92. "jeija_pressure_plate_wood_off.png",
  93. "jeija_pressure_plate_wood_on.png",
  94. {{"default:wood", "default:wood"}})
  95. mesecon:register_pressure_plate(
  96. "mesecons_pressureplates:pressure_plate_stone_off",
  97. "mesecons_pressureplates:pressure_plate_stone_on",
  98. "Stone Pressure Plate",
  99. "jeija_pressure_plate_stone_off.png",
  100. "jeija_pressure_plate_stone_on.png",
  101. {{"default:cobble", "default:cobble"}})