mirror of
https://github.com/kepler155c/opus
synced 2025-02-09 21:40:01 +00:00
better turtle.condense
This commit is contained in:
parent
abec4a9740
commit
bd5cba8656
@ -873,23 +873,27 @@ end
|
|||||||
function turtle.condense()
|
function turtle.condense()
|
||||||
local slots = turtle.getInventory()
|
local slots = turtle.getInventory()
|
||||||
|
|
||||||
for i = 16, 1, -1 do
|
for i = 1, 16 do
|
||||||
if slots[i].count > 0 then
|
if slots[i].count < 64 then
|
||||||
for j = 1, i - 1 do
|
for j = 16, i + 1, -1 do
|
||||||
if slots[j].count == 0 or slots[i].key == slots[j].key then
|
if slots[j].count > 0 and (slots[i].count == 0 or slots[i].key == slots[j].key) then
|
||||||
turtle.select(i)
|
turtle.select(j)
|
||||||
turtle.transferTo(j, 64)
|
if turtle.transferTo(i) then
|
||||||
local transferred = slots[i].qty - turtle.getItemCount(i)
|
local transferred = turtle.getItemCount(i) - slots[i].qty
|
||||||
slots[j].count = slots[j].count + transferred
|
slots[j].count = slots[j].count - transferred
|
||||||
slots[i].count = slots[i].count - transferred
|
slots[i].count = slots[i].count + transferred
|
||||||
slots[j].key = slots[i].key
|
slots[i].key = slots[j].key
|
||||||
if slots[i].count == 0 then
|
if slots[i].count == 64 then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
else
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
turtle.select(1)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user