Advertisement
Guest User

Drain

a guest
May 23rd, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.91 KB | None | 0 0
  1. local x = 0
  2. local y = 0
  3.  
  4. local xPos = 0
  5. local yPos = 0
  6.  
  7. local last = false
  8. local done = false
  9. local levelDone = false
  10.  
  11. local function goDwn()
  12.   local floor = false
  13.   for i=0, 6 do
  14.     if not turtle.down() then
  15.       floor = true
  16.     end
  17.   end
  18.   return floor
  19. end
  20.      
  21.  
  22. local function drain()
  23.   turtle.select(1)
  24.   turtle.placeUp()
  25.   sleep(1)
  26.   turtle.digUp()
  27. end
  28.  
  29. local function nextLine()
  30.   drain()
  31.  
  32.   local startPos = yPos
  33.   turtle.turnRight()
  34.   for i=0, 6 do
  35.     if yPos < y then
  36.       if turtle.forward() then
  37.         yPos = yPos+1
  38.       end
  39.     end
  40.   end
  41.   turtle.turnLeft()  
  42.   if startPos == yPos then
  43.     if goDwn() then
  44.       last = true
  45.     end
  46.     turtle.turnLeft()
  47.     for i=0, y-1 do
  48.       turtle.forward()
  49.     end
  50.     yPos = 0
  51.     turtle.turnRight()
  52.     if xPos == x-1 then
  53.       for i=0, x do
  54.         turtle.back()
  55.       end
  56.       xPos = 0
  57.     end
  58.     if last == true then
  59.       done = true
  60.     end
  61.     levelFinished = true
  62.   end
  63. end
  64.  
  65. local function startDraining()
  66.   print("enter x: ")
  67.   x = tonumber(read())
  68.   print("enter y: ")
  69.   y = tonumber(read())
  70.  
  71.   turtle.down()
  72.   turtle.down()
  73.   turtle.down()  
  74.   while not done do
  75.  
  76.     drain()
  77.      
  78.     levelFinished = false
  79.     for i=0, x-1 do
  80.       if turtle.forward() then
  81.         xPos = xPos+1
  82.       end
  83.    
  84.       if xPos % 6 == 0 then
  85.         drain()
  86.       end
  87.  
  88.       if xPos == x then
  89.         nextLine()
  90.       end  
  91.     end
  92.  
  93.     drain()
  94.     if not levelFinished then
  95.       for i=0, x-1 do
  96.         if turtle.back() then
  97.           xPos = xPos-1
  98.         end
  99.    
  100.         if xPos % 6 == 0 then
  101.           drain()
  102.         end
  103.      
  104.         if xPos == 0 then
  105.           drain()
  106.           nextLine()        
  107.         end
  108.       end
  109.     end
  110.   end
  111. end
  112.  
  113. if turtle.getItemCount(1) == 0 then
  114.   print("No sponge found in slot 1")
  115. else
  116.   print("Sponge found")
  117.   startDraining()
  118. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement