Advertisement
MsFrizzled

layerCraft

Aug 1st, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --functions
  2.  
  3. function initialise()
  4.     currentX = 0
  5.     currentY = 0
  6.     currentZ = 0
  7.     currentDir = 0
  8.     fuelThreshold = 10
  9.     fuelSlot = 1
  10.     firstBlockSlot = 2
  11.     canContinue = true
  12. end
  13.  
  14. function checkFuel()
  15.     if turtle.getFuelLevel() < fuelThreshold then
  16.         turtle.select(fuelSlot)
  17.         if turtle.refuel(1) == false then
  18.             print ("Waiting for fuel...")
  19.         end
  20.         while turtle.refuel(1) == false do
  21.         end
  22.     else
  23.         print ("No fuel necessary, foolish human")
  24.     end
  25.     print ("I have " .. turtle.getFuelLevel() .. " fuulez")
  26. end
  27.  
  28. function getNextSlot()
  29.     local i=turtle.getSelectedSlot()
  30.     while turtle.getItemCount(i) == 0 do
  31.         i = i + 1
  32.         if i > 16 then
  33.             i = firstBlockSlot
  34.         end    
  35.         turtle.select(i)
  36.     end
  37. end
  38.  
  39. function moveNPlace()
  40.     moveBackwardsXWait()
  41.     turtle.place()
  42. end
  43.  
  44. function turnCorner
  45.     moveBackwardsYWait()
  46.     turtle.place()
  47.        
  48.  
  49. function moveBackwardsXWait()
  50.     while moveBackwardsX(1) ~= 1 do
  51.     end
  52. end
  53.  
  54. function moveBackwardsYWait()
  55.     while moveBackwardsY(1) ~= 1 do
  56.     end
  57. end
  58.  
  59. function whereAmI()
  60.     print ("I am at" .. " " .. currentX .. "X" .. "," .. currentY .. "Y" .. "," .. currentZ .. "Z," .. " Direction:" .. currentDir)
  61. end
  62.  
  63. function moveUp(a)
  64.     local i=1
  65.     for i=1,a do
  66.         if turtle.up() == true then
  67.             currentZ = currentZ + 1
  68.         end
  69.     end
  70.     whereAmI()
  71. end
  72.  
  73. function moveDown(a)
  74.     local i=1
  75.     for i=1,a do
  76.         if turtle.down() == true then
  77.             currentZ = currentZ - 1
  78.         end
  79.     end
  80.     whereAmI()
  81. end
  82.  
  83. function moveZ(a)
  84.     if a < 0 then
  85.         moveDown(-a)
  86.     elseif a > 0 then
  87.         moveUp(a)
  88.     else
  89.     end
  90. end
  91.  
  92. function turnRight(a)
  93.     local i=1
  94.     for i=1,a do
  95.         turtle.turnRight()
  96.         currentDir = currentDir + 1
  97.         if currentDir == 4 then
  98.             currentDir = 0
  99.         end
  100.     end
  101.     whereAmI()
  102. end
  103.  
  104. function turnLeft(a)
  105.     local i=1
  106.     for i=1,a do
  107.         turtle.turnLeft()
  108.         currentDir = currentDir - 1
  109.         if currentDir == -1 then
  110.             currentDir = 3
  111.         end
  112.     end
  113.     whereAmI()
  114. end
  115.  
  116. function setDirection(a)
  117.     local diffTurn = a - currentDir
  118.     if diffTurn < 0 then
  119.         diffTurn = diffTurn + 4
  120.     end
  121.     if diffTurn ~= 0 then
  122.         turnRight(diffTurn)
  123.     end
  124. end
  125.  
  126. function moveForwardX(a)
  127.     local i=1
  128.     if a > 0 then
  129.         setDirection(0)
  130.         for i=1,a do
  131.             if turtle.forward() == true then
  132.                 currentX = currentX + 1
  133.             end
  134.         end
  135.     elseif a < 0 then
  136.         setDirection(2)
  137.         for i=-1,a,-1 do
  138.             if turtle.forward() == true then
  139.                 currentX = currentX - 1
  140.             end
  141.         end
  142.     else
  143.     end
  144.     whereAmI()
  145. end
  146.  
  147. function moveBackwardsX(a)
  148.     local i=1
  149.     local howfar=0
  150.     if a > 0 then
  151.         setDirection(0)
  152.         for i=1,a do
  153.             if turtle.back() == true then
  154.                 currentX = currentX - 1
  155.                 howfar = howfar + 1
  156.             end
  157.         end
  158.     elseif a < 0 then
  159.         setDirection(2)
  160.         for i=-1,a,-1 do
  161.             if turtle.back() == true then
  162.                 currentX = currentX + 1
  163.                 howfar = howfar + 1
  164.             end
  165.         end
  166.     else
  167.     end
  168.     whereAmI()
  169.     return howfar
  170. end
  171.  
  172. function moveForwardY(a)
  173.     local i=1
  174.     if a > 0 then
  175.         setDirection(1)
  176.         for i=1,a do
  177.             if turtle.forward() == true then
  178.                 currentY = currentY + 1
  179.             end
  180.         end
  181.     elseif a < 0 then
  182.         setDirection(3)
  183.         for i=-1,a,-1 do
  184.             if turtle.forward() == true then
  185.                 currentY = currentY - 1
  186.             end
  187.         end
  188.     else
  189.     end
  190.     whereAmI()
  191. end
  192.  
  193. function moveBackwardsY(a)
  194.     local i=1
  195.     local howfar = 0
  196.     if a > 0 then
  197.         setDirection(3)
  198.         for i=1,a do
  199.             if turtle.back() == true then
  200.                 currentY = currentY - 1
  201.                 howfar = howfar + 1
  202.             end
  203.         end
  204.     elseif a < 0 then
  205.         setDirection(1)
  206.         for i=-1,a,-1 do
  207.             if turtle.back() == true then
  208.                 currentY = currentY + 1
  209.                 howfar = howfar + 1
  210.             end
  211.         end
  212.     else
  213.     end
  214.     whereAmI()
  215.     return howfar
  216. end
  217.  
  218. function goTo(x,y,z)
  219.     local diffX = x - currentX
  220.     local diffY = y - currentY
  221.     local diffZ = z - currentZ
  222.  
  223.     moveForwardX(diffX)
  224.     moveForwardY(diffY)
  225.     moveZ(diffZ)
  226. end
  227.  
  228. initialise()
  229. while true do
  230.     moveBackwardsXWait()
  231. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement