Advertisement
DustinRosebery

wallSwap2.0

Nov 15th, 2014
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local t = turtle
  2.  
  3. local function dropCheck()
  4.     while true do
  5.         os.sleep(1)
  6.         if t.detect == true then
  7.         t.dig()             --clears falling blocks until there are no more blocks in the space ahead
  8.         else
  9.         break
  10.         end
  11.     end
  12. end
  13.  
  14. local function reSupply()
  15.     t.select(15)
  16.     t.turnLeft()
  17.     t.dig()
  18.     t.place()
  19.  
  20.     for i = 9, 14, 1 do         --places red ender chest and gets inventory to place for slots 9-14
  21.         t.select(i)
  22.         t.suck()
  23.     end
  24.  
  25.     t.select(15)
  26.     t.dig()
  27.     t.turnRight()
  28. end
  29.  
  30.  
  31. local function clearInventory()     --places white ender chest and selects inventory slots 1-8 and places them in it
  32.  
  33.         t.select(16)  
  34.         t.turnRight()  
  35.         t.dig()
  36.         t.place()
  37.        
  38.         for i = 1, 8, 1 do      
  39.                 t.select(i)
  40.                 t.drop()
  41.     end
  42.  
  43.         t.select(16)
  44.         t.dig()
  45.         t.turnLeft()
  46. end
  47.  
  48. local function matCheck()
  49.  
  50.     for i = 9, 14, 1 do
  51.        
  52.         itemCount = t.getItemCount(i)
  53.         t.select(i)
  54.         if itemCount > 0 then
  55.  
  56.         break end               --if slot 14 has less than 64 supply, the resupply function is run
  57.  
  58.         if t.getItemCount(14) < 64 then
  59.         reSupply()
  60.         end
  61.     end
  62. end
  63.  
  64. local function goingUp()
  65.  
  66.     blockAbove = false 
  67.  
  68.     repeat
  69.  
  70.     itemCount = t.getItemCount(8)     --checks last open incoming slot and if it has inventory, will clearinventory
  71.         if itemCount > 0 then
  72.             clearInventory()
  73.     end
  74.  
  75.     matCheck()            --Digs up until a block is detected above the turtle
  76.     t.dig()
  77.     dropCheck()
  78.     t.place()
  79.     t.up()
  80.    
  81.     if t.detectUp() then
  82.         blockAbove = true
  83.     end
  84.    
  85.     until blockAbove == true
  86. end
  87.    
  88. local function keepGoing()
  89.    
  90.     t.turnRight()
  91.     flag = true
  92.    
  93.     if t.detect() then          --determines if there is a block to the right of the turtle and stops program
  94.     flag = false                --if there is
  95.     end
  96.    
  97.     t.turnLeft()
  98.     return flag
  99. end
  100.    
  101. local function topDown()
  102.    
  103.     itemCount = t.getItemCount(16)
  104.         if itemCount > 0 then
  105.             clearInventory()
  106.     end                     --positions the turtle at the top of a column to start digging down
  107.  
  108.     matCheck()
  109.     t.dig()
  110.     t.place()
  111.     t.turnRight()
  112.     t.forward()
  113.     t.turnLeft()
  114. end
  115.  
  116. local function goingDown()
  117.    
  118.     blockBelow = false
  119.  
  120.     repeat
  121.    
  122.     itemCount = t.getItemCount(8)
  123.     if itemCount > 0 then       --checks inventory and digs down until a block is undearneath
  124.             clearInventory()
  125.     end
  126.  
  127.     matCheck()
  128.     t.dig()
  129.     t.place()
  130.     t.down()
  131.  
  132.     if t.detectDown() then
  133.         blockBelow = true
  134.     end
  135.  
  136.     until blockBelow == true
  137. end
  138.    
  139. local function bottomUp()
  140.  
  141.     itemCount = t.getItemCount(8)
  142.         if itemCount > 0 then
  143.             clearInventory()
  144.     end             --positions the turtle at the bottom of next column to start digging up.
  145.  
  146.     matCheck()
  147.     t.dig()
  148.     t.place()
  149.     t.turnRight()
  150.     t.forward()
  151.     t.turnLeft()
  152. end
  153.  
  154. --_________________________________END OF FUNCTIONS________________________________________
  155. while true do
  156.     goingUp()
  157.         if keepGoing() == false
  158.             break
  159.         end
  160.     topDown()
  161.     goingDown()
  162.         if keepGoing() == false
  163.             break
  164.         end
  165.     bottomUp()
  166. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement