DeepFriedBabeez

New CC Quarry

Sep 15th, 2013
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.66 KB | None | 0 0
  1. --need to fix a couple things including a better sorting method
  2. --also sorts empty inventory immediately after going down after dropping off
  3. --perhaps auto sort occasionally(when empty slot is first filled by non-exclude?)
  4. --use above to drop entire stacks of junk continually instead of dropping everything once
  5.  
  6. --variables
  7. length = 32
  8. width = 32
  9. depth = 70
  10.  
  11. debug = true
  12.  
  13. hasDropped = false
  14. turtX = 0
  15. turtY = 0
  16. turtZ = -1
  17. turtDir = 0 --0 forward, 1 left, 2 back, 3 right
  18.  
  19. --functions
  20. function vals()
  21.   term.clear()
  22.   term.setCursorPos(1,1)
  23.   print("Position: "..turtX..","..turtY..","..turtZ)
  24.   print("Direction: "..turtDir)
  25.   --sleep(1)
  26. end
  27.  
  28. function up(x, dropping)
  29.   x = x or 1
  30.   dropping = dropping or false
  31.   for i=1, x do
  32.     while (turtle.up() == false) do
  33.       turtle.digUp()
  34.       turtle.attackUp()
  35.     end
  36.     turtY = turtY + 1
  37.     if (debug) then
  38.       vals()
  39.     end
  40.     if (dropping == false) then
  41.       checkDrop()
  42.     end
  43.   end
  44. end
  45.  
  46. function down(x, dropping)
  47.   x = x or 1
  48.   dropping = dropping or false
  49.   for i=1, x do
  50.     while (turtle.down() == false) do
  51.       turtle.digDown()
  52.       turtle.attackDown()
  53.     end
  54.     turtY = turtY - 1
  55.     if (debug) then
  56.       vals()
  57.     end
  58.     if (dropping == false) then
  59.       checkDrop()
  60.     end
  61.   end
  62. end
  63.  
  64. function left(x)
  65.   x = x or 1
  66.   for i=1, x do
  67.     turtle.turnLeft()
  68.     turtDir = turtDir + 1
  69.     if (turtDir == 4) then
  70.       turtDir = 0
  71.     end
  72.     if (debug) then
  73.       vals()
  74.     end
  75.   end
  76. end
  77.  
  78. function right(x)
  79.   x = x or 1
  80.   for i=1, x do
  81.     turtle.turnRight()
  82.     turtDir = turtDir - 1
  83.     if (turtDir == -1) then
  84.       turtDir = 3
  85.     end
  86.     if (debug) then
  87.       vals()
  88.     end
  89.   end
  90. end
  91.  
  92. function forward(x, dropping)
  93.   x = x or 1
  94.   dropping = dropping or false
  95.   for i=1, x do
  96.     while (turtle.forward() == false) do
  97.       turtle.dig()
  98.       turtle.attack()
  99.     end
  100.     if (turtDir == 0) then
  101.       turtZ = turtZ + 1
  102.     elseif (turtDir == 1) then
  103.       turtX = turtX + 1
  104.     elseif (turtDir == 2) then
  105.       turtZ = turtZ - 1
  106.     elseif (turtDir == 3) then
  107.       turtX = turtX - 1
  108.     end
  109.     if (debug) then
  110.       vals()
  111.     end
  112.     if (dropping == false) then
  113.       checkDrop()
  114.     end
  115.   end
  116. end
  117.  
  118. function checkDrop()
  119.   if (turtle.getItemCount(15) > 0) then
  120.     for s=1, 15 do
  121.       turtle.select(s)
  122.       if (turtle.compareTo(16) == true) then
  123.         turtle.drop()
  124.       end
  125.     end
  126.     if (hasDropped == true) then
  127.       drop(turtX, turtY, turtZ, turtDir)
  128.     else
  129.       hasDropped = true
  130.     end
  131.     for a=1, 15 do
  132.       turtle.select(a)
  133.       for b=1, 15 do
  134.         if (turtle.getItemCount(16 - b) == 0) then
  135.           turtle.transferTo(16 - b)
  136.         end
  137.       end
  138.     end
  139.     turtle.select(1)
  140.   end
  141. end
  142.  
  143. function drop(oldX, oldY, oldZ, oldDir, x)
  144.   x = x or false
  145.   hasDropped = false
  146.   up(-1 * oldY, true)
  147.   while (turtDir ~= 3) do
  148.     right()
  149.   end
  150.   forward(oldX, true)
  151.   right()
  152.   forward(oldZ + 1, true)
  153.   for i=1, 15 do
  154.     turtle.select(i)
  155.     turtle.drop()
  156.   end
  157.   turtle.select(1)
  158.   right(2)
  159.   if (x == false) then --keep going!
  160.     forward(oldZ + 1)
  161.     left()
  162.     forward(oldX)
  163.     down(-1 * oldY)
  164.     while (turtDir ~= oldDir) do
  165.       right()
  166.     end
  167.   else --done
  168.     print("Done!")
  169.   end
  170. end
  171.  
  172.  
  173. forward()
  174. for d=1, depth do
  175.   for l=1, length do
  176.     if (turtZ % 2 == 0) then
  177.       left()
  178.       forward(width - 1)
  179.       right()
  180.     else
  181.       right()
  182.       forward(width - 1)
  183.       left()
  184.     end
  185.     if(l ~= length) then
  186.       forward()
  187.     end
  188.   end
  189.   right(2)
  190.   if(d ~= depth) then
  191.     down()
  192.   end
  193. end
  194. drop(turtX, turtY, turtZ, turtDir, true)
Advertisement
Add Comment
Please, Sign In to add comment