nodeinspector.lua 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. if not minetest.global_exists("nodeinspector") then nodeinspector = {} end
  2. nodeinspector.modpath = minetest.get_modpath("hb4")
  3. COLOR_RED = core.get_color_escape_sequence("#ff0000")
  4. COLOR_WHITE = core.get_color_escape_sequence("#ffffff")
  5. function nodeinspector.inspect(pname, under, above)
  6. if gdac.player_is_admin(pname) then
  7. local meta = minetest.get_meta(under)
  8. local data = meta:to_table()
  9. if data then
  10. local str = dump(data) or "No data!"
  11. minetest.chat_send_player(pname, "# Server: " .. str)
  12. end
  13. local timer = minetest.get_node_timer(under)
  14. local yesno = ""
  15. if timer:is_started() then
  16. yesno = "YES"
  17. else
  18. yesno = "NO"
  19. end
  20. minetest.chat_send_player(pname, "# Server: Nodetimer: " .. yesno .. ", Timeout: " .. timer:get_timeout() .. ", Elapsed: " .. timer:get_elapsed() .. ".")
  21. end
  22. local nodeunder = minetest.get_node(under)
  23. local nodeabove = minetest.get_node(above)
  24. local defunder = minetest.registered_items[nodeunder.name]
  25. local defabove = minetest.registered_items[nodeabove.name]
  26. if not defunder or not defabove then
  27. return
  28. end
  29. local strunder = rc.pos_to_namestr(under)
  30. local strabove = rc.pos_to_namestr(above)
  31. local descunder = utility.get_short_desc(defunder.description or "<NONE>")
  32. local descabove = utility.get_short_desc(defabove.description or "<NONE>")
  33. local levelunder = 0
  34. local levelabove = 0
  35. if defunder.groups then
  36. levelunder = (defunder.groups.level or 0)
  37. end
  38. if defabove.groups then
  39. levelabove = (defabove.groups.level or 0)
  40. end
  41. if descunder == "" then descunder = "<NONE>" end
  42. if descabove == "" then descabove = "<NONE>" end
  43. local lightunder = minetest.get_node_light(under) or 0
  44. local lightabove = minetest.get_node_light(above) or 0
  45. local ownerunder = rename.gpn(protector.get_node_owner(under) or "")
  46. local ownerabove = rename.gpn(protector.get_node_owner(above) or "")
  47. if ownerunder == "" then ownerunder = "Nobody" else ownerunder = "<" .. ownerunder .. ">" end
  48. if ownerabove == "" then ownerabove = "Nobody" else ownerabove = "<" .. ownerabove .. ">" end
  49. local protunder = "You can build here."
  50. if minetest.test_protection(under, pname) then
  51. protunder = "Position is protected."
  52. end
  53. local protabove = "You can build here."
  54. if minetest.test_protection(above, pname) then
  55. protabove = "Position is protected."
  56. end
  57. local checkunder = COLOR_RED .. "FAIL" .. COLOR_WHITE
  58. if minetest.test_protection(under, "") then
  59. checkunder = "PASS"
  60. end
  61. local checkabove = COLOR_RED .. "FAIL" .. COLOR_WHITE
  62. if minetest.test_protection(above, "") then
  63. checkabove = "PASS"
  64. end
  65. local metaunder = minetest.get_meta(under)
  66. local metaabove = minetest.get_meta(above)
  67. local mounder = metaunder:get_string("owner")
  68. local moabove = metaabove:get_string("owner")
  69. if mounder == "" or mounder == "server" then mounder = "Unspecified" else mounder = "<" .. rename.gpn(mounder) .. ">" end
  70. if moabove == "" or moabove == "server" then moabove = "Unspecified" else moabove = "<" .. rename.gpn(moabove) .. ">" end
  71. local escape = minetest.formspec_escape
  72. local formspec = "size[7,8.75]" ..
  73. default.gui_bg ..
  74. default.gui_bg_img ..
  75. default.gui_slots ..
  76. "label[0,0.0;" .. escape("Node Under " .. strunder .. ":") .. "]" ..
  77. "label[0,0.4;" .. escape("Description: " .. descunder) .. "]" ..
  78. "label[0,0.8;" .. escape("Node ID: " .. nodeunder.name) .. "]" ..
  79. "label[0,1.2;" .. escape("Node Light: " .. lightunder) .. "]" ..
  80. "label[0,1.6;" .. escape("Land Claimed By: " .. ownerunder) .. "]" ..
  81. "label[0,2.0;" .. escape(protunder) .. "]" ..
  82. "label[0,2.4;" .. escape("Protection Check: " .. checkunder) .. "]" ..
  83. "label[0,2.8;" .. escape("Meta Owner: " .. mounder) .. "]" ..
  84. "label[0,3.2;" .. escape("Node Level: " .. levelunder) .. "]" ..
  85. "item_image[6,0;1,1;" .. escape(nodeunder.name) .. "]" ..
  86. "label[0,4.0;" .. escape("Node Above " .. strabove .. ":") .. "]" ..
  87. "label[0,4.4;" .. escape("Description: " .. descabove) .. "]" ..
  88. "label[0,4.8;" .. escape("Node ID: " .. nodeabove.name) .. "]" ..
  89. "label[0,5.2;" .. escape("Node Light: " .. lightabove) .. "]" ..
  90. "label[0,5.6;" .. escape("Land Claimed By: " .. ownerabove) .. "]" ..
  91. "label[0,6.0;" .. escape(protabove) .. "]" ..
  92. "label[0,6.4;" .. escape("Protection Check: " .. checkabove) .. "]" ..
  93. "label[0,6.8;" .. escape("Meta Owner: " .. moabove) .. "]" ..
  94. "label[0,7.2;" .. escape("Node Level: " .. levelabove) .. "]" ..
  95. "item_image[6,4;1,1;" .. escape(nodeabove.name) .. "]" ..
  96. "item_image[4,8;1,1;nodeinspector:nodeinspector]" ..
  97. "button_exit[5,8;2,1;exit;Close]"
  98. local formname = "nodeinspector:" .. strunder .. ":" .. strabove
  99. minetest.show_formspec(pname, formname, formspec)
  100. end
  101. function nodeinspector.on_receive_fields(player, formname, fields)
  102. if string.sub(formname, 1, 14) ~= "nodeinspector:" then
  103. return
  104. end
  105. return true
  106. end
  107. function nodeinspector.reveal(pname, pos)
  108. protector.toggle_protector_entities_in_area(pname, pos)
  109. end
  110. function nodeinspector.on_use(itemstack, user, pt)
  111. if not user or not user:is_player() then return end
  112. if pt.type == "node" and pt.under and pt.above then
  113. local control = user:get_player_control()
  114. if control.sneak then
  115. nodeinspector.reveal(user:get_player_name(), pt.under)
  116. else
  117. nodeinspector.inspect(user:get_player_name(), pt.under, pt.above)
  118. end
  119. end
  120. end
  121. if not nodeinspector.registered then
  122. minetest.register_tool(":nodeinspector:nodeinspector", {
  123. description = "Node Inspector\n\nGet information about the pointed node.\nCheck protection and other things.\nHold 'sneak' to toggle protector display grid.",
  124. inventory_image = "nodeinspector.png",
  125. groups = {not_repaired_by_anvil=1},
  126. on_use = function(...)
  127. return nodeinspector.on_use(...)
  128. end,
  129. })
  130. minetest.register_craft({
  131. output = "nodeinspector:nodeinspector",
  132. recipe = {
  133. {'', 'default:mese_crystal', ''},
  134. {'plastic:plastic_sheeting', 'books:book_blank', 'plastic:plastic_sheeting'},
  135. {'plastic:plastic_sheeting', 'default:gold_ingot', 'plastic:plastic_sheeting'},
  136. },
  137. })
  138. minetest.register_on_player_receive_fields(function(...)
  139. return nodeinspector.on_receive_fields(...)
  140. end)
  141. nodeinspector.registered = true
  142. end