rtc.lua 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. local GET_COMMAND = "GET"
  2. local rtc_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, 7/16, -5/16, 7/16 },
  8. }
  9. }
  10. local rtc_selbox =
  11. {
  12. type = "fixed",
  13. fixed = {{ -8/16, -8/16, -8/16, 8/16, -3/16, 8/16 }}
  14. }
  15. local on_digiline_receive = function (pos, _, channel, msg)
  16. local setchan = minetest.get_meta(pos):get_string("channel")
  17. if channel == setchan and msg == GET_COMMAND then
  18. local timeofday = minetest.get_timeofday()
  19. digilines.receptor_send(pos, digilines.rules.default, channel, timeofday)
  20. end
  21. end
  22. minetest.register_alias("digilines_rtc:rtc", "digilines:rtc")
  23. minetest.register_node("digilines:rtc", {
  24. description = "Digiline Real Time Clock (RTC)",
  25. drawtype = "nodebox",
  26. tiles = {"digilines_rtc.png"},
  27. paramtype = "light",
  28. paramtype2 = "facedir",
  29. groups = {dig_immediate=2},
  30. selection_box = rtc_selbox,
  31. node_box = rtc_nodebox,
  32. digiline =
  33. {
  34. receptor = {},
  35. effector = {
  36. action = on_digiline_receive
  37. },
  38. },
  39. on_construct = function(pos)
  40. local meta = minetest.get_meta(pos)
  41. meta:set_string("formspec", "field[channel;Channel;${channel}]")
  42. end,
  43. on_receive_fields = function(pos, _, fields, sender)
  44. local name = sender:get_player_name()
  45. if minetest.is_protected(pos, name) and not minetest.check_player_privs(name, {protection_bypass=true}) then
  46. minetest.record_protection_violation(pos, name)
  47. return
  48. end
  49. if (fields.channel) then
  50. minetest.get_meta(pos):set_string("channel", fields.channel)
  51. end
  52. end,
  53. })