blunderhund

quarry

Mar 30th, 2021
388
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.80 KB | None | 0 0
  1. local craplib = require("libs.craplib")
  2.  
  3. local tArgs = {...}
  4.  
  5. -- handle cli arguments
  6. if #tArgs > 2 or tArgs[1] == "help" then
  7.     print()
  8.     print("Usage: quarry [option] [diameter]")
  9.     print("              [altitude]")
  10.     print()
  11.     print("Options:")
  12.     print("  -d  specify heigth to start digging")
  13.     print()
  14.     return
  15. end
  16.  
  17. local size
  18. local goDown = 0
  19.  
  20. local function readParams()
  21.     write("diameter: ")
  22.     size = tonumber(io.read())
  23.     write("altitude: ")
  24.     temp = tonumber(io.read())
  25.     if temp ~= nil then craplib.setAltitude(temp) end
  26. end
  27.  
  28. local function readArgs()
  29.     if #tArgs == 0 then
  30.         readParams()
  31.         return
  32.     end
  33.  
  34.     local valid_args = false
  35.  
  36.     local skip_one = false
  37.     for i = 1, #tArgs - 1 do
  38.         if skip_one then do break end end
  39.  
  40.         if tArgs[i] == "-d" then
  41.             skip_one = true
  42.             goDown = tonumber(tArgs[i + 1])
  43.  
  44.             -- elseif tostring(tArgs[i]).find("-") then
  45.             -- print( "unrecognized argument " + tArgs[i] )
  46.  
  47.         elseif #tArgs - i <= 2 then
  48.             size = tonumber(tArgs[i])
  49.             if #tArgs > i then
  50.                 craplib.setAltitude(tonumber(tArgs[i + 1]))
  51.             end
  52.  
  53.             valid_args = true
  54.             i = #tArgs -- end for loop
  55.         end
  56.     end
  57.  
  58.     if not valid_args then readParams() end
  59. end
  60.  
  61. local function checkArgs()
  62.     if craplib.getAltitude() ~= 0 then
  63.         if craplib.getAltitude() > 0 then
  64.             downwards = false
  65.             craplib.setAltitude(craplib.getAltitude() - 1)
  66.         else
  67.             craplib.setAltitude(craplib.getAltitude() + 1)
  68.         end
  69.     end
  70.  
  71.     if size == nil or size < 1 then
  72.         print("Diameter must be a positive number")
  73.         return
  74.     end
  75. end
  76.  
  77. -- ############################################################
  78. -- Mine in a quarry pattern until we hit something we can't dig
  79. -- ############################################################
  80.  
  81. local function main()
  82.     readArgs()
  83.     checkArgs()
  84.  
  85.     turtle.select(1)
  86.  
  87.     if turtle.getItemCount(1) > 0 then
  88.         item = turtle.getItemDetail(1).name
  89.         if string.find(item, "bucket") then craplib.setFuelLava() end
  90.     end
  91.  
  92.     craplib.turnLeft()
  93.  
  94.     if turtle.detect() and turtle.suck(1) and turtle.refuel(0) then
  95.         craplib.setFuelChest()
  96.         turtle.suck(1)
  97.         craplib.supplyChest()
  98.     end
  99.  
  100.     craplib.turnRight()
  101.  
  102.     if not craplib.refuel() then
  103.         print("Out of Fuel")
  104.         return
  105.     end
  106.  
  107.     print("Excavating...")
  108.  
  109.     if goDown ~= 0 then
  110.         if downwards then
  111.             for i = 1, goDown do craplib.goDown() end
  112.         else
  113.             for i = 1, goDown do craplib.goUp() end
  114.         end
  115.     end
  116.  
  117.     craplib.quarry(size)
  118.  
  119.     craplib.endTour()
  120.  
  121. end
  122.  
  123. main()
Advertisement
Add Comment
Please, Sign In to add comment