lightsensor.lua 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. local GET_COMMAND = "GET"
  2. local lsensor_nodebox =
  3. {
  4. type = "fixed",
  5. fixed = {
  6. { -8/16, -8/16, -8/16, 8/16, -7/16, 8/16 }, -- bottom slab
  7. { -7/16, -7/16, -7/16, -4/16, -5/16, 7/16 }, -- bonds
  8. { 4/16, -7/16, -7/16, 7/16, -5/16, 7/16 },
  9. { -7/16, -7/16, -7/16, 7/16, -5/16, -4/16 },
  10. { -7/16, -7/16, 4/16, 7/16, -5/16, 7/16 },
  11. { -1/16, -7/16, -1/16, 1/16, -5/16, 1/16 }, -- pin thing in the middle
  12. }
  13. }
  14. local lsensor_selbox =
  15. {
  16. type = "fixed",
  17. fixed = {{ -8/16, -8/16, -8/16, 8/16, -3/16, 8/16 }}
  18. }
  19. local on_digiline_receive = function (pos, _, channel, msg)
  20. local setchan = minetest.get_meta(pos):get_string("channel")
  21. if channel == setchan and msg == GET_COMMAND then
  22. local lightval = minetest.get_node_light(pos)
  23. digilines.receptor_send(pos, digilines.rules.default, channel, lightval)
  24. end
  25. end
  26. minetest.register_alias("digilines_lightsensor:lightsensor", "digilines:lightsensor")
  27. minetest.register_node("digilines:lightsensor", {
  28. description = "Digiline Lightsensor",
  29. drawtype = "nodebox",
  30. tiles = {"digilines_lightsensor.png"},
  31. paramtype = "light",
  32. groups = {dig_immediate=2},
  33. selection_box = lsensor_selbox,
  34. node_box = lsensor_nodebox,
  35. digiline =
  36. {
  37. receptor = {},
  38. effector = {
  39. action = on_digiline_receive
  40. },
  41. },
  42. on_construct = function(pos)
  43. local meta = minetest.get_meta(pos)
  44. meta:set_string("formspec", "field[channel;Channel;${channel}]")
  45. end,
  46. on_receive_fields = function(pos, _, fields, sender)
  47. local name = sender:get_player_name()
  48. if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
  49. minetest.record_protection_violation(pos, name)
  50. return
  51. end
  52. if (fields.channel) then
  53. minetest.get_meta(pos):set_string("channel", fields.channel)
  54. end
  55. end,
  56. })