Commit 630bf7f7 authored by Fedja Beader's avatar Fedja Beader
Browse files

+ positions:iterate_on_bounding_box() and make inv_to_drawers support it

parent ca3a1a18
......@@ -86,10 +86,12 @@ function drawers_step()
core.after(15, drawers_step) -- use after as it takes forever
return
end
queue:prepend(drawers_step)
local node_inv = core.get_inventory(source_pos)
if not node_inv then
l:err("source does not have an inventory at " .. minetest.pos_to_string(source_pos))
state.sources[#state.sources] = nil
return
end
local pos_str = minetest.pos_to_string(source_pos)
......@@ -123,7 +125,6 @@ function drawers_step()
l:info("node " .. pos_str .. " processing complete, moved "
.. state.moved_count .. " items in " .. state.moved_stacks .. " stacks")
queue:prepend(drawers_step)
state.sources[#state.sources] = nil
state.moved_stacks = 0
state.moved_count = 0
......@@ -158,6 +159,7 @@ end)
local function help()
return ".drawer add -- toggles adding nodes/controller\n"
.. ".drawer add-pos-bb -- add all positions inside a bounding box defined by .pos\n"
.. ".drawer start -- starts moving stuff from nodes to drawer controller\n"
.. ".drawer stop -- stops moving stuff"
end
......@@ -173,6 +175,10 @@ core.register_chatcommand("drawer", {
l:info("punch controller (and then nodes to process them). Run 'add' again to end this process.")
wait_for_punch = true
end
elseif args[1] == "add-pos-bb" then
positions:iterate_on_bounding_box(function(pos)
table.insert(state.sources, pos)
end)
elseif args[1] == "start" then
state.enabled = true
queue:prepend(drawers_step)
......
......@@ -42,6 +42,27 @@ function positions:get(n)
return self.pos_list[n]
end
function positions:iterate_on_bounding_box(func)
local min = self.min
local max = self.max
if not min then
l:err("Need at least two positions to iterate")
return false
else
for x = min.x, max.x do
for y = min.y, max.y do
for z = min.z, max.z do
local pos = { x = x, y = y, z = z }
func(pos)
end
end
end
end
end
-- return two positions: .min with minimum coordinates and .max with maximum coordinates of the bounding box
function positions:update()
local min = { x = math.huge, y = math.huge, z = math.huge }
......
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