Advertisement
Guest User

Q

a guest
Aug 28th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.39 KB | None | 0 0
  1. -- Davis Cook's myExcavate (Totaly written from scratch)
  2.  
  3. x=0 --forward
  4. y=0 --down
  5. z=0 --right (Perpendicular to "forward")
  6. lookdir="forward"
  7.  
  8. function checkFuel()
  9.     fuelLvl = turtle.getFuelLevel()
  10.     --print("Checking Fuel Level...")
  11.     if fuelLvl<100 then
  12.         --print("Needs Fuel, Refueling..")
  13.         turtle.select(16)
  14.         turtle.refuel(2)
  15.     else
  16.         --print("No Fuel Needed.")
  17.     end
  18. end
  19.  
  20. function left()
  21.     turtle.turnLeft()
  22. end
  23.  
  24. function right()
  25.     turtle.turnRight()
  26. end
  27.  
  28. function lookDir(s) -- Options are "forward" "left" "right" "back" --print("Looking " .. s)
  29.     if     ((lookdir=="forward") and (s=="forward")) then
  30.     elseif ((lookdir=="forward") and (s=="right")) then    right()
  31.     elseif ((lookdir=="forward") and (s=="left")) then     left()
  32.     elseif ((lookdir=="forward") and (s=="back")) then     left() left()
  33.     elseif ((lookdir=="right") and (s=="forward")) then    left()
  34.     elseif ((lookdir=="right") and (s=="right")) then    
  35.     elseif ((lookdir=="right") and (s=="left")) then       left() left()
  36.     elseif ((lookdir=="right") and (s=="back")) then       right()
  37.     elseif ((lookdir=="left") and (s=="forward")) then     right()
  38.     elseif ((lookdir=="left") and (s=="right")) then       left() left()
  39.     elseif ((lookdir=="left") and (s=="left")) then      
  40.     elseif ((lookdir=="left") and (s=="back")) then        left()
  41.     elseif ((lookdir=="back") and (s=="forward")) then     left() left()
  42.     elseif ((lookdir=="back") and (s=="right")) then       left()
  43.     elseif ((lookdir=="back") and (s=="left")) then        right()
  44.     elseif ((lookdir=="back") and (s=="back")) then        
  45.     end
  46.     lookdir = s
  47. end
  48.  
  49. function forward()
  50.     checkFuel()
  51.     while turtle.forward()==false do
  52.         turtle.attack()
  53.         turtle.dig()
  54.     end
  55.     if lookdir=="forward" then x=x+1
  56.     elseif lookdir=="right" then z=z+1
  57.     elseif lookdir=="left" then z=z-1
  58.     elseif lookdir=="back" then x=x-1
  59.     end
  60. end
  61.  
  62. function up()
  63.     checkFuel()
  64.     while turtle.up()==false do
  65.         turtle.attackUp()
  66.         turtle.digUp()
  67.     end
  68.     y=y+1
  69. end
  70.  
  71. function down()
  72.     checkFuel()
  73.     while turtle.down()==false do
  74.         turtle.attackDown()
  75.         turtle.digDown()
  76.     end
  77.     y=y-1
  78. end
  79.  
  80. function reSupply()
  81.    
  82.     print("Re-Supplying")
  83.     checkFuel()
  84.     savex = x
  85.     savey = y
  86.     savez = z
  87.     savedir=lookdir
  88.    
  89.     lookDir("back")
  90.     while y~=0 do
  91.         up()
  92.     end
  93.     while x~=0 do
  94.         forward()
  95.     end
  96.     while z~=0 do
  97.         lookDir("left")
  98.         forward()
  99.     end
  100.     print("Grabbing Fuel...")
  101.     while ((turtle.getItemCount(16)<10) and (turtle.getFuelLevel()<300)) do
  102.         turtle.select(16)
  103.         turtle.suckUp()
  104.     end
  105.     lookDir("back")
  106.     print("Emptying Inventory...")
  107.     for slot=1, 15 do
  108.         turtle.select(slot)
  109.         turtle.drop()
  110.     end
  111.     rs.setOutput("front",true)
  112.     sleep(1)
  113.     rs.setOutput("front",false)
  114.     lookDir("forward")
  115.     while x~=savex do
  116.         forward()
  117.     end
  118.     while z~=savez do
  119.         lookDir("right")
  120.         forward()
  121.     end
  122.     while y~=savey do
  123.         down()
  124.     end
  125.     lookDir(savedir)
  126. end
  127.  
  128. function digupdown()
  129.     turtle.digUp()
  130.     turtle.digDown()
  131. end
  132.  
  133. function needResupply()
  134.     n=1
  135.     for q=1,15 do
  136.         if ((turtle.getItemCount(q)>0) or ((turtle.getFuelLevel()<100) and (turtle.getItemCount(16)<4))) then
  137.             n=n+1
  138.         end
  139.     end
  140.     if n>13 then reSupply() end
  141. end
  142.  
  143. function goHome()
  144.    
  145.     print("Going Home")
  146.     checkFuel()
  147.    
  148.     lookDir("back")
  149.     while y~=0 do
  150.         up()
  151.     end
  152.     while x~=0 do
  153.         forward()
  154.     end
  155.     while z~=0 do
  156.         lookDir("left")
  157.         forward()
  158.     end
  159.     lookDir("forward")
  160.    
  161. end
  162.  
  163. function excavate(length,width,depth)
  164.    
  165.     checkFuel()
  166.     down()
  167.     down()
  168.     for u=1,(depth/3) do
  169.         for o=1,(width/2) do
  170.             for i=1,(length-1) do
  171.                 needResupply()
  172.                 digupdown()
  173.                 forward()
  174.             end
  175.             digupdown()
  176.             lookDir("right")
  177.             forward()
  178.             lookDir("back")
  179.             for p=2,length do
  180.                 needResupply()
  181.                 digupdown()
  182.                 forward()
  183.             end
  184.             digupdown()
  185.             if o~=(width/2) then
  186.                 lookDir("right")
  187.                 forward()
  188.                 lookDir("forward")
  189.             end
  190.         end
  191.         lookDir("left")
  192.         for r=2,width do
  193.             forward()
  194.         end
  195.         lookDir("forward")
  196.         if u~=(depth/3) then
  197.             down()
  198.             down()
  199.             down()
  200.         end
  201.     end
  202. end
  203.  
  204. function bedRock()
  205.    
  206.     print("At Bedrock Level.")
  207.     print("Running Bedrock Code...")
  208.     for h=1,(width/2) do
  209.         for j=2,length do
  210.             checkFuel()
  211.             hole=0
  212.             while turtle.down() do
  213.                 y=y-1
  214.                 turtle.digDown()
  215.                 hole=hole+1
  216.             end
  217.             while hole~=0 do
  218.                 up()
  219.                 hole=hole-1
  220.             end
  221.             if j~=length then
  222.                 forward()
  223.             end
  224.         end
  225.         while turtle.down() do
  226.             y=y-1
  227.             turtle.digDown()
  228.             hole=hole+1
  229.         end
  230.         while hole~=0 do
  231.             up()           
  232.             hole=hole-1
  233.         end
  234.         lookDir("right")
  235.         forward()
  236.         lookDir("back")
  237.         for b=2,length do
  238.             checkFuel()
  239.             hole=0
  240.             while turtle.down() do
  241.                 y=y-1
  242.                 turtle.digDown()
  243.                 hole=hole+1
  244.             end
  245.             while hole~=0 do
  246.                 up()
  247.                 hole=hole-1
  248.             end
  249.             if b~=length then
  250.                 forward()
  251.             end
  252.         end
  253.         while turtle.down() do
  254.             y=y-1
  255.             turtle.digDown()
  256.             hole=hole+1
  257.         end
  258.         while hole~=0 do
  259.             up()
  260.             hole=hole-1
  261.         end
  262.         if h~=(width/2) then
  263.             lookDir("right")
  264.             forward()
  265.             lookDir("forward")
  266.         end
  267.     end
  268.    
  269. end
  270.  
  271. print("Davis Cook's myExcavate")
  272. print("")
  273. print("Length can Be Anything above 2.")
  274. print("Length?")
  275. length= io.read()
  276. print("Width has to be Even and Above 2.")
  277. print("Width?")
  278. width= io.read()
  279. print("To Go All The Way To Bedrock, do: y_coord-5")
  280. print("Depth?")
  281. depth=io.read()
  282. print("Dig Bellow Bedrock? yes or no")
  283. decision=io.read()
  284. reSupply()
  285. excavate(length,width,(depth))
  286. if decision=="yes" then
  287.     bedRock()
  288. end
  289. goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement