Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local A = {
- [1] = {name="minecraft:coal", count=64},
- [5] = {name="minecraft:wheat_seeds", count=54},
- [7] = {name="minecraft:wheat_seeds", count=21}
- }
- local total = 0
- for k,v in pairs(A) do
- print(v.name .. " : " .. v.count)
- end
- local non_full = 0
- for i=1,16 do
- if A[i] ~= nil then
- if A[i].name == "minecraft:wheat_seeds" and total < 64 then
- total = total + A[i].count
- --combine stacks
- if non_full == 0 then
- non_full = i
- end
- if non_full ~= 0 then
- A[non_full] = A[non_full] or {name="minecraft:wheat_seeds", count=0}
- local slot_count = A[non_full].count
- if slot_count < 64 then
- local diff = math.abs(64 - slot_count)
- printError(diff)
- A[non_full].count = A[non_full].count + diff
- A[i].count = A[i].count - diff
- end
- end
- elseif A[i].name == "minecraft:wheat_seeds" and total >= 64 then
- A[i].count = 0
- end
- else
- if non_full == 0 then non_full = i end
- end
- end
- print(non_full)
- print(total)
- for k,v in pairs(A) do
- print(v.name .. " : " .. v.count)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement