Advertisement
Guest User

tunnel.lua

a guest
Apr 21st, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. ---------------functions---------------
  2. ---------------------------------------
  3.  
  4. function percent(current,volume)
  5.     current=current+1
  6.     percent=current/volume*100
  7.     term.clear()
  8.     print("current advencement:", percent,"%")
  9.     return current
  10. end
  11.  
  12. function height(h,height)
  13.     print(h)
  14.     if h==1 then
  15.         if turtle.detectDown()==false then
  16.             turtle.placeDown()
  17.         end
  18.     elseif h==height then
  19.         if turtle.detectUp()==false then
  20.             turtle.placeUp()
  21.         end
  22.        
  23.     end
  24.    
  25. end
  26.  
  27. function OOF() --out of fuel
  28.     while true do
  29.         term.clear()
  30.         term.setCursorPos(1,1)
  31.         print(" Out of fuel!")
  32.         print(" Place fuel in slot 16")
  33.         turtle.select(16)
  34.         if turtle.getItemCount()>0 then
  35.             prev=turtle.getFuelLevel()
  36.             turtle.refuel(1)
  37.             print("Fuel level:", turtle.getFuelLevel()/(1000).."k")
  38.             if turtle.getItemCount()==0 or turtle.getFuelLevel()>=100000-(turtle.getFuelLevel()-prev) then
  39.                 break
  40.             end
  41.            
  42.         end
  43.         sleep(0.01)
  44.        
  45.     end
  46.    
  47. end
  48.    
  49.    
  50. --------------main program-------------
  51. ---------------------------------------
  52. --terminal clear
  53. term.clear()
  54.  
  55. --variables
  56. print("enter lenght:")
  57. lenght=tonumber(read())
  58. print("enter width:")
  59. width=tonumber(read())
  60. print("enter height:")
  61. height=tonumber(read())
  62.  
  63. volume=lenght*width*height
  64. current=0
  65. for l=1,lenght do
  66.     turtle.select(16)
  67.     turtle.drop(turtle.getItemCount())
  68.     if turtle.getFuelLevel()<((height*width)+height+width) then
  69.         OOF() --out off fuel
  70.     end
  71.    
  72.     turtle.dig()
  73.     current=percent(current,volume)
  74.     turtle.forward()
  75.     turtle.turnRight()
  76.     if turtle.detect()==false then
  77.         turtle.place()
  78.     end
  79.    
  80.     for i=1,height do
  81.         h=i
  82.         for w=1,width-1 do
  83.            
  84.            
  85.             turtle.dig()
  86.             current=percent(current,volume)
  87.             turtle.forward()
  88.            
  89.             height(i)
  90.         end
  91.        
  92.         if turtle.detect()==false then
  93.             turtle.place()
  94.         end
  95.        
  96.         if i~=height then
  97.             turtle.digUp()
  98.             current=percent(current,volume)
  99.             turtle.up()
  100.             if turtle.detect()==false then
  101.                 turtle.place()
  102.             end
  103.            
  104.             turtle.turnLeft()
  105.             turtle.turnLeft()
  106.         end
  107.        
  108.     end
  109.    
  110.     if height%2==0 then
  111.         for i=1, height do
  112.             turtle.down()
  113.         end
  114.        
  115.     else
  116.         for i=1, height do
  117.             turtle.down()
  118.         end
  119.        
  120.         turtle.turnLeft()
  121.         turtle.turnLeft()
  122.         for i=1,witdh-1 do
  123.             turtle.forward()
  124.         end
  125.        
  126.     end
  127.    
  128.     turtle.turnRight()
  129. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement