Pinkishu

excav

May 6th, 2012
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.38 KB | None | 0 0
  1. local location = {0,0,0}
  2. local origin = {0,0,0}
  3. local dir=1
  4. local modX= {0,1,0,-1}
  5. local modZ = {1,0,-1,0}
  6. local max = {5,2,5}
  7. turtle.select(1)
  8.  
  9. function turnLeft()
  10.   turtle.turnLeft()
  11.   dir = dir - 1
  12.   if dir < 1 then dir = 4 end
  13. end
  14.  
  15. function turnAround()
  16.   turnLeft()
  17.   turnLeft()
  18. end
  19.  
  20. function turnRight()
  21.   turtle.turnRight()
  22.   dir = dir + 1
  23.   if dir > 4 then dir = 1 end
  24. end
  25.  
  26. function addLocStep()
  27.   location[1] = location[1] + modX[dir]
  28.   location[3] = location[3] + modZ[dir]
  29. end
  30.  
  31. function subLocStep()
  32.   location[1] = location[1] - modX[dir]
  33.   location[3] = location[3] - modZ[dir]
  34. end
  35.  
  36. function forward()
  37.   local b = turtle.forward()
  38.   if b then
  39.     addLocStep()
  40.     return true
  41.   else
  42.     return false
  43.   end  
  44. end
  45.  
  46. function back()
  47.   local b = turtle.back()
  48.   if b then
  49.     subLocStep()
  50.     return true
  51.   else
  52.     return false
  53.   end
  54. end
  55.  
  56. function dig()
  57.   while turtle.detect() do
  58.     turtle.dig()
  59.     sleep(0)
  60.   end
  61. end
  62.  
  63. function digUp()
  64.   while turtle.detectUp() do
  65.     turtle.digUp()
  66.     sleep(0.5)
  67.   end
  68. end
  69.  
  70. function digForward()
  71.   while forward() == false do
  72.     dig()
  73.     sleep(0)
  74.   end
  75. end
  76.  
  77. function digBack()
  78.   while back() == false do
  79.     turnAround()
  80.     dig()
  81.     turnAround()
  82.     sleep(0)
  83.   end
  84. end
  85.  
  86. function turnOriginLeft()
  87.   while dir ~= 4 do
  88.     turnLeft()
  89.   end
  90. end
  91.  
  92. function turnOriginRight()
  93.   while dir ~= 2 do
  94.     turnLeft()
  95.   end
  96. end
  97.  
  98. function turnOriginDown()
  99.   while dir ~= 3 do
  100.     turnLeft()
  101.   end
  102. end
  103.  
  104. function turnOriginUp()
  105.   while dir ~= 1 do
  106.     turnLeft()
  107.   end
  108. end
  109.  
  110.  
  111. local input = ""
  112. while input ~= "start" do
  113.   input = read()
  114.   sleep(0)
  115. end
  116.  
  117. function checkInventory()
  118.   if turtle.getItemCount(9) > 0 then
  119.     return true
  120.   else
  121.     return false
  122.   end
  123. end
  124.  
  125. function getLocCopy()
  126.   local copy = {}
  127.   for i,n in ipairs(location) do
  128.     copy[i] = n
  129.   end
  130.   return copy
  131. end
  132.  
  133. function doDropOff(goBack)
  134.   local orgDir = dir
  135.   local orgPos = getLocCopy()
  136.   moveToOrigin()
  137.   turnOriginDown()
  138.   forward()
  139.   forward()
  140.   dropAll()
  141.   moveToOrigin()
  142.   if goBack then
  143.     moveTo(orgPos[1],origin[3])
  144.     moveTo(orgPos[1],orgPos[3])
  145.     while orgDir ~= dir do
  146.         turnLeft()
  147.         sleep(0)
  148.     end
  149.   end
  150. end
  151.  
  152. function dropAll()
  153.   for i=1,9,1 do
  154.     turtle.select(i)
  155.     if turtle.getItemCount(i) > 0 then
  156.       turtle.drop()
  157.     end
  158.   end
  159.   turtle.select(1)
  160. end
  161.  
  162. function moveToOrigin()
  163.   moveTo(origin[1],location[3])
  164.   moveTo(origin[1],origin[3])
  165. end
  166.  
  167. function turnToX(x)
  168.   if location[1] < x then
  169.     turnOriginRight()
  170.   elseif location[1] > x then
  171.     turnOriginLeft()
  172.   end  
  173. end
  174.  
  175. function turnToZ(z)
  176.   if location[3] < z then
  177.     turnOriginUp()
  178.   elseif location[3] > z then
  179.     turnOriginDown()
  180.   end
  181. end
  182.  
  183. function moveTo(x,z)
  184.   turnToX(x)
  185.   while location[1] ~= x do
  186.     forward()
  187.     sleep(0)
  188.   end
  189.   turnToZ(z)
  190.   while location[3]~=z do
  191.     forward()
  192.     sleep(0)
  193.   end
  194. end
  195.  
  196. for x=1,max[1],1 do
  197.   for z=1,max[3],1 do
  198.     if x ~= 1 and z == 1 then
  199.     else
  200.     print(tostring(x).."/"..tostring(z).."  /// " .. tostring(location[1]) .. "/"..tostring(location[2]).."/"..tostring(location[3]))
  201.    
  202.     digForward()
  203.     digUp()
  204.     if checkInventory() then
  205.       doDropOff(true)
  206.     end
  207.     end
  208.   end
  209.   turnOriginLeft()
  210.   digForward()
  211.   digUp()
  212.   if x % 2 == 1 then
  213.     turnOriginDown()
  214.   else
  215.     turnOriginUp()
  216.   end
  217.   --turnOriginDown()
  218.   --digBack()
  219. end
  220.  
  221. doDropOff(false)
Advertisement
Add Comment
Please, Sign In to add comment