Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local sortSlots = {}
- local input = turtle.suckDown
- local output = turtle.dropUp
- local wait = 10
- local facing = 0
- function orient(dir)
- if facing == dir then
- return
- elseif math.abs(facing - dir) == 2 then
- turtle.turnLeft()
- turtle.turnLeft()
- facing = dir
- elseif facing - dir == 1 or facing - dir == -3 then
- turtle.turnLeft()
- facing = dir
- else
- turtle.turnRight()
- facing = dir
- end
- end
- for i = 1, 16 do
- if turtle.getItemCount(i) > 0 then
- sortSlots[i] = true
- end
- end
- while true do
- -- get items
- turtle.select(1)
- while input() do
- end
- local full = {}
- for slot = 1, 16 do
- if sortSlots[slot] and turtle.getItemCount(slot) > 1
- or not sortSlots[slot] and turtle.getItemCount(slot) > 0 then
- turtle.select(slot)
- local similarSlots = {}
- for sortSlot in pairs(sortSlots) do
- if turtle.compareTo(sortSlot) then
- table.insert(similarSlots, sortSlot)
- end
- end
- if #similarSlots > 0 then
- for i, sortSlot in ipairs(similarSlots) do
- local chest = math.floor((sortSlot-1)/4)
- if not full[chest] then
- orient(chest)
- local amount = turtle.getItemCount(slot)
- if sortSlots[slot] then
- amount = amount - 1
- end
- -- temp fix for duplication bug
- while amount > 64 do
- if not turtle.drop(64) then
- full[chest] = true
- break
- end
- amount = amount - 64
- end
- if not full[chest] then
- -- end temp fix
- if turtle.drop(amount) then
- break
- else
- full[chest] = true
- end
- -- temp fix
- end
- -- end temp fix
- end
- end
- else
- output()
- end
- end
- end
- orient(0)
- sleep(wait)
- end
Advertisement
Add Comment
Please, Sign In to add comment