Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local dumpDir = "up"
- local chestDir = "east"
- local mainLoopDelay = 10
- local mon = peripheral.wrap("top")
- local narc = peripheral.find("turtle")
- local lp = peripheral.find("LogisticsPipes:Normal")
- local chest = peripheral.find("deep_storage_unit")
- local dump = peripheral.find("diamond")
- if not narc or not lp or not chest or not dump then mon.setTextColor(colors.red) mon.clear() mon.setCursorPos(1,1) mon.write("Peripheral Error:") mon.setCursorPos(1,2) mon.write("narc: "..(narc and 1 or 0).." lp: "..(lp and 1 or 0).." chest: "..(chest and 1 or 0).." dump: "..(dump and 1 or 0)) return 0 end
- mon.setTextColor(colors.white)
- mon.setBackgroundColor(colors.black)
- mon.clear()
- mon.setCursorPos(1,1)
- --mon.write("beep")
- local ALKAHEST = 27480
- local DIAMOND = 264
- local WITHER = 397
- local POTION = 27484
- local STAR = 399
- local ingredients = {[ALKAHEST]=1,[DIAMOND]=1,[STAR]=1,[WITHER]=3,[POTION]=3}
- local function moveItemToInventory(inventory,dir,slot,number)
- while number > 0 and turtle.getItemCount(slot) > 0 do
- number = number - inventory.pullItem(dumpDir,slot,number)
- if number > 0 then sleep(0.5) end
- end
- end
- local function dumpItem(slot,number)
- moveItemToInventory(dump,dumpDir,slot,number)
- end
- local next = next
- local function checkInventory()
- -- narc.condenseItems()
- local items = narc.getAllStacks()
- -- shallow copy
- local currentRecipe = {}
- for i,k in pairs(ingredients) do currentRecipe[i] = k end
- --for i,k in pairs(currentRecipe) do print(i," ",k) end
- for n,item in pairs(items) do
- if currentRecipe[item.id] then
- currentRecipe[item.id] = currentRecipe[item.id]-item.qty ~= 0 and currentRecipe[item.id]-item.qty or nil
- if currentRecipe[item.id] and currentRecipe[item.id] < 0 then dumpItem(n,-currentRecipe[item.id]) currentRecipe[item.id] = nil end
- else
- dumpItem(n,64)
- end
- end
- --for i,k in pairs(currentRecipe) do print(i," ",k) end
- return next(currentRecipe) == nil and true or false
- end
- local recipe = {ALKAHEST,DIAMOND,STAR,nil,WITHER,WITHER,WITHER,nil,POTION,POTION,POTION,nil,nil,nil,nil,nil}
- local reverseRecipe = {}
- for i,k in pairs(recipe) do reverseRecipe[k] = i end
- local function getEmptySlotsTurtle()
- local slots = {}
- for i=1,16 do
- if turtle.getItemCount(i) == 0 then slots[i] = true end
- end
- return slots
- end
- local function getEmptySlots(itemList)
- local slots = {}
- --{4,8,12,13,14,15,16,11,10,9,7,6,5,3,2,1}
- for _,i in ipairs({1,2,3,5,6,7,9,10,11,16,15,14,13,12,8,4}) do
- if not itemList[i] then slots[#slots+1] = i end
- end
- return slots
- end
- local function move(slot,qty,emptySlots)
- turtle.select(slot)
- while not turtle.transferTo(emptySlots[#emptySlots],qty) do sleep(0.5) end
- emptySlots[#emptySlots] = nil
- end
- local condenseRecipe = {ALKAHEST,DIAMOND,STAR,nil,WITHER,nil,nil,nil,POTION}
- local reverseCondenseRecipe = {}
- for i,k in pairs(condenseRecipe) do reverseCondenseRecipe[k] = i end
- local distribution = {}
- local reverseDistribution = {}
- local function swapItems(src,dst)
- --,distr,reverseDistr)
- narc.swapStacks(src,dst)
- local tmpId = reverseDistribution[dst]
- local tmpSlot = distribution[dst]
- distribution[dst] = distribution[src]
- distribution[src] = tmpId
- reverseDistribution[dst] = reverseDistribution[src]
- reverseDistribution[src] = tmpSlot
- end
- local function prepareCraft()
- narc.condenseItems()
- local items = narc.getAllStacks()
- --local emptySlots = getEmptySlots(items)
- for n,item in pairs(items) do
- distribution[item.id] = n
- reverseDistribution[n] = item.id
- end
- for _,slot in ipairs({1,2,3,5,6,7,9,10,11}) do
- if reverseDistribution[slot] ~= condenseRecipe[slot] then
- --print(slot," ",condenseRecipe[slot]," ",distribution[condenseRecipe[slot]])
- swapItems(slot,distribution[condenseRecipe[slot]],distribution,reverseDistribution)
- end
- end
- turtle.select(5)
- turtle.transferTo(6,1) turtle.transferTo(7,1)
- turtle.select(9)
- turtle.transferTo(10,1) turtle.transferTo(11,1)
- turtle.select(3)
- end
- --for i,k in pairs(recipe) do print(i," ",k) end
- local slot3
- while true do
- if not checkInventory() then os.pullEvent("turtle_inventory") end
- while not checkInventory() do
- mon.write("waiting for items")
- sleep(0.5)
- end
- prepareCraft()
- turtle.craft()
- slot3=narc.getStackInSlot(3)
- if slot3.id == STAR and slot3.qty >= 2 then chest.pullItem(chestDir,3,slot3.qty-1) end
- --sleep(mainLoopDelay)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement