CelticCoder

turtleGeoScanMine

Dec 1st, 2024 (edited)
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.loadAPI("turtleManualOneTrip.lua")
  2. --start with pick in left and geoscanner in right of turtle, and modem in first slot
  3.  
  4. function scan()
  5.     scanner = peripheral.wrap("right")
  6.     if scanner.cost(15) > scanner.getFuelLevel() then
  7.         print("Not Enough Fuel")
  8.         print("Cost: " .. scanner.cost(15))
  9.         print("Fuel Level: " .. scanner.getFuelLevel() .. "/" .. scanner.getMaxFuelLevel())
  10.         os.exit(1)
  11.     end
  12.  
  13.     turtle.equipRight()
  14.     rednet.open("right")
  15.     cx, cy, cz = gps.locate()
  16.     if cx == nil and cy == nil and cz == nil then
  17.         print("GPS Error")
  18.         os.exit(1)
  19.     end
  20.     turtle.equipRight()
  21.  
  22.     if not item and choice == 2 then
  23.         print("No Name Inputted")
  24.         os.exit(1)
  25.     end
  26.  
  27.     return scanner.scan(15)
  28. end
  29.  
  30. function findItemSlot(itemName)
  31.     for slot = 1, 16 do
  32.         local itemDetail = turtle.getItemDetail(slot)
  33.         if itemDetail and itemDetail.name == itemName then
  34.             return slot
  35.         end
  36.     end
  37.     return nil
  38. end
  39.  
  40. function splitPairs(pairsArray)
  41.     local keys = {}
  42.     local values = {}
  43.  
  44.     for _, pair in ipairs(pairsArray) do
  45.         table.insert(keys, pair[1])
  46.         table.insert(values, pair[2])
  47.     end
  48.  
  49.     return keys, values
  50. end
  51.  
  52. function dropUnwantedItems(allowedItems)
  53.     table.insert(allowedItems, "computercraft:wireless_modem_normal")
  54.     for slot = 1, 16 do
  55.         local itemDetail = turtle.getItemDetail(slot)
  56.         if itemDetail then
  57.             local isAllowed = false
  58.             -- Check if the item is in the allowed list
  59.             for _, allowedItem in ipairs(allowedItems) do
  60.                 if itemDetail.name == allowedItem then
  61.                     isAllowed = true
  62.                     break
  63.                 end
  64.             end
  65.             -- Drop the item if it's not allowed
  66.             if not isAllowed then
  67.                 turtle.select(slot)
  68.                 turtle.drop()
  69.                 print("Dropped unwanted item: " .. itemDetail.name)
  70.             end
  71.         end
  72.     end
  73. end
  74.  
  75. function geoMineItem(item)
  76.     blocks = scan()
  77.     if blocks ~= nil then
  78.         for _, block in pairs(blocks) do
  79.             if block.name == item then
  80.                 x = cx + block.x
  81.                 y = cy + (block.y + 1)
  82.                 z = cz + block.z
  83.                 turtleManualOneTrip.goToCordsMine(x, y, z)
  84.             end
  85.         end
  86.         turtleManualOneTrip.goToCordsMine(cx, cy, cz)
  87.     else
  88.         print("Couldnt Scan")
  89.     end
  90. end
  91.  
  92. function geoMineList(itemlist)
  93.     itemlist, matlist = splitPairs(itemlist)
  94.     found = false
  95.     if itemlist ~= nil then
  96.         blocks = scan()
  97.     else
  98.         print("Itemlist no found")
  99.         os.exit(1)
  100.     end
  101.     if blocks ~= nil and itemlist ~= nil then
  102.         for _, block in pairs(blocks) do
  103.             for _, item in pairs(itemlist) do
  104.                 if block.name == item then
  105.                     x = cx + block.x
  106.                     y = cy + (block.y + 1)
  107.                     z = cz + block.z
  108.                     slot = findItemSlot("computercraft:wireless_modem_normal")
  109.                     if slot ~= nil then
  110.                         turtle.select(slot)
  111.                     end
  112.                     turtleManualOneTrip.goToCordsMine(x, y, z)
  113.                     dropUnwantedItems(matlist)
  114.                     found = true
  115.                 end
  116.             end
  117.         end
  118.         if found then
  119.             dropUnwantedItems(matlist)
  120.             slot = findItemSlot("computercraft:wireless_modem_normal")
  121.             if slot ~= nil then
  122.                 turtle.select(slot)
  123.             end
  124.             turtleManualOneTrip.goToCordsMine(cx, cy, cz)
  125.             dropUnwantedItems(matlist)
  126.             turtle.digUp()
  127.             turtle.up()
  128.         end
  129.     elseif blocks == nil  then
  130.         print("Couldnt Scan")
  131.     elseif itemlist == nil then
  132.         print("Itemlist no found")
  133.     end
  134. end
Advertisement
Add Comment
Please, Sign In to add comment