Advertisement
CelticCoder

turtleDelivery

May 12th, 2024 (edited)
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.75 KB | None | 0 0
  1. os.loadAPI("turtleChest.lua")
  2. os.loadAPI("predictPath.lua")
  3. os.loadAPI("turtleOneTrip.lua")
  4.  
  5.  
  6.  
  7. function getLocation()
  8.     turtle.equipLeft()
  9.     cx, cy, cz = gps.locate()
  10.     turtle.equipLeft()
  11.     return cx, cy, cz
  12. end
  13.  
  14. function predictTotalFuelCostDelivery(x, y, z, cx, cy, cz)
  15.     path = {1}
  16.     predictPath.resetFuelCost()
  17.     predictPath.predictTwo(x, y, z, cx, cy, cz, path)
  18.     predictPath.finalWrite(predictPath.getPath())
  19.     fuelcost = predictPath.getFuelCost()
  20.     print("cost" .. fuelcost)
  21.     if fuelcost > turtle.getFuelLevel() then
  22.         getTurtleFuel.displayFuelInfo()
  23.         print("Fuel Needed: " .. fuelcost)
  24.         print("Fuel too Low to Start, Please Insert Buckets")
  25.         return false
  26.     end
  27.     return true
  28. end
  29.  
  30. function predictTotalFuelCostUPS(ax, ay, az, bx, by, bz)
  31.     path = {1}
  32.     predictPath.resetFuelCost()
  33.     predictPath.predictTwo(ax, ay, az, bx, by, bz, path)
  34.     predictPath.predict(bx, by, bz, path)
  35.     predictPath.finalWrite(predictPath.getPath())
  36.     fuelcost = predictPath.getFuelCost()
  37.     print("cost" .. fuelcost)
  38.     if fuelcost > turtle.getFuelLevel() then
  39.         getTurtleFuel.displayFuelInfo()
  40.         print("Fuel Needed: " .. fuelcost)
  41.         print("Fuel too Low to Start, Please Insert Buckets")
  42.         return false
  43.     end
  44.     return true
  45. end
  46.  
  47. function placeCarePackage()
  48.     turtle.dig()
  49.     turtle.select(2)
  50.     turtle.place()
  51.     turtleChest.insertSome(2)
  52. end
  53.  
  54. turtleChest.insertSome(2)
  55.  
  56. function sendUPS(ax, ay, az, bx, by, bz)
  57.     sx, sy, sz = getLocation()
  58.     if predictTotalFuelCostUPS(ax, ay, az, bx, by, bz) then
  59.         if turtleOneTrip.oneTrip(ax, ay, az) then
  60.             turtleChest.takeAll()
  61.             if not turtleOneTrip.oneTrip(bx, by, bz) then
  62.                 hx, hy, hz = getLocation()
  63.                 return "help " ..  hx .. " " .. hy .. " " .. hz
  64.             else
  65.                 turtleChest.insertSome(2)
  66.                 if not turtleOneTrip.oneTrip(sx, sy, sz) then
  67.                     hx, hy, hz = getLocation()
  68.                     return "help " ..  hx .. " " .. hy .. " " .. hz
  69.                 else
  70.                     return "true"
  71.                 end
  72.             end
  73.         end
  74.     else
  75.         return "fuel"
  76.     end
  77. end
  78.  
  79. function sendDelivery(x, y, z)
  80.     sx, sy, sz = getLocation()
  81.     if predictTotalFuelCostDelivery(x, y, z, sx, sy, sz) then
  82.         if turtleOneTrip.oneTrip(x, y, z) then
  83.             turtleChest.insertSome(2)
  84.             if not turtleOneTrip.oneTrip(sx, sy, sz) then
  85.                 hx, hy, hz = getLocation()
  86.                 return "help " ..  hx .. " " .. hy .. " " .. hz
  87.             else
  88.                 return "true"
  89.             end
  90.         end
  91.     else
  92.         return "fuel"
  93.     end
  94. end
  95.  
  96. function sendCarePackage(x, y, z)
  97.     sx, sy, sz = getLocation()
  98.     if predictTotalFuelCostDelivery(x, y, z, sx, sy, sz) then
  99.         if turtleOneTrip.oneTrip(x, y, z) then
  100.             placeCarePackage()
  101.             if not turtleOneTrip.oneTrip(sx, sy, sz) then
  102.                 hx, hy, hz = getLocation()
  103.                 return "help " ..  hx .. " " .. hy .. " " .. hz
  104.             else
  105.                 return "true"
  106.             end
  107.         end
  108.     else
  109.         return "fuel"
  110.     end
  111. end
  112.  
  113.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement