ArsKvsh

[CC] 5+1 glass holes

Jan 29th, 2020
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.85 KB | None | 0 0
  1. if not turtle then
  2.     printError( "Requires a Turtle" )
  3.     return
  4. end
  5.  
  6. local tArgs = { ... }
  7. if #tArgs ~= 2 then
  8.     print( "Usage: gh <length> <width>" )
  9.     return
  10. end
  11.  
  12. -- Mine in a quarry pattern until we hit something we can't dig
  13. local length = tonumber( tArgs[1] )
  14. local width = tonumber( tArgs[2] )
  15.  
  16. if length < 1 then
  17.     print( "Length must be natural number" )
  18.     return
  19. end
  20.  
  21. if width < 1 then
  22.     print( "Width must be natural number" )
  23.     return
  24. end
  25.  
  26. local depth = 0
  27. local item = 1
  28.  
  29. local function refuel()
  30.     local fuelLevel = turtle.getFuelLevel()
  31.     if fuelLevel == "unlimited" or fuelLevel > 0 then
  32.         return
  33.     end
  34.  
  35.     local function tryRefuel()
  36.         for n=1,16 do
  37.             if turtle.getItemCount(n) > 0 then
  38.                 turtle.select(n)
  39.                 if turtle.refuel(1) then
  40.                     turtle.select(1)
  41.                     return true
  42.                 end
  43.             end
  44.         end
  45.         turtle.select(1)
  46.         return false
  47.     end
  48.  
  49.     if not tryRefuel() then
  50.         print( "Add more fuel to continue." )
  51.         while not tryRefuel() do
  52.             os.pullEvent( "turtle_inventory" )
  53.         end
  54.         print( "Resuming floor building..." )
  55.     end
  56. end
  57.  
  58. local function charge()
  59.     local function tryCharge()
  60.         for n=1,16 do
  61.             if turtle.getItemCount(n) > 0 then
  62.                 if turtle.getItemDetail(n).name == "chisel:glass" then
  63.                     turtle.select(n)
  64.                     return true
  65.                 end
  66.             end
  67.         end
  68.         turtle.select(2)
  69.         return false
  70.     end
  71.     if not tryCharge() then
  72.         print( "Add more material to continue." )
  73.         while not tryCharge() do
  74.             os.pullEvent( "turtle_inventory" )
  75.         end
  76.         print( "Resuming floor building..." )
  77.     end
  78. end
  79.  
  80. local function tryForward()
  81.     refuel()
  82.     while not turtle.forward() do
  83.         if turtle.detect() then
  84.             if not tryDig() then
  85.                 return false
  86.             end
  87.         elseif turtle.attack() then
  88.         else
  89.             sleep( 0.1 )
  90.         end
  91.     end
  92.     return true
  93. end
  94.  
  95. local function tryUp()
  96.     refuel()
  97.     while not turtle.up() do
  98.         if turtle.detectUp() then
  99.             if not tryDigUp() then
  100.                 return false
  101.             end
  102.         elseif turtle.attackUp() then
  103.         else
  104.             sleep( 0.1 )
  105.         end
  106.     end
  107.     return true
  108. end
  109.  
  110. local function tryDigDown()
  111.     while turtle.detectDown() do
  112.         if turtle.digDown() then
  113.             sleep(0.1)
  114.         else
  115.             return false
  116.         end
  117.     end
  118.     return true
  119. end
  120.  
  121. local function tryDown()
  122.     refuel()
  123.     while not turtle.down() do
  124.         if turtle.detectDown() then
  125.             if not tryDigDown() then
  126.                 return false
  127.             end
  128.         elseif turtle.attackDown() then
  129.         else
  130.             sleep( 0.1 )
  131.         end
  132.     end
  133.     return true
  134. end
  135.  
  136. local function tryPlaceDown()
  137.     refuel()
  138.     charge()
  139.     while not turtle.detectDown() do
  140.         if turtle.placeDown() then
  141.             sleep(0.1)
  142.         else
  143.             return false
  144.         end
  145.     end
  146.     return true
  147. end
  148.  
  149. print( "Building the floor..." )
  150.  
  151. local function buildForward(dir)
  152.     for n=1,dir do
  153.         for x=1,6 do
  154.             tryForward()
  155.         end
  156.         tryDown()
  157.         tryDigDown()
  158.         tryUp()
  159.         tryPlaceDown()
  160.     end
  161. end
  162.  
  163. local frwDir = true;
  164.  
  165. tryDown()
  166. tryDigDown()
  167. tryUp()
  168. tryPlaceDown()
  169.  
  170. length = length - 1
  171. width = width - 1
  172.  
  173. while (length > 0 or width > 0) do
  174.     if frwDir == true then
  175.         buildForward(length)
  176.         width = width - 1
  177.         frwDir = false
  178.     else
  179.         buildForward(width)
  180.         length = length - 1
  181.         frwDir = true
  182.     end
  183.     turtle.turnRight()
  184. end
  185.  
  186. print( "Floor building complete" )
Add Comment
Please, Sign In to add comment