Advertisement
SavageCore

Untitled

Apr 22nd, 2013
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.03 KB | None | 0 0
  1. shell.run("clear")
  2. local enderchest = false
  3. local torch = turtle.getItemCount(1)
  4. local chests = turtle.getItemCount(2)
  5. local dist = 0
  6. local retdist = 0
  7. local fuel = turtle.getFuelLevel()
  8. local t = 0
  9.  
  10. function start()
  11.     io.write "How deep do you want each branch? (Length) (1/99): "
  12.     ll = io.read()
  13.   if not tonumber(ll) then
  14.     print ""
  15.         print "Please enter a valid number"
  16.         print ""
  17.     start()
  18.   else
  19.     length = ll+1
  20.     start_1()
  21.   end
  22.   if tonumber(length) < 1 then
  23.         print ""
  24.         print "Number must be positive"
  25.         print ""
  26.         start()
  27.     end
  28. end
  29.  
  30. function start_1()  
  31.     io.write "How many branches do you want? (Width) (1/99): "
  32.     w = io.read()
  33.   if not tonumber(w) then
  34.     print ""
  35.         print "Please enter a valid number"
  36.         print ""
  37.     start_1()
  38.   else
  39.     width = w+1
  40.     start_2()
  41.   end
  42.   if tonumber(w) < 1 then
  43.         print ""
  44.         print "Number must be positive"
  45.         print ""
  46.         start_1()
  47.     end
  48. end
  49.  
  50. function start_2()  
  51.   io.write "Enderchest? (y/n): "
  52.     e = io.read()
  53.   if e == "y" then
  54.     enderchest = true
  55.     start_3()
  56.   elseif e == "n" then
  57.     enderchest = false
  58.     start_3()
  59.   else
  60.     print ""
  61.     print "Please enter y or n"
  62.     print ""
  63.     start_2()
  64.   end
  65. end
  66.  
  67. function start_3()
  68.   print ("")
  69.   print ("I will dig ".. w .. ", " .. ll .. " long tunnel(s)")
  70.   if enderchest == true then
  71.     print("Enderchest: Yes")
  72.   else
  73.     print("Enderchest: No")
  74.   end
  75.     io.write "Are you sure you want to procede? (y/n): "
  76.     c = io.read()
  77.   if c == "y" then
  78.    --do stuff
  79.     print "Off I go"
  80.   elseif c == "n" then
  81.     print "Be seeing you!"
  82.   else
  83.     print ""
  84.     print "Please enter y or n"
  85.     print ""
  86.     start_3()
  87.   end
  88. end
  89.  
  90. function reFuel()
  91.     turtle.select(3)
  92.     turtle.refuel(1)
  93.     local fuel = turtle.getFuelLevel()
  94. end
  95.  
  96. function forward()
  97.   if turtle.getFuelLevel() < 1 then
  98.     reFuel()
  99.   end
  100.   if turtle.detect() then turtle.dig() end
  101.   turtle.forward()
  102.   dump()
  103.   turtle.digUp()
  104.   dump()
  105.   dist = dist + 1
  106.   print("dist:" .. dist)
  107.   print("length:" .. length)
  108. end
  109.  
  110. function dump()
  111.   if turtle.getItemCount(16)>0 then
  112.     turtle.digDown()
  113.     turtle.select(2)
  114.     turtle.placeDown()
  115.     for slot = 4,15,1 do
  116.       turtle.select(slot)
  117.       turtle.dropDown()
  118.     end
  119.     if enderchest then
  120.       turtle.select(2)
  121.       turtle.digDown()
  122.     else
  123.       chests = chests - 1  
  124.     end
  125.   end
  126. end
  127.  
  128. function light()
  129.   turtle.turnLeft()
  130.   turtle.turnLeft()
  131.   turtle.select(1)
  132.   turtle.place()
  133.   turtle.turnLeft()
  134.   turtle.turnLeft()
  135.   torch = torch - 1
  136. end
  137.  
  138. function run()
  139.   --[[print("torch:" .. torch)
  140.   print("chests:" .. chests)
  141.   print("fuel:" .. fuel)
  142.   print("retdist:" .. retdist)]]--
  143.   while (torch > 0) and (chests > 0) and (fuel > retdist) and (dist < tonumber(length)) do
  144.     t = t + 1
  145.     if t == 12 then
  146.       light()
  147.       t = 0
  148.     end
  149.     forward()
  150.     --light()
  151.     retdist = dist + 14
  152.     local fuel = turtle.getFuelLevel()
  153.   end
  154.   --home()
  155. end
  156.  
  157. start()
  158. if fuel == 0 then
  159.   print("Better refuel")
  160.   reFuel()
  161. end
  162. --run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement