Commit 3ff58a74 authored by Fedja Beader's avatar Fedja Beader
Browse files

WorldEdit: don't build if we are missing some material (and state what

it is)
parent e9271597
......@@ -233,6 +233,18 @@ local function csmwe_chatcommand_func(param)
l:err("You need to specify anchor position (minimal x,y,z) to paste a build")
else
node_storage:convert_for_placement()
local inventory = core.get_inventory()
local missing_material = node_storage:get_missing_materials(inventory)
for name,count in pairs(missing_material) do
l:info(string.format("Missing material: need %8d more of '%s'", count, name))
end
if next(missing_material) then
l:err("Missing some material and cannot build. See above.")
return
end
queue:prepend(compute_next_step_saved)
queue:walk()
end
......
......@@ -117,6 +117,33 @@ function NodeStorage:print_bill_of_materials()
end
-- Go through inventory at inv and return name->count pairs of missing stuff (modify BOM)
function NodeStorage:get_missing_materials(inv)
local BOM = self:get_bill_of_materials()
local need = table.copy(BOM) -- deep copy
for _,list in pairs(inv) do
for index = 1,#list do
local stack = list[index]
local count = stack:get_count()
local name = stack:get_name()
local need_count = need[name]
if need_count then
need_count = need_count - count
if need_count > 0 then
need[name] = need_count
else
need[name] = nil
end
end
end
end
return need
end
-- TODO: lua can't really list files in a directory...
function NodeStorage:load(fname)
......
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