diff --git a/src/main.lua b/src/main.lua index 704b4d5..70cebee 100644 --- a/src/main.lua +++ b/src/main.lua @@ -638,26 +638,31 @@ local function VP_createstack(buf, dimensions) end VP_optimizestack(tempbuf) - if #tempbuf > 0 then out[posasstring(x,z)] = tempbuf end + if #tempbuf > 0 then + out[posasstring(x,z)] = tempbuf + end end end - for i,v in pairs(out) do print("ok");read() end + + fout["stacks"] = out return fout end +local function VP_lengthofdict(target) + local out = 0 + for _,v in pairs(target) do out = out + 1 end + return out +end local function VP_splitstack(_stack, x) local stack = _stack["stacks"] - if #stack == 0 then - error("Internal error, splitstack received 0 stacks. There is nothing to split.") - end local dimensions = _stack["dimensions"] local sx = dimensions["sx"] local sz = dimensions["sz"] local height = _stack["height"] local stacks = {} local unevenstack = {} - local stackmod = math.fmod(#stack, x) - local stackdiv = math.floor(#stack/x) + local stackmod = math.fmod(VP_lengthofdict(stack), x) + local stackdiv = math.floor(VP_lengthofdict(stack)/x) if stackmod ~= 0 then for tempstackindex=0,stackmod,1 do