Commit d770cb67 authored by Fedja Beader's avatar Fedja Beader
Browse files

improve informative printing of inventory locations (and dedupe)

parent 6dc3061e
......@@ -16,6 +16,22 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
--]]
function inventory_location_to_string(loc)
if not loc then
return "nil"
elseif type(loc) == "table" then
if loc.x and loc.y and loc.z then
return minetest.pos_to_string(loc)
else
return "unknown table"
end
elseif type(self.inv_loc) == "string" then
return "detached(" .. loc .. ")"
else
return "unknown"
end
end
ItemLoc = {}
......@@ -56,18 +72,7 @@ end
function ItemLoc:to_string()
local str = ""
if not self.inv_loc then
str = str .. "nil"
elseif type(self.inv_loc) == "table" then
str = str .. minetest.pos_to_string(self.inv_loc)
elseif type(self.inv_loc) == "string" then
str = str .. self.inv_loc
else
str = str .. "unknown"
end
return str .. "[" .. self.list_name .. "][" .. self.list_index .. "]"
return inventory_location_to_string(self.inv_loc) .. "[" .. self.list_name .. "][" .. self.list_index .. "]"
end
......
......@@ -25,22 +25,11 @@ local l = Logger:new("repair chest")
-- Hardcoded for now. This is actually a chest node.
local reformer_pos = { y = 81, x = 11999, z = 11997 }
function location_to_string(loc)
if type(loc) == "table" and loc.x and loc.y and loc.z then
return minetest.pos_to_string(loc)
elseif type(loc) == "string" then
return loc
elseif not loc then
return "nil"
else
return "unknown"
end
end
local move_stack = function(from_inv, from, from_i, to_inv, to, to_i, count)
-- print("moving " .. tostring(count)
-- .. " from " .. location_to_string(from_inv) .. "[" .. from .. "][" .. tostring(from_i)
-- .. "] to " .. location_to_string(to_inv) .. "[" .. to .. "][" .. tostring(to_i) .. "]")
-- .. " from " .. inventory_location_to_string(from_inv) .. "[" .. from .. "][" .. tostring(from_i)
-- .. "] to " .. inventory_location_to_string(to_inv) .. "[" .. to .. "][" .. tostring(to_i) .. "]")
core.move_stack(from_inv, from, from_i, to_inv, to, to_i, count)
end
......@@ -132,7 +121,7 @@ function reformer:deprecated_step(distance)
-- We've repaired everything that was possible, see if anything remains
for i = 1, #self.inventory_map do
local entry = self.inventory_map[i]
local loc = location_to_string(entry[1])
local loc = inventory_location_to_string(entry[1])
self:log("Unable to repair item at: " .. tostring(entry[3]).."[" .. tostring(entry[4]) .. "]: in " .. loc)
end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment