Blackhome

Turtle Tasks

Feb 6th, 2026 (edited)
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 23.69 KB | Gaming | 0 0
  1.     -- pastebin get Bfmm8YH2 Turtle Tasks
  2.  
  3.     AM = require("AM")
  4.     SE = require("SE")
  5.  
  6.     TT = {}
  7.  
  8.     TT.Task = {}
  9.  
  10.     local function setTaskStatus(status)
  11.         TT.Task.status = status
  12.         SDM.TURTLE.saveTurtleTask(TT.Task)
  13.     end
  14.     local function finishTask()
  15.         while true do
  16.             local fList = SDM.getFinishedTask()
  17.             if fList and #textutils.serialize(fList) > 2 then
  18.                 sleep(0.5)
  19.             else
  20.                 SDM.setFinishedTask(TT.Task)
  21.                 TT.Task = {}
  22.                 SDM.TURTLE.saveTurtleTask({})
  23.                 return
  24.             end
  25.         end
  26.     end
  27.  
  28.     local function isCoordLeftSection(coord)
  29.         local initData = SDM.TURTLE.loadInitData()
  30.         local chestSection = POS.getSection(coord)
  31.         local d1 = (coord[POS.beltDir] - chestSection) * initData.dirTopBelt[POS.beltDir]
  32.  
  33.         if d1 > 0 then return false end
  34.         return true
  35.     end
  36.  
  37.     local function getItemCount(itemName)
  38.         local num = 0
  39.         for cnt=1, 16 do
  40.             if turtle.getItemCount(cnt) > 0 then
  41.                 local item = turtle.getItemDetail(cnt)
  42.                 if not itemName or (item and item.name == itemName) then
  43.                     num = num + turtle.getItemCount(cnt)
  44.                 end
  45.             end
  46.            
  47.         end
  48.         return num
  49.     end
  50.     local function compactChestInventory(strDir)
  51.         local chest = peripheral.wrap(strDir)
  52.         local function getLastIndex(oldLast)
  53.             local chestList = chest.list()
  54.             for i=oldLast, 1, -1 do if chestList[i] then return i end end
  55.             return 1
  56.         end
  57.         local lastIdx = getLastIndex(54)
  58.         for i = 1, 54 do
  59.             if i > lastIdx then break end
  60.             local itemI = chest.getItemDetail(i, true)
  61.             if not itemI or (itemI and itemI.count < itemI.maxCount) then
  62.                 for j = i + 1, 54 do
  63.                     if j > lastIdx then break end
  64.                     local itemJ = chest.getItemDetail(j, true)
  65.                     if (not itemI and itemJ) or (itemJ and itemJ.name == itemI.name) then
  66.                         chest.pushItems(strDir, j, itemJ.count, i)
  67.                         itemI = chest.getItemDetail(i, true)
  68.                         if not itemI or itemI.count == itemI.maxCount then
  69.                             break
  70.                         end
  71.                     end
  72.                 end
  73.                 lastIdx = getLastIndex(lastIdx)
  74.             end
  75.         end
  76.     end
  77.     local function getChestSingleItem()
  78.         local chest = peripheral.wrap("front")
  79.         local actualItem = {
  80.                     name = "", dName = "itemDName",
  81.                     stackSize = 64, number = 0
  82.                 }
  83.         for i=1, 54 do
  84.             local item = chest.getItemDetail(i, true)
  85.             local itemD = SE.getItemInfo(item)
  86.             if itemD and actualItem.name == "" then
  87.                 actualItem = itemD
  88.             elseif itemD then
  89.                 if itemD.name == actualItem.name then
  90.                     actualItem.number = actualItem.number + itemD.number
  91.                 else
  92.                     return false, nil
  93.                 end
  94.             end
  95.         end
  96.         if actualItem.name == "" then
  97.             return true, nil
  98.         end
  99.         return true, actualItem
  100.     end
  101.  
  102.     local function calcChestPos()
  103.         local initData = SDM.TURTLE.loadInitData()
  104.         local num = getItemCount()
  105.  
  106.         local yCoord = -num % 5
  107.         local dirBeltCoord = 1
  108.         if num <= 50 then
  109.             dirBeltCoord = 0
  110.         else
  111.             num = num - 50
  112.         end
  113.         local dirSecCoord = math.floor(-((-num + 1) / 5))
  114.  
  115.         local pos = {x=dirBeltCoord, y=yCoord, z=dirSecCoord}
  116.  
  117.         if isCoordLeftSection(TT.Task.coords) then
  118.             return {
  119.                 [POS.beltDir] = TT.Task.coords[POS.beltDir] + dirBeltCoord * initData.dirBottomBelt[POS.beltDir],
  120.                 ["y"] = TT.Task.coords["y"] + yCoord,
  121.                 [POS.sectionDir] = TT.Task.coords[POS.sectionDir] + dirSecCoord * initData.dirSection[POS.sectionDir]
  122.             }
  123.         else
  124.             return {
  125.                 [POS.beltDir] = TT.Task.coords[POS.beltDir] + dirBeltCoord * initData.dirTopBelt[POS.beltDir],
  126.                 ["y"] = TT.Task.coords["y"] + yCoord,
  127.                 [POS.sectionDir] = TT.Task.coords[POS.sectionDir] + dirSecCoord * initData.dirSection[POS.sectionDir]
  128.             }
  129.         end
  130.     end
  131.  
  132.     local function goToUncheckedChest(chest)
  133.         local initData = SDM.TURTLE.loadInitData()
  134.  
  135.         if chest.checkState < 2 then
  136.             local targChestCoord = {x=chest.coords.x,y=chest.coords.y,z=chest.coords.z}
  137.             if isCoordLeftSection(targChestCoord) then
  138.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  139.             else
  140.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  141.             end
  142.             while not AM.goToCoord(targChestCoord) do
  143.                 while not POS.get_GPS_Position() do sleep(1) end
  144.             end
  145.             setTaskStatus(2)
  146.             return true
  147.         end
  148.         return false
  149.     end
  150.  
  151.     local function checkSingleChest(chest)
  152.         local initData = SDM.TURTLE.loadInitData()
  153.         if chest.checkState == 0 then
  154.             local targChestCoord = {x=chest.coords.x,y=chest.coords.y,z=chest.coords.z}
  155.             if isCoordLeftSection(targChestCoord) then
  156.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  157.                 BM.turnInDirection("LEFT")
  158.             else
  159.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  160.                 BM.turnInDirection("RIGHT")
  161.             end
  162.  
  163.             if not CVF.equalCoords(targChestCoord, POS.position) then
  164.                 setTaskStatus(1)
  165.             else
  166.                 local suc, item = getChestSingleItem()
  167.                 if suc then
  168.                     if item then
  169.                         chest.item = item
  170.                     end
  171.                     chest.checkState = 2
  172.                     SDM.TURTLE.saveTurtleTask(TT.Task)
  173.                 else
  174.                     chest.checkState = 1
  175.                     SDM.TURTLE.saveTurtleTask(TT.Task)
  176.                     while turtle.suck() do end
  177.                     setTaskStatus(3)
  178.                 end
  179.             end
  180.            
  181.             return true
  182.         end
  183.         if chest.checkState == 1 then
  184.             while turtle.suck() do end
  185.             if getItemCount() == 0 then
  186.                 chest.checkState = 2
  187.                 SDM.TURTLE.saveTurtleTask(TT.Task)
  188.                 setTaskStatus(2)
  189.             else
  190.                 setTaskStatus(3)
  191.             end
  192.             return true
  193.         end
  194.  
  195.         return false
  196.     end
  197.  
  198.     local function dropOfItems(dir)
  199.         local fktInspect = {
  200.             ["front"] = turtle.inspect,
  201.             ["top"] = turtle.inspectUp,
  202.             ["bottom"] = turtle.inspectDown
  203.         }
  204.         local fktDrop = {
  205.             ["front"] = turtle.drop,
  206.             ["top"] = turtle.dropUp,
  207.             ["bottom"] = turtle.dropDown
  208.         }
  209.  
  210.         local suc, block = fktInspect[dir]()
  211.         if not suc or block.name ~= "minecraft:chest" then return false end
  212.         local chest = peripheral.wrap(dir)
  213.         for cnt=1, 16 do
  214.             local item = turtle.getItemDetail(cnt, true)
  215.             local itemD = SE.getItemInfo(item)
  216.  
  217.             if itemD then
  218.                 turtle.select(cnt)
  219.                 fktDrop[dir]()
  220.             end
  221.         end
  222.         if getItemCount() == 0 then return true end
  223.         return false
  224.     end
  225.     local function pullItems(dir, num)
  226.         local fktInspect = {
  227.             ["front"] = turtle.inspect,
  228.             ["top"] = turtle.inspectUp,
  229.             ["bottom"] = turtle.inspectDown
  230.         }
  231.         local fktSuck = {
  232.             ["front"] = turtle.suck,
  233.             ["top"] = turtle.suckUp,
  234.             ["bottom"] = turtle.suckDown
  235.         }
  236.         local suc, block = fktInspect[dir]()
  237.         if not suc or block.name ~= "minecraft:chest" then return false end
  238.  
  239.  
  240.     end
  241.     local function selectItem(itemName)
  242.         for i=1, 16 do
  243.             if turtle.getItemCount(i) > 0 then
  244.                 local item = turtle.getItemDetail(i)
  245.                 if item.name == itemName then
  246.                     turtle.select(i)
  247.                     return true
  248.                 end
  249.             end
  250.         end
  251.         return false
  252.     end
  253.  
  254.     local function compactInventory()
  255.         for i = 1, 16 do
  256.             local itemI = turtle.getItemDetail(i)
  257.             if itemI and itemI.count < 64 then
  258.                 for j = i + 1, 16 do
  259.                     local itemJ = turtle.getItemDetail(j)
  260.                     if itemJ and itemJ.name == itemI.name then
  261.                         turtle.select(j)
  262.                         turtle.transferTo(i)
  263.                        
  264.                         -- Aktuellen Slot updaten
  265.                         itemI = turtle.getItemDetail(i)
  266.                         if not itemI or itemI.count == 64 then
  267.                             break
  268.                         end
  269.                     end
  270.                 end
  271.             end
  272.         end
  273.         turtle.select(1) -- zum Standard zurückkehren
  274.     end
  275.  
  276.     local function suckSpecificItem(itemName, count, strDir)
  277.         local chest = peripheral.wrap(strDir)
  278.         if not chest or not chest.list then
  279.             return false
  280.         end
  281.  
  282.         local chestItems = chest.list()
  283.         local foundSlots = {}
  284.         local totalAvailable = 0
  285.  
  286.         -- 1. Scans chest for requested Item
  287.         for slot, itemA in pairs(chestItems) do
  288.             local item = chest.getItemDetail(slot, true)
  289.             local itemD = SE.getItemInfo(item)
  290.             if itemD and itemD.name == itemName then
  291.                 table.insert(foundSlots, {slot = slot, count = itemD.number})
  292.                 totalAvailable = totalAvailable + itemD.number
  293.                 chestItems[slot].name = itemD.name
  294.             end
  295.         end
  296.         if count > totalAvailable then return false end
  297.         count = math.min(totalAvailable, count)
  298.         if count == 0 then
  299.             return false
  300.         end
  301.  
  302.         -- 2. Looks for available Slot for cached item
  303.         local cachedItemSlot = nil
  304.         for i = 1, 16 do
  305.             if turtle.getItemCount(i) == 0 then
  306.                 cachedItemSlot = i
  307.                 break
  308.             end
  309.         end
  310.  
  311.         if not cachedItemSlot then
  312.             print("Kein freier Slot zum Zwischenspeichern des Kisten-Items.")
  313.             return false
  314.         end
  315.  
  316.         turtle.select(cachedItemSlot)
  317.         local cachedItem = nil
  318.  
  319.         fktSuck = {
  320.             ["front"] = turtle.suck,
  321.             ["top"] = turtle.suckUp,
  322.             ["bottom"] = turtle.suckDown
  323.         }
  324.         fktDrop = {
  325.             ["front"] = turtle.drop,
  326.             ["top"] = turtle.dropUp,
  327.             ["bottom"] = turtle.dropDown
  328.         }
  329.         suck = fktSuck[strDir] or fktSuck["front"]
  330.         drop = fktDrop[strDir] or fktDrop["front"]
  331.  
  332.  
  333.         if chestItems[1] and chestItems[1].name ~= itemName then
  334.             if suck(64) then
  335.                 cachedItem = turtle.getItemDetail(cachedItemSlot)
  336.             end
  337.         end
  338.  
  339.         -- 3. Moves first requested item to slot 1
  340.         local nextSlotIndex = 1
  341.         if not chest.getItemDetail(1) then
  342.             local nextSource = foundSlots[nextSlotIndex]
  343.             chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  344.             nextSlotIndex = nextSlotIndex + 1
  345.         elseif (chest.getItemDetail(1) and SE.getItemInfo(chest.getItemDetail(1, true)).name == itemName) then
  346.             nextSlotIndex = nextSlotIndex + 1
  347.         end
  348.        
  349.         -- 4. Returns cached item (returns to first available chest slot ≠ 1)
  350.         if cachedItem then
  351.             turtle.select(cachedItemSlot)
  352.             drop()
  353.         end
  354.        
  355.         -- 5. Pulls requested items
  356.         local collected = 0
  357.         turtle.select(cachedItemSlot)
  358.         while collected < count do
  359.             local remaining = count - collected
  360.             local slot1Item = chest.getItemDetail(1)
  361.             local pullCount = math.min(slot1Item.count, remaining)
  362.            
  363.             if suck(pullCount) then
  364.                 collected = collected + pullCount
  365.             end
  366.  
  367.             if collected < count and nextSlotIndex <= #foundSlots then
  368.                 local nextSource = foundSlots[nextSlotIndex]
  369.                 chest.pushItems(strDir, nextSource.slot, nextSource.count, 1)
  370.                 nextSlotIndex = nextSlotIndex + 1
  371.             end
  372.         end
  373.         return true
  374.     end
  375.  
  376.  
  377.     function TT.getTask()
  378.         local initData = SDM.TURTLE.loadInitData()
  379.         local taskOutputCoord = initData.diskOutCoord
  380.  
  381.         taskOutputCoord.y = taskOutputCoord.y + 1
  382.         local task = SDM.TURTLE.loadTurtleTask()
  383.  
  384.         if CVF.equalCoords(POS.position, taskOutputCoord) then
  385.             if task and #textutils.serialize(task) == 2  then
  386.                 SDM.TURTLE.getNextOutgoingTask()
  387.                 task = SDM.TURTLE.loadTurtleTask()
  388.             else
  389.                 local tasksOut = SDM.getOutgoingTasks()
  390.                 if tasksOut and #textutils.serialize(tasksOut) > 2 then
  391.                     local firstTask = table.remove(tasksOut, 1)
  392.                     if firstTask.id == task.id then
  393.                         SDM.setOutgoingTasks(tasks)
  394.                     end
  395.                 end
  396.                 TT.Task = task
  397.                 return true
  398.             end
  399.         end
  400.         if task and #textutils.serialize(task) > 2  then
  401.             TT.Task = task
  402.             return true
  403.         end
  404.  
  405.         return false
  406.     end
  407.  
  408.     local bProgress = true
  409.     function TT.doIncomingTask()
  410.         local initData = SDM.TURTLE.loadInitData()
  411.         if TT.Task.status == 1 then
  412.             if suckSpecificItem(TT.Task.info.name, TT.Task.info.number, "top") then
  413.                 setTaskStatus(2)
  414.                 bProgress = true
  415.             else
  416.                 if bProgress then
  417.                     if SDM.TURTLE.update_SE() then
  418.                         os.reboot()
  419.                     else
  420.                         print("Waiting for more items in chest above.")
  421.                         bProgress = false
  422.                     end
  423.                 end
  424.                 sleep(1)
  425.             end
  426.         elseif TT.Task.status == 2 then
  427.             local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y,z=TT.Task.coords.z}
  428.             if isCoordLeftSection(targChestCoord) then
  429.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  430.             else
  431.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  432.             end
  433.             while not AM.goToCoord(targChestCoord) do
  434.                 while not POS.get_GPS_Position() do sleep(1) end
  435.             end
  436.             setTaskStatus(3)
  437.         end
  438.         if TT.Task.status == 3 then
  439.             local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y,z=TT.Task.coords.z}
  440.             if isCoordLeftSection(targChestCoord) then
  441.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  442.                 BM.turnInDirection("LEFT")
  443.             else
  444.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  445.                 BM.turnInDirection("RIGHT")
  446.             end
  447.             if not CVF.equalCoords(targChestCoord, POS.position) then
  448.                 setTaskStatus(2)
  449.             else
  450.                 if not dropOfItems("front") then
  451.                     compactChestInventory("front")
  452.                     if not dropOfItems("front") then
  453.                         setTaskStatus(4)
  454.                     else
  455.                         setTaskStatus(5)
  456.                     end
  457.                 else
  458.  
  459.                     setTaskStatus(5)
  460.                 end
  461.             end
  462.         end
  463.         if TT.Task.status == 4 then
  464.             local targChestCoord = {x=initData.chestOutCoord.x,y=initData.chestOutCoord.y-1,z=initData.chestOutCoord.z}
  465.             while not AM.goToCoord(targChestCoord) do
  466.                 while not POS.get_GPS_Position() do sleep(1) end
  467.             end
  468.             while not dropOfItems("top") do sleep(1) end
  469.             setTaskStatus(5)
  470.         end
  471.         if TT.Task.status == 5 then
  472.             local finishCoord = initData.diskFinishCoord
  473.             finishCoord.y = initData.diskFinishCoord.y + 1
  474.             while not AM.goToCoord(finishCoord) do
  475.                 while not POS.get_GPS_Position() do sleep(1) end
  476.             end
  477.             finishTask()
  478.             AM.joinQueue()
  479.             AM.queueForTask()
  480.         end
  481.         if TT.Task and #textutils.serialize(TT.Task) > 2 then
  482.             return TT.doIncomingTask()
  483.         end
  484.         return true
  485.     end
  486.  
  487.     function TT.doOutgoingTask()
  488.         local initData = SDM.TURTLE.loadInitData()
  489.         if TT.Task.status == 1 then
  490.             local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y,z=TT.Task.coords.z}
  491.             if isCoordLeftSection(targChestCoord) then
  492.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  493.             else
  494.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  495.             end
  496.             while not AM.goToCoord(targChestCoord) do
  497.                 while not POS.get_GPS_Position() do sleep(1) end
  498.             end
  499.             setTaskStatus(2)
  500.         elseif TT.Task.status == 2 then
  501.             local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y,z=TT.Task.coords.z}
  502.             if isCoordLeftSection(targChestCoord) then
  503.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  504.                 BM.turnInDirection("LEFT")
  505.             else
  506.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  507.                 BM.turnInDirection("RIGHT")
  508.             end
  509.             if not CVF.equalCoords(targChestCoord, POS.position) then
  510.                 setTaskStatus(2)
  511.             else
  512.                 if not suckSpecificItem(TT.Task.info.name, TT.Task.info.number, "front") then
  513.                     setTaskStatus(4)
  514.                 else
  515.                     setTaskStatus(3)
  516.                 end
  517.             end
  518.         elseif TT.Task.status == 3 then
  519.             local targChestCoord = {x=initData.chestOutCoord.x,y=initData.chestOutCoord.y-1,z=initData.chestOutCoord.z}
  520.             while not AM.goToCoord(targChestCoord) do
  521.                 while not POS.get_GPS_Position() do sleep(1) end
  522.             end
  523.             while not dropOfItems("top") do sleep(1) end
  524.             setTaskStatus(4)
  525.         elseif TT.Task.status == 4 then
  526.             local finishCoord = initData.diskFinishCoord
  527.             finishCoord.y = initData.diskFinishCoord.y + 1
  528.             while not AM.goToCoord(finishCoord) do
  529.                 while not POS.get_GPS_Position() do sleep(1) end
  530.             end
  531.             finishTask()
  532.             AM.joinQueue()
  533.             AM.queueForTask()
  534.         end
  535.  
  536.         if TT.Task and #textutils.serialize(TT.Task) > 2 then
  537.             return TT.doOutgoingTask()
  538.         end
  539.         return true
  540.     end
  541.  
  542.     function TT.doCreateChest()
  543.         local initData = SDM.TURTLE.loadInitData()
  544.         if TT.Task.status == 1 then
  545.             BM.turnInDirection("RIGHT")
  546.             if suckSpecificItem("minecraft:chest", 100, "front") then
  547.                 print("Succeeded")
  548.                 setTaskStatus(2)
  549.                 bProgress = true
  550.             else
  551.                 if bProgress then
  552.                     print("Waiting for more chests in chest infront.")
  553.                     bProgress = false
  554.                 end
  555.                 sleep(1)
  556.             end
  557.         elseif TT.Task.status == 2 then
  558.             local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y,z=TT.Task.coords.z}
  559.             if isCoordLeftSection(targChestCoord) then
  560.                 targChestCoord = CVF.add(targChestCoord, initData.dirTopBelt)
  561.             else
  562.                 targChestCoord = CVF.add(targChestCoord, initData.dirBottomBelt)
  563.             end
  564.             while not AM.goToCoord(targChestCoord) do
  565.                 while not POS.get_GPS_Position() do sleep(1) end
  566.             end
  567.             if isCoordLeftSection(targChestCoord) then
  568.                 BM.turnInDirection("LEFT")
  569.             else
  570.                 BM.turnInDirection("RIGHT")
  571.             end
  572.             setTaskStatus(3)
  573.         elseif TT.Task.status == 3 then
  574.             while getItemCount("minecraft:chest") > 0 do
  575.                 local targChestCoord = calcChestPos()
  576.                 AM.reachChestPlacementCoord(targChestCoord)
  577.                 selectItem("minecraft:chest")
  578.                 while not turtle.placeDown() do sleep(0.5) end
  579.             end
  580.  
  581.             if getItemCount("minecraft:chest") == 0 then
  582.                 local targChestCoord = {x=TT.Task.coords.x,y=TT.Task.coords.y + 4,z=TT.Task.coords.z}
  583.                 AM.reachChestPlacementCoord(targChestCoord)
  584.                 if isCoordLeftSection(targChestCoord) then
  585.                     BM.turnInDirection("RIGHT")
  586.                 else
  587.                     BM.turnInDirection("LEFT")
  588.                 end
  589.                 while not BM.forward() do sleep(0.1) end
  590.                 while not BM.down() do sleep(0.1) end
  591.                 setTaskStatus(4)
  592.             end
  593.         elseif TT.Task.status == 4 then
  594.             local finishCoord = initData.diskFinishCoord
  595.             finishCoord.y = initData.diskFinishCoord.y + 1
  596.             while not AM.goToCoord(finishCoord) do
  597.                 while not POS.get_GPS_Position() do sleep(1) end
  598.             end
  599.             finishTask()
  600.             AM.joinQueue()
  601.             AM.queueForTask()
  602.         end
  603.  
  604.         if TT.Task and #textutils.serialize(TT.Task) > 2 then
  605.             return TT.doCreateChest()
  606.         end
  607.         return true
  608.     end
  609.  
  610.     function TT.doCheckChests()
  611.         local initData = SDM.TURTLE.loadInitData()
  612.         local chests = TT.Task.chests
  613.  
  614.         if TT.Task.status == 1 then
  615.             print("GOTO Chest")
  616.             for _, chest in ipairs(chests) do
  617.                 if goToUncheckedChest(chest) then break end
  618.             end
  619.         elseif TT.Task.status == 2 then
  620.             print("CHECK Chest")
  621.             local bCheckedAll = true
  622.             for _, chest in ipairs(chests) do
  623.                 if checkSingleChest(chest) then break end
  624.             end
  625.             for _, chest in ipairs(chests) do
  626.                 bCheckedAll = bCheckedAll and chest.checkState == 2
  627.             end
  628.             if bCheckedAll then
  629.                 setTaskStatus(4)
  630.             end
  631.  
  632.         elseif TT.Task.status == 3 then
  633.             print("DROP Items")
  634.             local targChestCoord = {x=initData.chestOutCoord.x,y=initData.chestOutCoord.y-1,z=initData.chestOutCoord.z}
  635.             while not AM.goToCoord(targChestCoord) do
  636.                 while not POS.get_GPS_Position() do sleep(1) end
  637.             end
  638.             while not dropOfItems("top") do sleep(1) end
  639.             setTaskStatus(1)
  640.         elseif TT.Task.status == 4 then
  641.             print("FINISH")
  642.             local finishCoord = initData.diskFinishCoord
  643.             finishCoord.y = initData.diskFinishCoord.y + 1
  644.             while not AM.goToCoord(finishCoord) do
  645.                 while not POS.get_GPS_Position() do sleep(1) end
  646.             end
  647.             finishTask()
  648.             AM.joinQueue()
  649.             AM.queueForTask()
  650.         end
  651.  
  652.         if TT.Task and #textutils.serialize(TT.Task) > 2 then
  653.             return TT.doCheckChests()
  654.         end
  655.         return true
  656.  
  657.     end
  658.  
  659.  
  660.  
  661.     return TT
Advertisement
Add Comment
Please, Sign In to add comment