Xgamer911

Turtle-Tier

Jun 14th, 2014
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.20 KB | None | 0 0
  1. -- slots 1-8 Sand
  2. -- slots 9-12 cobblestone
  3. -- slot 13 empty
  4. -- slot 14 cobblestone
  5. -- slot 15 sand
  6. -- slot 16 coal
  7.  
  8. local w,h = term.getSize()
  9. local selection = 0
  10. local internalselection = 0
  11. local range = 0
  12. local currentrange = 0
  13. local ypos = 1
  14. local fuel
  15. local fuelava
  16. local counter = 0
  17. local turnleftvar = 1
  18. local turnrightvar = 0
  19. local itemcount = 0
  20. local itemcompare
  21.  
  22. --Some draw functions to get us started
  23. local function printCentered(str, ypos)
  24.   term.setCursorPos(w/2 - #str/2, ypos)
  25.   term.write(str)
  26. end
  27.  
  28. local function printFarLeft(str, ypos)
  29.   term.setCursorPos(1, ypos)
  30.   term.write(str)
  31. end
  32.  
  33. local function printLeft(str, ypos)
  34.   term.setCursorPos(5, ypos)
  35.   term.write(str)
  36. end
  37.  
  38. local function printLeft2(str, ypos)
  39.   term.setCursorPos(10, ypos)
  40.   term.write(str)
  41. end
  42.  
  43. local function printRight(str, ypos)
  44.   term.setCursorPos(w - 15, ypos)
  45.   term.write(str)
  46. end
  47.  
  48. local function printRight2(str, ypos)
  49.   term.setCursorPos(w - 25, ypos)
  50.   term.write(str)
  51. end
  52.  
  53. local function printFarRight(str, ypos)
  54.   term.setCursorPos(w - #str, ypos)
  55.   term.write(str)
  56. end
  57.  
  58. function drawHeader()
  59.     printCentered("Turtle Control", 1)
  60.     printCentered(string.rep("-", w+1), 2)
  61.  
  62. -- print fuel level
  63.     fuel = turtle.getFuelLevel()
  64.     printFarLeft("Fuel " ,3)
  65.     print(fuel)
  66.  
  67. -- print avilable fuel
  68.     fuelava = turtle.getItemCount(16)
  69.     printFarLeft("Fuel Available " ,5)
  70.     print(fuelava)
  71.    
  72. -- Print Range 
  73.     printRight("Counter: "..tostring(counter),3)
  74.     printRight("Left Var: "..tostring(turnleftvar),4)
  75.     printRight("Right Var: "..tostring(turnrightvar ),5)
  76.  
  77. end
  78.  
  79. function refuelme()
  80.     if fuel < 25 then
  81.         turtle.select(16)
  82.         turtle.refuel(1)
  83.         turtle.select(1)
  84.     end
  85. end
  86.  
  87. function drawMainMenu()
  88.     printLeft2("1. Start", 7)
  89.  
  90.     printRight("8. Quit", 10)
  91.  
  92.     printLeft2("Selection: ", 12)
  93.     selection = tonumber(read())
  94. end
  95.  
  96. function tier()
  97.     term.clear()
  98.     term.setCursorPos(1,1)
  99.     internalselection=0
  100.     drawHeader()
  101.    
  102.     printLeft("Start Tiers", 7)
  103.     printLeft("-------", 8)
  104.     printLeft("1. Start", 9)
  105.     printRight("3. Main Menu", 9)
  106.  
  107.    
  108.     printLeft("Selection: ", 12)
  109.     internalselection = tonumber(read())
  110.    
  111.     if internalselection==1 then
  112.         term.clear()
  113.         term.setCursorPos(1,1)
  114.  
  115.         for l = 0,4,1 do
  116.             for j = 0,7,1 do
  117.                 refuelme()
  118.    
  119.                 forward15()
  120.    
  121.                 sleep(1)
  122.                 drawHeader()
  123.  
  124.                 turnleftanddown()
  125.            
  126.                 drawHeader()
  127.                 sleep(1)
  128.    
  129.                 forward15()
  130.    
  131.                 drawHeader()
  132.                 sleep(1)
  133.  
  134.                 turnrightanddown()
  135.        
  136.                 drawHeader()
  137.                 sleep(1)
  138.  
  139.                 unload()
  140.             end
  141.  
  142.             refuelme()     
  143.             turtle.turnRight()
  144.             turtle.dig()
  145.             turtle.forward()
  146.  
  147.             forward15()
  148.        
  149.             turtle.turnLeft()
  150.  
  151.             for k = 0,12,1 do
  152.                 refuelme()
  153.                 turtle.digUp()
  154.                 turtle.digUp()
  155.                 turtle.digUp()
  156.                 turtle.digUp()
  157.                 turtle.up()
  158.             end
  159.         end
  160.  
  161.     end
  162.    
  163.  
  164. end
  165.  
  166. function forward15()
  167.     term.clear()
  168.     term.setCursorPos(1,1)
  169.     drawHeader()
  170.     refuelme()
  171.  
  172.     for i = 0,14,1 do
  173.         turtle.dig()
  174.  
  175.         sleep(1)
  176.         turtle.select(14)
  177.         itemcompare = turtle.compare()
  178.         if itemcompare == true then
  179.             for m = 0,8,1 do
  180.                 turtle.dig()
  181.                
  182.                 --printCentered("gravel",10)
  183.                 --printCentered(tostring(i),11)
  184.                 --printCentered(tostring(m),12)
  185.                 --printCentered(tostring(itemcompare),13)
  186.             end
  187.  
  188.            
  189.             sleep(1)
  190.            
  191.         end
  192.         itemcompare = false
  193.         turtle.select(1)
  194.  
  195.  
  196.         turtle.forward()
  197.         for k = 0,8,1 do
  198.             turtle.digUp()
  199.         end
  200.         turtle.digDown()
  201.  
  202. --printCentered(tostring(i),11)
  203. --printCentered(tostring(m),12)
  204. --printCentered(tostring(itemcompare),13)
  205.         sleep(1)
  206.  
  207.     end
  208. end
  209.  
  210.  
  211. function unload()
  212.     turtle.select(15)
  213.     turtle.placeDown()
  214.     turtle.select(1)
  215.     turtle.dropDown(64)
  216.     turtle.select(2)
  217.     turtle.dropDown(64)
  218.     turtle.select(3)
  219.     turtle.dropDown(64)
  220.     turtle.select(4)
  221.     turtle.dropDown(64)
  222.     turtle.select(5)
  223.     turtle.dropDown(64)
  224.     turtle.select(6)
  225.     turtle.dropDown(64)
  226.     turtle.select(7)
  227.     turtle.dropDown(64)
  228.     turtle.select(8)
  229.     turtle.dropDown(64)
  230.     turtle.select(9)
  231.     turtle.dropDown(64)
  232.     turtle.select(10)
  233.     turtle.dropDown(64)
  234.     turtle.select(11)
  235.     turtle.dropDown(64)
  236.     turtle.select(12)
  237.     turtle.dropDown(64)
  238.     turtle.select(13)
  239.     turtle.dropDown(64)
  240.  
  241.     itemcount = turtle.getItemCount(14)
  242.     itemcount = itemcount - 1
  243.     turtle.select(14)
  244.     turtle.dropDown(itemcount)
  245.  
  246.     turtle.digDown()
  247.     turtle.select(1)
  248.     turtle.transferTo(15)
  249.  
  250. end
  251.  
  252.  
  253.  
  254. function turnleftanddown()
  255.     term.clear()
  256.     term.setCursorPos(1,1)
  257.     drawHeader()
  258.     refuelme()
  259.  
  260.     turtle.turnLeft()
  261.     turtle.dig()
  262.     turtle.forward()
  263.     turtle.turnLeft()
  264.     turtle.digDown()
  265.     turtle.down()
  266.     turtle.digDown()
  267.  
  268.     turnleftvar = 0
  269.     turnrightvar = 1
  270.     counter = counter + 1
  271. end
  272.  
  273. function turnrightanddown()
  274.     term.clear()
  275.     term.setCursorPos(1,1)
  276.     drawHeader()
  277.     refuelme()
  278.  
  279.     turtle.turnRight()
  280.     turtle.dig()
  281.     turtle.forward()
  282.     turtle.turnRight()
  283.     turtle.digDown()
  284.     turtle.down()
  285.     turtle.digDown()
  286.  
  287.     turnleftvar = 1
  288.     turnrightvar = 0
  289.     counter = counter + 1
  290. end
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298. function main()
  299. --PROGRAM START
  300. term.clear()
  301. term.setCursorPos(1,1)
  302.  
  303.     while true do
  304.         drawHeader()
  305.         drawMainMenu()
  306.         refuelme()
  307.  
  308.        
  309.         if selection==1 then
  310.             tier()
  311.  
  312.         end
  313.        
  314.        
  315.        
  316.         if selection==8 then
  317.             term.clear()
  318.             term.setCursorPos(1,1)
  319.             break
  320.         end
  321.        
  322.     end
  323. end
  324.  
  325. main()
Advertisement
Add Comment
Please, Sign In to add comment