Advertisement
DemonicArcher

Builder

Oct 3rd, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 24.05 KB | None | 0 0
  1. -- Slot 1 Block = Smooth Stone
  2. -- Slot 2 Block = Cobble
  3. -- Slot 3 Block = Thickened Glass
  4. modem = peripheral.wrap("right")
  5.  
  6. face = 1 -- intial facing direction
  7.  
  8. xFreq = 1
  9. yFreq = 2
  10. zFreq = 3
  11. Action = 4
  12.  
  13. modem.open(xFreq)
  14. modem.open(yFreq)
  15. modem.open(zFreq)
  16. modem.open(Action)
  17. structure = Taurus -- place your array name here
  18. baseDirection = "North"
  19. yTravel = 120
  20.  
  21. xPos = nil
  22. yPos = nil
  23. zPos = nil
  24.  
  25. xHome = nil
  26. yHome = nil
  27. zHome = nil
  28.  
  29. xProgress = nil
  30. yProgress = nil
  31. zProgress = nil
  32. fProgress = nil
  33.  
  34. yMin = 82
  35.  
  36. xQuarry = nil
  37. yQuarry = nil
  38. zQuarry = nil
  39.  
  40. xSlot1 = 2939
  41. ySlot1 = 96
  42. zSlot1 = 1860
  43.    
  44. xSlot2 = 2936
  45. ySlot2 = 96
  46. zSlot2 = 1860
  47.  
  48. xSlot3 = 2933
  49. ySlot3 = 96
  50. zSlot3 = 1860
  51.  
  52. slot = 1
  53. row = 1
  54. directions = {"North","East","South","West"}
  55. baseDirection = "North""Not Calibrated")
  56.   end
  57. end
  58.  
  59. function digForward()  
  60.   while turtle.detect() do
  61.     turtle.dig()
  62.   end
  63.   travelForward()
  64.   if inventoryFull() then
  65.     returnItems()
  66.   end
  67. end
  68.  
  69. function travelBack()
  70.   turtle.back()
  71.   if cal == true then
  72.     if face == 1 then
  73.       zPos = zPos + 1
  74.     elseif face == 2 then
  75.       xPos = xPos - 1
  76.     elseif face == 3 then
  77.       zPos = zPos - 1
  78.     elseif face == 4 then
  79.       xPos = xPos + 1
  80.     end
  81.   else
  82.     print("Not Calibrated")
  83.   end
  84. end
  85.  
  86. function travelUp()
  87.   turtle.up()
  88.   if cal == true then
  89.     yPos = yPos + 1
  90.   else
  91.     print("Not Calibrated")
  92.   end
  93. end
  94.  
  95. function travelDown()
  96.   turtle.down()
  97.   if cal == true then
  98.     yPos = yPos - 1
  99.   else
  100.   print("Not Calibrated")
  101.   end
  102.   if yPos < yMin then
  103.     yMin = yPos
  104.   end
  105. end
  106.  
  107. function digDown()
  108.   while turtle.detectDown() do
  109.     turtle.digDown()
  110.   end
  111.   travelDown()
  112. end
  113.  
  114. function Look(direction)
  115.   while  direction ~= directions[face] do
  116.   Right()
  117.   end
  118. end
  119.  
  120. function goto(xTarget, yTarget, zTarget)
  121.   if xTarget < xPos then
  122.     Look("West")
  123.     while xTarget < xPos do
  124.       travelForward()
  125.     end
  126.   end
  127.  
  128.   if xTarget > xPos then
  129.     Look("East")
  130.     while xTarget > xPos do
  131.       travelForward()
  132.     end
  133.   end
  134.  
  135.   if zTarget < zPos then
  136.     Look("North")
  137.     while zTarget < zPos do
  138.       travelForward()
  139.     end
  140.   end
  141.  
  142.   if zTarget > zPos then
  143.     Look("South")
  144.     while zTarget > zPos do
  145.       travelForward()
  146.     end
  147.   end
  148.  
  149.   while yTarget < yPos do
  150.     travelDown()
  151.   end
  152.  
  153.   while yTarget > yPos do
  154.     travelUp()
  155.   end
  156. end
  157.  
  158. function Fuel()
  159.   redstone.setOutput("back", true)
  160.   turtle.refuel()
  161.   turtle.dropDown()
  162.   redstone.setOutput("back", false)
  163.   print(turtle.getFuelLevel())
  164.   sleep(0.5)
  165. end
  166.  
  167. function returnItems(xReturn,yReturn,zReturn,slot)
  168.   xProgress = xPos
  169.   yProgress = yPos
  170.   zProgress = zPos
  171.   fProgress = face
  172.  
  173.   goto(xPos,yTravel,zPos)
  174.   goto(xReturn,yReturn,zReturn)
  175.   if slot == 1 then
  176.     for i = 1,4 do
  177.     turtle.select(i)
  178.     turtle.dropDown()
  179.     turtle.suckDown()
  180.     end
  181.   elseif slot == 2 then
  182.     for i = 5,8 do
  183.     turtle.select(i)
  184.     turtle.dropDown()
  185.     turtle.suckDown()
  186.     end
  187.   elseif slot == 3 then
  188.     for i = 9,16 do
  189.     turtle.select(i)
  190.     turtle.dropDown()
  191.     turtle.suckDown()
  192.     end
  193.   end
  194.   Full = 0
  195.   goto(xProgress,yProgress,zProgress)
  196.   Look(directions[fProgress])
  197. end
  198.  
  199. function Launch()
  200.   goto(xSlot1,ySlot1,zSlot1)
  201.     for i = 1,4 do
  202.     turtle.select(i)
  203.     turtle.dropDown()
  204.     turtle.suckDown(64)
  205.     end
  206.   goto(xSlot2,ySlot2,zSlot2)
  207.     for i = 5,8 do
  208.     turtle.select(i)
  209.     turtle.dropDown()
  210.     turtle.suckDown(64)
  211.     end
  212.   goto(xSlot3,ySlot3,zSlot3)
  213.     for i = 9,16 do
  214.     turtle.select(i)
  215.     turtle.dropDown()
  216.     turtle.suckDown(64)
  217.     end
  218.   slot = 1
  219.   goto(xPos, yTravel, zPos)
  220.   end
  221.  
  222.  
  223. function Dock()
  224.   Look(baseDirection)
  225.  
  226.   for a = 1,16 do
  227.    turtle.select(a)
  228.    turtle.dropDown()
  229.   end
  230.   turtle.select(1)
  231. end
  232.  
  233. -- keeps the selection an a full inventory slot
  234. -- and refills when empty
  235. function checkInventory(a)
  236.  
  237.     if a == 1 then
  238.       if turtle.getItemCount(1) > 0 then
  239.         turtle.select(1)
  240.       elseif turtle.getItemCount(2) > 0 then
  241.         turtle.select(2)
  242.       elseif turtle.getItemCount(3) > 0 then
  243.         turtle.select(3)
  244.       elseif turtle.getItemCount(4) > 0 then
  245.         turtle.select(4)
  246.       else
  247.         returnItems(xSlot1,ySlot1,zSlot1,a)
  248.       end
  249.     elseif a == 2 then
  250.       if turtle.getItemCount(5) > 0 then
  251.         turtle.select(5)
  252.       elseif turtle.getItemCount(6) > 0 then
  253.         turtle.select(6)
  254.       elseif turtle.getItemCount(7) > 0 then
  255.         turtle.select(7)
  256.       elseif turtle.getItemCount(8) > 0 then
  257.         turtle.select(8)
  258.       else
  259.         returnItems(xSlot2,ySlot2,zSlot2,a)
  260.       end
  261.     elseif a == 3 then
  262.       if turtle.getItemCount(9) > 0 then
  263.         turtle.select(9)
  264.       elseif turtle.getItemCount(10) > 0 then
  265.         turtle.select(10)
  266.       elseif turtle.getItemCount(11) > 0 then
  267.         turtle.select(11)
  268.       elseif turtle.getItemCount(12) > 0 then
  269.         turtle.select(12)
  270.       elseif turtle.getItemCount(13) > 0 then
  271.         turtle.select(13)
  272.       elseif turtle.getItemCount(14) > 0 then
  273.         turtle.select(14)
  274.       elseif turtle.getItemCount(15) > 0 then
  275.         turtle.select(15)
  276.       elseif turtle.getItemCount(16) > 0 then
  277.         turtle.select(16)
  278.       else
  279.         returnItems(xSlot3,ySlot3,zSlot3,a)
  280.       end
  281.     end
  282. end
  283.  
  284.  
  285. -- places a block and moves forward
  286. function Place(a)
  287.   checkInventory(a)
  288.  
  289.   if turtle.detectDown() ~= true then
  290.     turtle.placeDown()
  291.     travelForward()
  292.   else
  293.     travelForward()
  294.   end
  295.  
  296. end
  297.  
  298. function row1() -- turns turtle around and keeps rows even
  299.   Right()
  300.   travelForward()
  301.   Right()
  302.   travelForward()
  303. end
  304.  
  305. function row2() -- turns turtle around and keeps rows even
  306.   Left()
  307.   travelForward()
  308.   Left()
  309.   travelForward()
  310. end
  311.  
  312. function newLayer() -- takes turtle up a level and starts a new layer
  313.   if row == 2 then
  314.     travelUp()
  315.     Right()
  316.     travelForward()
  317.     Left()
  318.   elseif row == 1 then
  319.     travelUp()
  320.     Left()
  321.     travelForward()
  322.     Right()
  323.   end
  324. end
  325.  
  326. -- reads your arrays and tells the turtle what to do with the information
  327. function bluePrint(a)
  328.  
  329.   for b,c in pairs(a) do
  330.     for k,block in pairs(a[b]) do
  331.       if block == 0 then
  332.         travelForward()
  333.       else
  334.         Place(block)
  335.       end
  336.      end
  337.     if row == 1 then
  338.       row1()
  339.       row = 2
  340.     elseif row == 2 then
  341.       row2()
  342.       row = 1
  343.     end
  344.   end
  345.   newLayer()
  346.   row = 1
  347. end
  348.  
  349. while true do
  350.  
  351. event, side, sent, reply, message, distance = os.pullEvent("modem_message")
  352.  
  353. if sent == xFreq then
  354.   xQuarry = message
  355. end
  356.  
  357. if sent == yFreq then
  358.   yQuarry = message
  359. end
  360. if sent == zFreq then
  361.   zQuarry = message
  362. end
  363.  
  364. if sent == Action and message == "Go" then
  365.  
  366.  
  367. setLocation()
  368. print(getLocation())
  369. Launch()
  370.  
  371.  
  372. goto(xQuarry,yQuarry,zQuarry)
  373. for m,n in pairs (Taurus) do
  374. bluePrint(Taurus[m])
  375. end
  376. goto(xHome, yHome, zHome)
  377. Dock()
  378. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement