nodeinspector.lua 5.9 KB

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