Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- slot1 : chest x3
- -- slot2 : cobblestone x1
- -- slot3 : dirt x1
- -- slot4 : gravel x1
- -- ----------------------------
- -- config
- -- ----------------------------
- local CHEST_SLOT = 1
- local EXCLUSION_SLOTS = {2,3,4}
- local OTHER_SLOTS = {5,6,7,8,9,10,11,12,13,14,15,16}
- -- ----------------------------
- -- application
- -- ----------------------------
- local function extractItems(itemChestPlaced)
- local garbageList = {}
- local itemList = {}
- for _, i in ipairs(OTHER_SLOTS) do
- if 0 < turtle.getItemCount(i) then
- turtle.select(i)
- local isItem = true
- for _, j in ipairs(EXCLUSION_SLOTS) do
- if turtle.compareTo(j) then
- isItem = false
- table.insert(garbageList, i)
- break
- end
- end
- if isItem then
- if not itemChestPlaced then
- turtle.select(CHEST_SLOT)
- while not turtle.placeUp() do
- turtle.digUp()
- end
- itemChestPlaced = true
- turtle.select(i)
- end
- turtle.dropUp()
- table.insert(itemList, i)
- end
- end
- end
- return garbageList, itemList, itemChestPlaced
- end
- local function dump(garbageList, garbageChestPlaced)
- turtle.turnLeft()
- turtle.turnLeft()
- if not garbageChestPlaced then
- turtle.select(CHEST_SLOT)
- turtle.place()
- end
- for _, i in ipairs(garbageList) do
- turtle.select(i)
- turtle.drop()
- end
- for _, i in ipairs(EXCLUSION_SLOTS) do
- turtle.select(i)
- turtle.drop(turtle.getItemCount(i) - 1)
- end
- turtle.turnRight()
- turtle.turnRight()
- return true
- end
- local function sifting()
- local gcPlaced = false
- local icPlaced = false
- local garbageList
- local itemList
- while true do
- local empty = true
- while turtle.suck() do empty = false end
- garbageList, itemList, icPlaced = extractItems(icPlaced)
- if 0 == #itemList then
- gcPlaced = dump(garbageList, gcPlaced)
- end
- if empty then
- if turtle.getItemCount(CHEST_SLOT) < 64 then
- turtle.select(CHEST_SLOT)
- turtle.dig()
- end
- break
- end
- end
- end
- local function dumpItems()
- turtle.turnLeft()
- turtle.turnLeft()
- for _, i in ipairs(OTHER_SLOTS) do
- if 0 < turtle.getItemCount(i) then
- turtle.select(i)
- while not turtle.drop() do
- print("Cannot drop items. sleep(5)")
- os.sleep(5)
- end
- end
- end
- local chestCnt = turtle.getItemCount(CHEST_SLOT)
- if 3 < chestCnt then
- turtle.select(CHEST_SLOT)
- while not turtle.drop(chestCnt - 3) do
- print("Cannot drop chests. sleep(5)")
- os.sleep(5)
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- local function transportItems()
- while turtle.suckUp() do empty = false end
- end
- local function hasEmptySlot()
- for i = 1, 16 do
- if 0 == turtle.getItemCount(i) then
- return true
- end
- end
- return false
- end
- -- ----------------------------
- -- main
- -- ----------------------------
- while true do
- local noResult = true
- for i = 1, 100 do
- turtle.up()
- if turtle.detect() then
- if turtle.suck() then
- sifting()
- noResult = false
- else
- turtle.select(CHEST_SLOT)
- if turtle.compare() then
- if turtle.getItemCount(CHEST_SLOT) < 64 then
- turtle.dig()
- else
- noResult = false
- end
- end
- end
- end
- if turtle.detectUp() then
- if turtle.suckUp() then
- transportItems()
- noResult = false
- else
- turtle.select(CHEST_SLOT)
- if turtle.compareUp() then
- if hasEmptySlot() and not turtle.suckUp() then
- turtle.digUp()
- end
- noResult = false
- else
- break
- end
- end
- end
- end
- while turtle.down() do end
- dumpItems()
- if noResult then
- break
- end
- end
- print("sifting was completed!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement