Advertisement
Guest User

myQuarry

a guest
Jan 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.16 KB | None | 0 0
  1. local enderchestSlot = 1
  2. local diamondSlot = 2
  3. local uraniumSlot = 3
  4.  
  5. local heightToDig = 70
  6. local widthToDig = 6 -- actually doubled
  7. local lengthToDig = 6 -- actually doubled
  8.  
  9.  
  10. term.clear()
  11. print("Place enderchest in slot 1")
  12. print("")
  13. print("Press ENTER to start")
  14.  
  15. -- wait untill ENTER is pressed to start
  16. while true do
  17.                     press, key = os.pullEvent()
  18.                     if press == "key" and key == 28 then
  19.                             break
  20.                     end
  21. end
  22.  
  23.  
  24. local p = peripheral.wrap("left")
  25.  
  26. if p ~= nil then -- check if it can connect to the peripheral
  27.   print("")
  28.   print("connected")
  29. else
  30.   print("")
  31.   print("can't connect")
  32. end
  33.  
  34.  
  35. print("")
  36. print("running code")
  37. print("")
  38.  
  39.  
  40.  
  41. function digForward()
  42.     local p = peripheral.wrap("left")
  43.     p.dig()
  44. end
  45.  
  46. function digLeft()
  47.     local p = peripheral.wrap("left")
  48.     turtle.turnLeft()
  49.     p.dig()
  50.     turtle.turnRight()
  51. end
  52.  
  53. function digRight()
  54.     local p = peripheral.wrap("left")
  55.     turtle.turnRight()
  56.     p.dig()
  57.     turtle.turnLeft()
  58. end
  59.  
  60. function checkIfFull()
  61.  
  62. print("")
  63. print("checking inventory")
  64. print("")
  65. ItemCount=turtle.getItemCount(16)
  66.     if ItemCount > 0 then
  67.        
  68.         -- the chest is full so we need to turn around and place the enderchest
  69.         turtle.turnLeft()
  70.         turtle.turnLeft()
  71.         p.dig()
  72.         turtle.select(enderchestSlot)
  73.         turtle.place()
  74.         --turtle.sleep(120)
  75.  
  76.        
  77.        
  78.         -- drop everything except diamonds
  79.         for j=2, 16 do
  80.        
  81.             local data = turtle.getItemDetail(j)
  82.  
  83.                 if data then
  84.                     print("Item name: ", data.name)
  85.                    
  86.                     if data.name=="minecraft:diamond" then
  87.                         turtle.transferTo(diamondSlot)                     
  88.                     end
  89.  
  90.  
  91.                     if data.name=="IC2:blockOreUran" then
  92.                         turtle.transferTo(uraniumSlot)                     
  93.                     end
  94.  
  95.  
  96.                     if data.name~="minecraft:diamond" and data.name~="IC2:blockOreUran" then
  97.                         turtle.select(j)
  98.                         turtle.drop()
  99.                     end
  100.                 end
  101.  
  102.  
  103.         end
  104.        
  105.        
  106.         -- now we need to break the enderchest and add it back to the inventory
  107.         local p = peripheral.wrap("left")
  108.         turtle.select(enderchestSlot)
  109.         p.dig()
  110.         turtle.turnLeft()
  111.         turtle.turnLeft()
  112.        
  113.        
  114.     else
  115.         print("turtle is not full")
  116.     end
  117. end
  118.  
  119.  
  120.  
  121. function digForwardGravel()
  122.  
  123. if turtle.forward() == false then
  124.     repeat
  125.         p.dig()
  126.         sleep(1)
  127.         until turtle.forward() == true
  128. end
  129. end
  130.  
  131.  
  132.  
  133. function main_code()
  134.     for lengthCounter=1, lengthToDig do
  135.    
  136.    
  137.     -- go forward into the first block
  138.     local p = peripheral.wrap("left")
  139.     p.dig()
  140.     digRight()
  141.     turtle.forward()
  142.    
  143.    
  144.    for widthCounter=1, widthToDig do
  145.    
  146.        
  147.         heightCounter=1
  148.         -- go up the first column and dig to the right also
  149.         while heightCounter < heightToDig do         
  150.             checkIfFull()
  151.             p.dig()
  152.             p.digUp()
  153.  
  154.            
  155.             if turtle.up() == false then
  156.                 repeat
  157.                 p.digUp()
  158.                 sleep(1)
  159.                 until turtle.up() == true
  160.             end
  161.             heightCounter = heightCounter + 1
  162.             digRight() 
  163.             end
  164.        
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.         -- we have reached the top of a vertical column so we need to move right by 1
  173.         p.dig()
  174.         turtle.turnRight()
  175.         p.dig()
  176.         turtle.forward()
  177.         --p.dig()
  178.         --turtle.forward()
  179.         turtle.turnLeft()
  180.        
  181.  
  182.  
  183.         heightCounter=1
  184.         -- come back down and dig to the right also
  185.         while heightCounter < heightToDig do         
  186.             checkIfFull()
  187.             p.dig()
  188.             p.digDown()
  189.  
  190.            
  191.             if turtle.down() == false then
  192.                 repeat
  193.                 p.digDown()
  194.                 sleep(1)
  195.                 until turtle.down() == true
  196.             end
  197.             heightCounter = heightCounter + 1
  198.             digRight() 
  199.             end
  200.        
  201.  
  202.         -- we have reached the bottom of a vertical column so we need to move right by 1 before starting another column
  203.         p.dig()
  204.         turtle.turnRight()
  205.         p.dig()
  206.         turtle.forward()
  207.         --p.dig()
  208.         --turtle.forward()
  209.         turtle.turnLeft()
  210.  
  211.  
  212.        
  213.     end
  214.        
  215.        
  216.     -- need to move back to the bottom left and start the new length   
  217.  
  218.         -- come back down and dig to the right also
  219.   turtle.turnLeft()
  220.         for widthCounter=1, (widthToDig*2) +0 do         
  221.                     digForwardGravel()
  222.  
  223.                 end
  224.   turtle.turnRight()
  225.   digForwardGravel()
  226.  
  227. --
  228.  
  229.  
  230.  
  231.  
  232.        
  233. end
  234.  
  235.     for lengthCounter=1, lengthToDig do
  236.     turtle.back()  
  237.     end
  238.  
  239.     -- move back one more and one up
  240.     turtle.back()
  241.     turtle.up()
  242.     turtle.up()
  243. end
  244.  
  245.  
  246. main_code()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement