4 Copyright (C) 2015 - Auke Kok <sofar@foo-projects.org>
6 "inspector" is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1
9 of the license, or (at your option) any later version.
13 local function dehash_vector(s
)
15 x
= 256 * string.byte(s
, 1) + string.byte(s
, 2) - 32768,
16 y
= 256 * string.byte(s
, 3) + string.byte(s
, 4) - 32768,
17 z
= 256 * string.byte(s
, 5) + string.byte(s
, 6) - 32768,
21 local function inspect_pos(pos
)
22 local node
= minetest
.get_node(pos
)
23 local desc
= "===== node data =====\n"
24 desc
= desc
.. "name = " .. node
.name
.. "\n"
25 desc
= desc
.. "param1 = " .. node
.param1
.. "\n"
26 desc
= desc
.. "param2 = " .. node
.param2
.. "\n"
27 local light
= minetest
.get_node_light({x
= pos
.x
, y
= pos
.y
+ 1, z
= pos
.x
}, nil)
29 desc
= desc
.. "light = " .. light
.. "\n"
32 local timer
= minetest
.get_node_timer(pos
)
33 if timer
:get_timeout() ~= 0 then
34 desc
= desc
.. "==== node timer ====\n"
35 desc
= desc
.. "timeout = " .. timer
:get_timeout() .. "\n"
36 desc
= desc
.. "elapsed = " .. timer
:get_elapsed() .. "\n"
39 local nodedef
= minetest
.registered_items
[node
.name
]
40 local meta
= minetest
.get_meta(pos
)
41 local table = meta
:to_table()
42 if table.fields
.offsets
then
43 local offsets
= minetest
.deserialize(table.fields
.offsets
)
44 table.fields
.offsets
= nil
45 desc
= desc
.. "==== triggers ====\n"
46 for so
, _
in pairs(offsets
) do
47 local off
= dehash_vector(so
)
48 local npos
= vector
.add(pos
, off
)
49 local nname
= minetest
.get_node(npos
).name
50 desc
= desc
.. nname
.. " at " .. minetest
.pos_to_string(npos
) ..
51 " (offset is " .. minetest
.pos_to_string(off
) .. ")\n"
55 if table.fields
.roffsets
then
56 local roffsets
= minetest
.deserialize(table.fields
.roffsets
)
57 table.fields
.roffsets
= nil
58 desc
= desc
.. "==== triggered by ====\n"
59 for so
, _
in pairs(roffsets
) do
60 local off
= dehash_vector(so
)
61 local npos
= vector
.add(pos
, off
)
62 local nname
= minetest
.get_node(npos
).name
63 desc
= desc
.. nname
.. " at " .. minetest
.pos_to_string(npos
) ..
64 " (offset is " .. minetest
.pos_to_string(off
) .. ")\n"
69 local fields
= minetest
.serialize(table.fields
)
70 desc
= desc
.. "==== meta ====\n"
71 desc
= desc
.. "meta.fields = " .. fields
.. "\n"
73 local inventory
= meta
:get_inventory()
74 desc
= desc
.. "meta.inventory = \n"
75 for key
, list
in pairs(inventory
:get_lists()) do
76 desc
= desc
.. key
.. " : \n"
80 if not stack
:is_empty() then
81 desc
= desc
.. "\"" .. stack
:get_name() .. "\" - " .. stack
:get_count() .. "\n"
86 if nodedef
then -- Some built in nodes have no nodedef
87 desc
= desc
.. "==== nodedef ====\n"
88 desc
= desc
.. dump(nodedef
) .. "\n"
94 minetest
.register_tool("inspector:inspector", {
95 description
= "Inspector Tool",
96 inventory_image
= "inspector.png",
97 liquids_pointable
= true, -- makes it hard to use underwater.
99 on_use
= function(itemstack
, user
, pointed_thing
)
102 or not minetest
.check_player_privs(user
, "server")
103 and not boxes
.players_editing_boxes
[user
:get_player_name()] then
108 if pointed_thing
.type == "nothing" then
110 elseif pointed_thing
.type == "node" then
112 local pos
= pointed_thing
.under
114 if pointed_thing
.type ~= "node" then
117 desc
= inspect_pos(pos
)
120 elseif pointed_thing
.type == "object" then
122 local ref
= pointed_thing
.ref
123 local entity
= ref
:get_luaentity()
128 local formspec
= "size[12,8]"..
129 "label[0.5,0.5;Node Information]"..
130 "textarea[0.5,1.5;11.5,7;text;Contents:;"..
131 minetest
.formspec_escape(desc
).."]"..
132 "button_exit[2.5,7.5;3,1;close;Close]"
134 fsc
.show(user
:get_player_name(), formspec
, {}, function() end)
138 minetest
.register_chatcommand("inspect", {
140 description
= "inspect a pos",
141 privs
= {server
= true},
142 func
= function(name
, param
)
144 for p
in string.gmatch(param
, "%S+") do
145 paramlist
[#paramlist
+ 1] = p
147 local pos
= {x
= paramlist
[1], y
= paramlist
[2], z
= paramlist
[3]}
148 local desc
= inspect_pos(pos
)
149 local formspec
= "size[12,8]"..
150 "label[0.5,0.5;Node Information]"..
151 "textarea[0.5,1.5;11.5,7;text;Contents:;"..
152 minetest
.formspec_escape(desc
).."]"..
153 "button_exit[2.5,7.5;3,1;close;Close]"
155 fsc
.show(name
, formspec
, {}, function() end)